@browserless/goto 9.3.0-beta.6 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@browserless/goto",
3
3
  "description": "Go to a page aborting unnecessary requests",
4
4
  "homepage": "https://browserless.js.org/#/?id=gotopage-options",
5
- "version": "9.3.0-beta.6",
5
+ "version": "9.3.0",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -29,17 +29,17 @@
29
29
  "puppeteer"
30
30
  ],
31
31
  "dependencies": {
32
- "@browserless/devices": "^9.2.22",
32
+ "@browserless/devices": "^9.3.0",
33
33
  "@cliqz/adblocker-puppeteer": "~1.23.0",
34
34
  "debug-logfmt": "~1.0.4",
35
- "got": "~11.8.2",
36
- "is-url-http": "~2.2.4",
35
+ "got": "~11.8.3",
36
+ "is-url-http": "~2.2.5",
37
37
  "p-reflect": "~2.1.0",
38
38
  "p-timeout": "~4.1.0",
39
39
  "pretty-ms": "~7.0.1",
40
40
  "shallow-equal": "~1.2.1",
41
41
  "time-span": "~4.0.0",
42
- "top-user-agents": "~1.0.38",
42
+ "top-user-agents": "~1.0.39",
43
43
  "tough-cookie": "~4.0.0",
44
44
  "unique-random-array": "~2.0.0"
45
45
  },
@@ -68,5 +68,5 @@
68
68
  "timeout": "2m",
69
69
  "verbose": true
70
70
  },
71
- "gitHead": "086fad1111f335b62fbdb628a86de0183e2ad12f"
71
+ "gitHead": "489d6fffc2e001fba2961838b73d10f916862676"
72
72
  }
package/src/engine.bin CHANGED
Binary file
package/src/index.js CHANGED
@@ -24,7 +24,6 @@ const engine = PuppeteerBlocker.deserialize(
24
24
 
25
25
  engine.on('request-blocked', ({ url }) => debugAdblock('block', url))
26
26
  engine.on('request-redirected', ({ url }) => debugAdblock('redirect', url))
27
- engine.setRequestInterceptionPriority(1)
28
27
 
29
28
  const isEmpty = val => val == null || !(Object.keys(val) || val).length
30
29
 
@@ -92,37 +91,38 @@ const disableAnimations = `
92
91
  }
93
92
  `.trim()
94
93
 
95
- // related https://github.com/puppeteer/puppeteer/issues/1353
96
- const createWaitUntilAuto = defaultOpts => (page, opts) => {
97
- const { timeout } = { ...defaultOpts, ...opts }
98
-
99
- return Promise.all(
100
- [
101
- {
102
- fn: () => page.waitForNavigation({ waitUntil: 'networkidle2' }),
103
- debug: 'waitUntilAuto:waitForNavigation'
104
- },
105
- {
106
- fn: () => page.evaluate(() => window.history.pushState(null, null, null)),
107
- debug: 'waitUntilAuto:pushState'
108
- }
109
- ].map(({ fn, ...opts }) => run({ fn: fn(), timeout, ...opts }))
110
- )
111
- }
112
-
113
94
  module.exports = ({
114
95
  evasions = ALL_EVASIONS_KEYS,
115
96
  defaultDevice = 'Macbook Pro 13',
116
97
  timeout: globalTimeout,
117
98
  ...deviceOpts
118
99
  }) => {
119
- const baseTimeout = globalTimeout * (1 / 2)
120
- const actionTimeout = baseTimeout * (1 / 8)
121
-
122
100
  const getDevice = createDevices(deviceOpts)
123
101
  const { viewport: defaultViewport } = getDevice.findDevice(defaultDevice)
124
102
 
125
- const _waitUntilAuto = createWaitUntilAuto({ timeout: actionTimeout })
103
+ const timeouts = {
104
+ base: (milliseconds = globalTimeout) => milliseconds * (2 / 3),
105
+ action: (milliseconds = globalTimeout) => milliseconds * (1 / 11),
106
+ goto: (milliseconds = globalTimeout) => milliseconds * (7 / 8)
107
+ }
108
+
109
+ // related https://github.com/puppeteer/puppeteer/issues/1353
110
+ const _waitUntilAuto = (page, opts = {}) => {
111
+ const timeout = timeouts.action(opts.timeout)
112
+
113
+ return Promise.all(
114
+ [
115
+ {
116
+ fn: () => page.waitForNavigation({ waitUntil: 'networkidle2' }),
117
+ debug: 'waitUntilAuto:waitForNavigation'
118
+ },
119
+ {
120
+ fn: () => page.evaluate(() => window.history.pushState(null, null, null)),
121
+ debug: 'waitUntilAuto:pushState'
122
+ }
123
+ ].map(({ fn, ...opts }) => run({ fn: fn(), timeout, ...opts }))
124
+ )
125
+ }
126
126
 
127
127
  const goto = async (
128
128
  page,
@@ -142,7 +142,7 @@ module.exports = ({
142
142
  scripts,
143
143
  scroll,
144
144
  styles,
145
- timeout = baseTimeout,
145
+ timeout = globalTimeout,
146
146
  timezone,
147
147
  url,
148
148
  waitForFunction,
@@ -154,6 +154,10 @@ module.exports = ({
154
154
  ...args
155
155
  }
156
156
  ) => {
157
+ const baseTimeout = timeouts.base(globalTimeout)
158
+ const actionTimeout = timeouts.action(baseTimeout)
159
+ const gotoTimeout = timeouts.goto(baseTimeout)
160
+
157
161
  const isWaitUntilAuto = waitUntil === 'auto'
158
162
  if (isWaitUntilAuto) waitUntil = 'load'
159
163
 
@@ -162,13 +166,15 @@ module.exports = ({
162
166
  if (abortTypes.length > 0) {
163
167
  await page.setRequestInterception(true)
164
168
  page.on('request', req => {
169
+ if (req.isInterceptResolutionHandled()) return
170
+
165
171
  const resourceType = req.resourceType()
166
172
  if (!abortTypes.includes(resourceType)) {
167
173
  debug('continue', { url: req.url(), resourceType })
168
- return req.continue(req.continueRequestOverrides(), 2)
174
+ return req.continue(req.continueRequestOverrides(), 0)
169
175
  }
170
176
  debug('abort', { url: req.url(), resourceType })
171
- return req.abort('blockedbyclient', 2)
177
+ return req.abort('blockedbyclient', 0)
172
178
  })
173
179
  }
174
180
 
@@ -277,7 +283,7 @@ module.exports = ({
277
283
 
278
284
  const { value } = await run({
279
285
  fn: html ? page.setContent(html, args) : page.goto(url, args),
280
- timeout: timeout * 0.8,
286
+ timeout: gotoTimeout,
281
287
  debug: html ? 'html' : 'url'
282
288
  })
283
289
 
@@ -288,7 +294,7 @@ module.exports = ({
288
294
  waitForTimeout
289
295
  })) {
290
296
  if (value) {
291
- await run({ fn: page[key](value), timeout: actionTimeout, debug: { [key]: value } })
297
+ await run({ fn: page[key](value), timeout: gotoTimeout, debug: { [key]: value } })
292
298
  }
293
299
  }
294
300
 
@@ -370,7 +376,11 @@ module.exports = ({
370
376
 
371
377
  if (click) {
372
378
  for (const selector of castArray(click)) {
373
- await run({ fn: page.click(selector), timeout: actionTimeout, debug: { click: selector } })
379
+ await run({
380
+ fn: page.click(selector),
381
+ timeout: actionTimeout,
382
+ debug: { click: selector }
383
+ })
374
384
  }
375
385
  }
376
386
 
@@ -395,8 +405,7 @@ module.exports = ({
395
405
  goto.deviceDescriptors = getDevice.deviceDescriptors
396
406
  goto.defaultViewport = defaultViewport
397
407
  goto.waitUntilAuto = _waitUntilAuto
398
- goto.timeout = baseTimeout
399
- goto.actionTimeout = actionTimeout
408
+ goto.timeouts = timeouts
400
409
  goto.run = run
401
410
 
402
411
  return goto