Skip to content

Commit

Permalink
Accept waitForNavigation options
Browse files Browse the repository at this point in the history
  • Loading branch information
samkpower committed Aug 1, 2019
1 parent 863f2e0 commit e4e049d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/renderers/chrome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,27 @@ export class ChromeRenderer extends Renderer {
}

async renderPage(page, options = {}) {
let { path: filepath, type } = options;
let { path: filepath, type, waitForNavigation } = options;
let buffer;

if (!isString(type)) {
type = isString(filepath) ? path.extname(filepath).slice(1) : 'html';
type = type.length > 0 ? type : 'html';
}

if (waitForNavigation !== false) {
if (waitForNavigation === Object(waitForNavigation)) {
await page._chromePage.waitForNavigation(waitForNavigation);
} else {
await page._chromePage.waitForNavigation({
waitUntil: 'networkidle',
networkIdleInflight: 0,
timeout: 0
});
}
delete options.waitForNavigation;
}

switch (type) {
case 'html':
buffer = await page._chromePage.content();
Expand All @@ -134,12 +147,6 @@ export class ChromeRenderer extends Renderer {
delete options.emulateMedia;
}

await page._chromePage.waitForNavigation({
waitUntil: 'networkidle',
networkIdleInflight: 0,
timeout: 0
});

buffer = await page._chromePage.pdf(options);
break;
default:
Expand Down

0 comments on commit e4e049d

Please sign in to comment.