Skip to content

Commit d594ac3

Browse files
authored
chore(goto): add isRequestInterceptionEnabled helper (#623)
1 parent be10f67 commit d594ac3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/goto/src/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,21 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
235235
)
236236
}
237237

238+
// TODO: drop this when https://github.com/ghostery/adblocker/pull/5161 is merged
239+
let isRequestInterceptionEnabled = false
240+
page.isRequestInterceptionEnabled = () => isRequestInterceptionEnabled
241+
238242
const enableInterception =
239243
(onPageRequest || abortTypes.length > 0) &&
240-
run({ fn: page.setRequestInterception(true), debug: 'enableInterception' })
244+
run({
245+
fn: page.setRequestInterception(true).then(() => (isRequestInterceptionEnabled = true)),
246+
debug: 'enableInterception'
247+
})
241248

242249
if (onPageRequest) {
243-
Promise.resolve(enableInterception).then(() => page.on('request', onPageRequest))
250+
Promise.resolve(enableInterception).then(() =>
251+
page.on('request', req => onPageRequest(req, page))
252+
)
244253
}
245254

246255
if (abortTypes.length > 0) {
@@ -266,8 +275,10 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
266275
if (adblock) {
267276
page.disableAdblock = async () => {
268277
await engine.disableBlockingInPage(page)
278+
isRequestInterceptionEnabled = false
269279
debug.adblock('disabled')
270280
}
281+
271282
prePromises.push(
272283
run({
273284
fn: engine.enableBlockingInPage(page),

0 commit comments

Comments
 (0)