Skip to content

Commit

Permalink
Add option timeoutAsWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed Aug 8, 2018
1 parent e6bad39 commit 9887209
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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
10 changes: 8 additions & 2 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 @@ -137,8 +136,15 @@ const processPage = ({
)}`;
} else if (urls.length > 0) {
error.message += `\nFor ${urls[0]}`;
} else if (options.timeoutAsWarning) {
// 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(error.message);
return;
}
}
fulfilledPromise = true;
tracker.dispose();
reject(error);
};
Expand Down Expand Up @@ -339,7 +345,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

0 comments on commit 9887209

Please sign in to comment.