Skip to content

Commit 13ee242

Browse files
authored
Change screenshot logic (#20)
1 parent 42da65f commit 13ee242

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

node/export.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ export async function pdf(url, pdf_path, options, screenshot_dir, screenshot_opt
2929
})
3030

3131
await waitForPlutoBusy(page, false, { timeout: 30 * 1000 })
32+
await screenshot_cells(page, screenshot_dir, screenshot_options)
3233

3334
console.log("Exporting as pdf...")
3435
await page.pdf({
3536
path: pdf_path,
3637
...options,
3738
})
38-
if (screenshot_dir != null) {
39-
await screenshot_cells(page, screenshot_dir, screenshot_options)
40-
}
4139

4240
console.log(chalk.green("Exported ✓") + " ... cleaning up")
4341

@@ -55,15 +53,20 @@ async function screenshot_cells(page, screenshot_dir, { outputOnly, scale }) {
5553
for (let cell_id of cells) {
5654
const cell = await page.$(`[id="${cell_id}"]${outputOnly ? " > pluto-output" : ""}`)
5755
if (cell) {
56+
await cell.scrollIntoView()
57+
await cell.boundingBox()
5858
await cell.scrollIntoView()
5959
const rect = await cell.boundingBox()
6060
if (rect == null) {
6161
throw new Error(`Cell ${cell_id} is not visible`)
6262
}
63-
const imgpath = path.join(screenshot_dir, `${cell_id}.png`)
6463

65-
await cell.screenshot({ path: imgpath, clip: { ...rect, scale }, omitBackground: false })
66-
console.log(`Screenshot ${cell_id} saved to ${imgpath}`)
64+
if (screenshot_dir != null) {
65+
const imgpath = path.join(screenshot_dir, `${cell_id}.png`)
66+
67+
await cell.screenshot({ path: imgpath, clip: { ...rect, scale }, omitBackground: false })
68+
console.log(`Screenshot ${cell_id} saved to ${imgpath}`)
69+
}
6770
}
6871
}
6972
}

0 commit comments

Comments
 (0)