From 16303bd52b91a893b1148e4918e49cfca3babf2a Mon Sep 17 00:00:00 2001 From: ChiefORZ Date: Fri, 26 May 2023 13:09:49 +0700 Subject: [PATCH] feat: add puppeteerArgs --- bin/epilogue.ts | 14 ++++++++------ bin/pdf-generator.ts | 7 +++++++ src/index.ts | 2 ++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/epilogue.ts b/bin/epilogue.ts index 5ff2ebb..f687798 100644 --- a/bin/epilogue.ts +++ b/bin/epilogue.ts @@ -1,18 +1,20 @@ const examples = [ { description: 'Generate a PDF from a URL using pipe', - example: - '$0 https://google.com -c "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" > ./google.pdf', + example: '$0 https://google.com > ./google.pdf', }, { description: 'Generate a PDF from a URL on the desired path', - example: - '$0 https://google.com -c "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" -o ./google.pdf', + example: '$0 https://google.com -o ./google.pdf', }, { description: 'Generate a PDF from a statically built website', - example: - '$0 ./my-website -c "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" -o ./website.pdf', + example: '$0 ./my-website -o ./website.pdf', + }, + { + description: + 'Additional command line arguments can be passed to the browser instance using the --puppeteer-args option. For example, to run the browser in headless mode', + example: '$0 https://google.com --puppeteer-args="--headless"', }, ]; diff --git a/bin/pdf-generator.ts b/bin/pdf-generator.ts index 5c3991d..9ac4412 100755 --- a/bin/pdf-generator.ts +++ b/bin/pdf-generator.ts @@ -34,6 +34,13 @@ void (async () => { 'The path to the chromium executable that will be used by puppeteer', optional: true, }, + 'puppeteer-args': { + alias: 'p', + type: 'array', + describe: + 'Additional command line arguments to pass to the browser instance.', + optional: true, + }, }) .epilogue(epilogue) .parseSync(); diff --git a/src/index.ts b/src/index.ts index 0783d21..249e824 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,6 +49,7 @@ interface IArgs { input: string; chromeExecutable: string; outputPath?: string; + puppeteerArgs?: string[]; } const pdfGenerator = async (args: IArgs) => { @@ -98,6 +99,7 @@ const pdfGenerator = async (args: IArgs) => { const browser = await puppeteer.launch({ executablePath: chromeExecutable, headless: true, + args: args?.puppeteerArgs ?? [], }); const page = await browser.newPage();