Skip to content

Commit

Permalink
Implement --puppeteer-page-pool-max
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmobrunfeldt committed Aug 16, 2021
1 parent 6980bc4 commit 29742c4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ kill $PID
--help Shows this help message
--puppeteer-launch-mode Options: launch, connect. Default: launch
--puppeteer-launch-options Puppeteer .launch or .connect options in JS. Default: {"headless":true}
--puppeteer-page-pool-max Maximum pages to use at the same time with Puppeteer. Default: 10
--include-hash When enabled, URL hashes are not ignored when crawling. Default: false
--include-search-query When enabled, URL search queries are not ignored when crawling. Default: false
--should-visit Custom JS function that can limit which links the crawler follows.
Expand Down
4 changes: 4 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export function formatHelp(defaultConfig: typeof _defaultConfig) {
--puppeteer-launch-options Puppeteer .launch or .connect options in JS. Default: ${JSON.stringify(
defaultConfig.puppeteerLaunchMode.options
)}
--puppeteer-page-pool-max Maximum pages to use at the same time with Puppeteer. Default: ${
defaultConfig.puppeteerPagePoolMax
}
--include-hash When enabled, URL hashes are not ignored when crawling. Default: ${
defaultConfig.includeHash
}
Expand Down Expand Up @@ -132,6 +135,7 @@ export function parseCliArgs() {
'--max-depth': Number,
'--puppeteer-launch-mode': String,
'--puppeteer-launch-options': String,
'--puppeteer-page-pool-max': Number,
'--after-goto': String,
'--after-page': String,
'--single-page': Boolean,
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type Config = {
shouldVisit?: string
trailingSlashMode: 'preserve' | 'remove' | 'add'
puppeteerLaunchMode: puppeteerLaunchMode
puppeteerPagePoolMax: number
maxDepth: number
outDir: string
outFile: string
Expand Down Expand Up @@ -55,6 +56,7 @@ export const defaultConfig = {
headless: true,
},
},
puppeteerPagePoolMax: 10,
outDir: '.squint',
screenshotOptions: {},
}
Expand Down Expand Up @@ -98,6 +100,8 @@ export function parseConfig() {
args['--puppeteer-launch-options'] ??
defaultConfig.puppeteerLaunchMode.options,
} as Config['puppeteerLaunchMode'],
puppeteerPagePoolMax:
args['--puppeteer-page-pool-max'] ?? defaultConfig.puppeteerPagePoolMax,
afterGoto: args['--after-goto'],
afterPage: args['--after-page'],
selector: args['--selector'],
Expand Down
2 changes: 1 addition & 1 deletion src/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function createPagePool(browser: Browser, config: Config) {
}

return genericPool.createPool(factory, {
max: 10,
max: config.puppeteerPagePoolMax,
min: 1,
})
}

0 comments on commit 29742c4

Please sign in to comment.