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 f45ee80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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 puppeter, 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
12 changes: 9 additions & 3 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const processPage = ({
doms,
allHrefs,
redirectResponses,
skippedUrls
skippedUrls,
timeoutAsWarning
}) =>
new Promise(async (resolve, reject) => {
// If anything goes wrong, for example a `pageerror` event or
Expand All @@ -128,7 +129,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 +137,14 @@ 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.
console.warn(error.message);
return;
}
}
fulfilledPromise = true;
tracker.dispose();
reject(error);
};
Expand Down Expand Up @@ -377,7 +383,7 @@ const minimalcss = async options => {
doms,
allHrefs,
redirectResponses,
skippedUrls
skippedUrls,
});
} catch (e) {
throw e;
Expand Down

0 comments on commit f45ee80

Please sign in to comment.