Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option timeoutAsWarning #248

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ key is `urls`. Other optional options are:
of strings for headless Chrome](https://peter.sh/experiments/chromium-command-line-switches/).
* `cssoOptions` - CSSO compress function [options](https://github.com/css/csso#compressast-options)
* `timeout` - Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
* `timeoutAsWarning` - This is workaround for the [bug in puppeteer](https://github.com/GoogleChrome/puppeteer/issues/1908#issuecomment-390214976), when there are no open connections but puppeteer reports it as timeout anyway. If you set it to true minimalcss will report timeouts as warnings instead of rejection. Take a note real timeouts still be reported as errors.

## Warnings

Expand Down
20 changes: 17 additions & 3 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ const processPage = ({
const tracker = createTracker(page);
const safeReject = error => {
if (fulfilledPromise) return;
fulfilledPromise = true;
if (error.message.startsWith('Navigation Timeout Exceeded')) {
const urls = tracker.urls();
if (urls.length > 1) {
Expand All @@ -139,6 +138,7 @@ const processPage = ({
error.message += `\nFor ${urls[0]}`;
}
}
fulfilledPromise = true;
tracker.dispose();
reject(error);
};
Expand Down Expand Up @@ -285,7 +285,21 @@ const processPage = ({
// Second, goto the page and evaluate it with JavaScript.
// The 'waitUntil' option determines how long we wait for all
// possible assets to load.
response = await page.goto(pageUrl, { waitUntil: 'networkidle0' });
try {
response = await page.goto(pageUrl, { waitUntil: 'networkidle0' });
Copy link
Collaborator Author

@stereobooster stereobooster Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work, we do not have response in case of error

} catch (e) {
if (
options.timeoutAsWarning &&
e.message &&
e.message.startsWith('Navigation Timeout Exceeded') &&
tracker.urls().length === 0
) {
// This is workaround for the bug in puppeter, when there are
// no open connections but puppeteer reports it as timeout anyway.
// https://github.com/GoogleChrome/puppeteer/issues/1908#issuecomment-390214976
console.warn(e.message);
}
}
if (!isOk(response)) {
return safeReject(
new Error(`${response.status()} on ${pageUrl} (second time)`)
Expand Down Expand Up @@ -339,7 +353,7 @@ const processPage = ({

/**
*
* @param {{ urls: Array<string>, debug: boolean, loadimages: boolean, skippable: function, browser: any, userAgent: string, withoutjavascript: boolean, viewport: any, puppeteerArgs: Array<string>, cssoOptions: Object }} options
* @param {{ urls: Array<string>, debug: boolean, loadimages: boolean, skippable: function, browser: any, userAgent: string, withoutjavascript: boolean, viewport: any, puppeteerArgs: Array<string>, cssoOptions: Object, timeoutAsWarning?: boolean }} options
* @return Promise<{ finalCss: string, stylesheetContents: { [key: string]: string } }>
*/
const minimalcss = async options => {
Expand Down