@browserless/goto 10.9.1 → 10.9.4

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +25 -5
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": "10.9.1",
5
+ "version": "10.9.4",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -64,5 +64,5 @@
64
64
  "timeout": "2m",
65
65
  "workerThreads": false
66
66
  },
67
- "gitHead": "be10f67b4113601686e30986e164158ceb6f32be"
67
+ "gitHead": "240ff54b29114b5f8525bd6b225d5aa6432c98ca"
68
68
  }
package/src/index.js CHANGED
@@ -237,10 +237,15 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
237
237
 
238
238
  const enableInterception =
239
239
  (onPageRequest || abortTypes.length > 0) &&
240
- run({ fn: page.setRequestInterception(true), debug: 'enableInterception' })
240
+ run({
241
+ fn: page.setRequestInterception(true),
242
+ debug: 'enableInterception'
243
+ })
241
244
 
242
245
  if (onPageRequest) {
243
- Promise.resolve(enableInterception).then(() => page.on('request', onPageRequest))
246
+ Promise.resolve(enableInterception).then(() =>
247
+ page.on('request', req => onPageRequest(req, page))
248
+ )
244
249
  }
245
250
 
246
251
  if (abortTypes.length > 0) {
@@ -264,13 +269,28 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
264
269
  }
265
270
 
266
271
  if (adblock) {
267
- page.disableAdblock = async () => {
268
- await engine.disableBlockingInPage(page)
272
+ let adblockContext
273
+
274
+ page.disableAdblock = () => {
275
+ // TODO: drop this when https://github.com/ghostery/adblocker/pull/5161 is merged
276
+
277
+ engine.contexts.delete(page)
278
+
279
+ if (adblockContext.blocker.config.loadNetworkFilters) {
280
+ adblockContext.page.off('request', adblockContext.onRequest)
281
+ }
282
+
283
+ if (adblockContext.blocker.config.loadCosmeticFilters) {
284
+ adblockContext.page.off('frameattached', adblockContext.onFrameNavigated)
285
+ adblockContext.page.off('domcontentloaded', adblockContext.onDomContentLoaded)
286
+ }
287
+
269
288
  debug.adblock('disabled')
270
289
  }
290
+
271
291
  prePromises.push(
272
292
  run({
273
- fn: engine.enableBlockingInPage(page),
293
+ fn: engine.enableBlockingInPage(page).then(context => (adblockContext = context)),
274
294
  timeout: actionTimeout,
275
295
  debug: 'adblock'
276
296
  })