@browserless/goto 9.7.3 → 9.8.1

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.7.3",
5
+ "version": "9.8.1",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -37,7 +37,7 @@
37
37
  "p-reflect": "~2.1.0",
38
38
  "p-timeout": "~4.1.0",
39
39
  "pretty-ms": "~7.0.1",
40
- "shallow-equal": "~1.2.1",
40
+ "shallow-equal": "~3.0.0",
41
41
  "time-span": "~4.0.0",
42
42
  "top-user-agents": "~1.0.45",
43
43
  "tough-cookie": "~4.1.0",
@@ -69,6 +69,5 @@
69
69
  "serial": true,
70
70
  "timeout": "30s",
71
71
  "verbose": true
72
- },
73
- "gitHead": "4a392f7661d15273bc96de328789ef57afe2d682"
72
+ }
74
73
  }
package/src/engine.bin CHANGED
Binary file
package/src/index.js CHANGED
@@ -212,6 +212,7 @@ module.exports = ({
212
212
  waitForXPath,
213
213
  waitUntil = 'auto',
214
214
  waitUntilAuto = _waitUntilAuto,
215
+ onPageRequest,
215
216
  ...args
216
217
  }
217
218
  ) => {
@@ -244,19 +245,27 @@ module.exports = ({
244
245
  )
245
246
  }
246
247
 
248
+ const enableInterception =
249
+ (onPageRequest || abortTypes.length > 0) && page.setRequestInterception(true)
250
+
251
+ if (onPageRequest) {
252
+ Promise.resolve(enableInterception).then(() => page.on('request', onPageRequest))
253
+ }
254
+
247
255
  if (abortTypes.length > 0) {
248
- await page.setRequestInterception(true)
249
- page.on('request', req => {
250
- if (req.isInterceptResolutionHandled()) return
251
- const resourceType = req.resourceType()
252
- const url = truncate(req.url())
253
-
254
- if (!abortTypes.includes(resourceType)) {
255
- debug('continue', { url, resourceType })
256
- return req.continue(req.continueRequestOverrides(), 0)
257
- }
258
- debug('abort', { url, resourceType })
259
- return req.abort('blockedbyclient', 0)
256
+ Promise.resolve(enableInterception).then(() => {
257
+ page.on('request', req => {
258
+ if (req.isInterceptResolutionHandled()) return
259
+ const resourceType = req.resourceType()
260
+ const url = truncate(req.url())
261
+
262
+ if (!abortTypes.includes(resourceType)) {
263
+ debug('continue', { url, resourceType })
264
+ return req.continue(req.continueRequestOverrides(), 0)
265
+ }
266
+ debug('abort', { url, resourceType })
267
+ return req.abort('blockedbyclient', 0)
268
+ })
260
269
  })
261
270
  }
262
271