Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 17f9663

Browse files
toolmantimmarkdalgleish
authored andcommitted
fix(puppeteer): Wait until networkidle2 for better dev server support (#63)
Switches to networkidle2 during Puppeteer navigation, preventing timeouts when requesting pages that are served from development environments like webpack-dev-server (which holds open event- source sockets for HMR). The networkidle2 event is fired when there are no more than 2 network connections for at least 500 ms. If the page you're requesting has 2 or fewer resources that stall for longer than 500ms and doesn't complete loading, you can switch back to networkidle0 using the new `--puppeteer-wait-until` option.
1 parent ed60b44 commit 17f9663

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ $ html-sketchapp --puppeteer-args="--no-sandbox --disable-setuid-sandbox" --file
211211

212212
*Note: Because Puppeteer args are prefixed with hyphens, you **must** use an equals sign and quotes when providing this option via the command line (as seen above).*
213213

214+
### Puppeteer `waitUntil`
215+
216+
By default, Puppeteer is configured to consider the page loaded when there are no more than 2 network connections for at least 500ms (`networkidle2`). This is so that html-sketchapp-cli can handle development environments with long-lived connections.
217+
218+
If the page you're requesting has 2 or fewer resources that stall for longer than 500ms and doesn't complete loading, you can switch back to `networkidle0` via the `puppeteer-wait-until` argument:
219+
220+
```bash
221+
$ html-sketchapp --puppeteer-wait-until networkidle0 --file sketch.html --out-dir dist
222+
```
223+
224+
For the full list of available options for `waitUntil`, view the [Puppeteer `page.goto()` API documentation](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagegotourl-options).
225+
214226
### Chromium executable
215227

216228
If you'd like to override the Chromium used by Puppeteer, you can provide a path to the executable with the `puppeteer-executable-path` option.

bin/cli.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ require('yargs')
7575
'puppeteer-executable-path': {
7676
type: 'string',
7777
describe: 'Path to a Chromium executable to use instead of the one downloaded by Puppeteer.'
78+
},
79+
'puppeteer-wait-until': {
80+
type: 'string',
81+
describe: 'The Puppeteer navigation event to use before considering the page loaded.',
82+
default: 'networkidle2',
83+
choices: ['load', 'domcontentloaded', 'networkidle0', 'networkidle2']
7884
}
7985
}, async argv => {
8086
try {
@@ -106,7 +112,7 @@ require('yargs')
106112
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
107113
}
108114

109-
await page.goto(symbolsUrl, { waitUntil: 'networkidle0' });
115+
await page.goto(symbolsUrl, { waitUntil: argv.puppeteerWaitUntil });
110116

111117
const bundle = await rollup({
112118
input: path.resolve(__dirname, '../script/generateAlmostSketch.js'),

0 commit comments

Comments
 (0)