Skip to content

Commit dcba194

Browse files
committed
Extract default network events
1 parent 3f2ef88 commit dcba194

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const { devices, getDevice } = require('./devices')
1010

1111
const ABORT_TYPES = ['image', 'media', 'stylesheet', 'font', 'xhr']
1212

13+
const WAIT_UNTIL = ['networkidle2', 'load', 'domcontentloaded']
14+
1315
module.exports = launchOpts => {
1416
let browser = puppeteer.launch(launchOpts)
1517

@@ -26,15 +28,8 @@ module.exports = launchOpts => {
2628
return text
2729
}
2830

29-
const html = async (
30-
url,
31-
opts = {
32-
waitFor: 0,
33-
waitUntil: ['networkidle2'],
34-
abortTypes: ABORT_TYPES
35-
}
36-
) => {
37-
const { abortTypes, waitFor } = opts
31+
const html = async (url, opts = {}) => {
32+
const { abortTypes = ABORT_TYPES, waitFor = 0, ...gotoOpts } = opts
3833

3934
const page = await newPage()
4035
await page.setRequestInterception(true)
@@ -47,7 +42,7 @@ module.exports = launchOpts => {
4742
return req[action]()
4843
})
4944

50-
await page.goto(url, opts)
45+
await page.goto(url, Object.assign({ waitUntil: WAIT_UNTIL }), gotoOpts)
5146
if (waitFor) await page.waitFor(waitFor)
5247
const content = await page.content()
5348

0 commit comments

Comments
 (0)