Skip to content

Commit 033f00c

Browse files
committed
html-to-pdf: optionally start Chromium with DevTools
This comes in _real_ handy for debugging. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 9606cbf commit 033f00c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

script/html-to-pdf.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const htmlToPDF = async (htmlPath, options) => {
3434
throw new Error(`Output file already exists: ${outputPath}`)
3535
}
3636

37-
const browser = await chromium.launch({ channel: 'chrome' })
37+
const browser = await chromium.launch({ channel: 'chrome', ...(options.devtools ? { devtools: true } : {}) })
3838
const page = await browser.newPage()
3939

4040
const htmlPathURL = url.pathToFileURL(htmlPath).toString()
@@ -76,6 +76,7 @@ const htmlToPDF = async (htmlPath, options) => {
7676
landscape: true,
7777
margin: { top: '0cm', bottom: '0cm', left: '0cm', right: '0cm' },
7878
})
79+
if (options.devtools) await new Promise((resolve) => { setTimeout(resolve, 5 * 60 * 1000) })
7980
await browser.close()
8081

8182
if (options.insertPDFLink) insertPDFLink(htmlPath)
@@ -87,6 +88,7 @@ while (args?.[0].startsWith('-')) {
8788
const arg = args.shift()
8889
if (arg === '--force' || arg === '-f') options.force = true
8990
else if (arg === '--insert-pdf-link' || arg === '-i') options.insertPDFLink = true
91+
else if (arg === '--devtools' || arg === '-d') options.devtools = true
9092
else throw new Error(`Unknown argument: ${arg}`)
9193
}
9294

0 commit comments

Comments
 (0)