diff --git a/src/js/scriptlet-filtering.js b/src/js/scriptlet-filtering.js index 1a8e2901fdd86..9b6ba7251d5ef 100644 --- a/src/js/scriptlet-filtering.js +++ b/src/js/scriptlet-filtering.js @@ -96,7 +96,6 @@ const contentscriptCode = (( ) => { ) { return; } - self.uBO_scriptletsInjected = true; const injectScriptlets = function(d) { let script; try { @@ -105,12 +104,11 @@ const contentscriptCode = (( ) => { decodeURIComponent(scriptlets)) ); (d.head || d.documentElement).appendChild(script); + self.uBO_scriptletsInjected = true; } catch (ex) { } if ( script ) { - if ( script.parentNode ) { - script.parentNode.removeChild(script); - } + script.remove(); script.textContent = ''; } }; diff --git a/src/js/start.js b/src/js/start.js index 0f8fd308ebf05..f5b086c64b9f2 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -19,6 +19,8 @@ Home: https://github.com/gorhill/uBlock */ +/* globals browser */ + 'use strict'; /******************************************************************************/ diff --git a/src/js/tab.js b/src/js/tab.js index c6da477f851c2..1bd03c1806c86 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -933,10 +933,7 @@ vAPI.Tabs = class extends vAPI.Tabs { const pageStore = µb.pageStoreFromTabId(tabId); if ( pageStore === null ) { return; } pageStore.setFrameURL(details); - if ( - vAPI.webextFlavor.soup.has('firefox') === false && - pageStore.getNetFilteringSwitch() - ) { + if ( pageStore.getNetFilteringSwitch() ) { scriptletFilteringEngine.injectNow(details); } } diff --git a/src/js/traffic.js b/src/js/traffic.js index b8b1c7781eec2..a653d036867ab 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -19,6 +19,8 @@ Home: https://github.com/gorhill/uBlock */ +/* globals browser */ + 'use strict'; /******************************************************************************/ @@ -1131,6 +1133,11 @@ const strictBlockBypasser = { /******************************************************************************/ +// https://github.com/uBlockOrigin/uBlock-issues/issues/2350 +// Added scriptlet injection attempt at onResponseStarted time as per +// https://github.com/AdguardTeam/AdguardBrowserExtension/issues/1029 and +// https://github.com/AdguardTeam/AdguardBrowserExtension/blob/9ab85be5/Extension/src/background/webrequest.js#L620 + const webRequest = { onBeforeRequest, @@ -1148,6 +1155,19 @@ const webRequest = { { urls: [ 'http://*/*', 'https://*/*' ] }, [ 'blocking', 'responseHeaders' ] ); + vAPI.net.addListener( + 'onResponseStarted', + details => { + const pageStore = µb.pageStoreFromTabId(details.tabId); + if ( pageStore === null ) { return; } + if ( pageStore.getNetFilteringSwitch() === false ) { return; } + scriptletFilteringEngine.injectNow(details); + }, + { + types: [ 'main_frame', 'sub_frame' ], + urls: [ 'http://*/*', 'https://*/*' ] + } + ); vAPI.net.unsuspend({ all: true }); }; })(),