Skip to content

Commit

Permalink
feat: add puppeteerArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiefORZ committed May 26, 2023
1 parent 19c9414 commit 16303bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bin/epilogue.ts
Original file line number Diff line number Diff line change
@@ -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"',
},
];

Expand Down
7 changes: 7 additions & 0 deletions bin/pdf-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface IArgs {
input: string;
chromeExecutable: string;
outputPath?: string;
puppeteerArgs?: string[];
}

const pdfGenerator = async (args: IArgs) => {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 16303bd

Please sign in to comment.