@@ -235,14 +235,10 @@ 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-
242238 const enableInterception =
243239 ( onPageRequest || abortTypes . length > 0 ) &&
244240 run ( {
245- fn : page . setRequestInterception ( true ) . then ( ( ) => ( isRequestInterceptionEnabled = true ) ) ,
241+ fn : page . setRequestInterception ( true ) ,
246242 debug : 'enableInterception'
247243 } )
248244
@@ -273,15 +269,28 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
273269 }
274270
275271 if ( adblock ) {
276- page . disableAdblock = async ( ) => {
277- await engine . disableBlockingInPage ( page )
278- isRequestInterceptionEnabled = false
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+
279288 debug . adblock ( 'disabled' )
280289 }
281290
282291 prePromises . push (
283292 run ( {
284- fn : engine . enableBlockingInPage ( page ) ,
293+ fn : engine . enableBlockingInPage ( page ) . then ( context => ( adblockContext = context ) ) ,
285294 timeout : actionTimeout ,
286295 debug : 'adblock'
287296 } )
0 commit comments