mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-25 03:43:25 +01:00
Try to inject scriptlets at onResponseStarted() time
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2350 As per AdGuard findings, it's possible (though unreliable) to try to inject scriptlets at webRequest.onResponseStarted time, which increases scriptlet injection reliability overall when injecting from multiple entry points. uBO was already injecting at webNavigation.onCommitted and main content script time, and adding webRequest.onResponseStarted as an entry point for scriptlet injection increases reliability for webpages which executes inline scripts at the top of the DOM. References: - https://github.com/AdguardTeam/AdguardBrowserExtension/issues/1029 - https://github.com/AdguardTeam/AdguardBrowserExtension/blob/9ab85be5/Extension/src/background/webrequest.js#L620
This commit is contained in:
parent
e0e68a24d2
commit
49df063191
@ -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 = '';
|
||||
}
|
||||
};
|
||||
|
@ -19,6 +19,8 @@
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
/* globals browser */
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 });
|
||||
};
|
||||
})(),
|
||||
|
Loading…
Reference in New Issue
Block a user