mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-04 01:59:38 +02: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;
|
return;
|
||||||
}
|
}
|
||||||
self.uBO_scriptletsInjected = true;
|
|
||||||
const injectScriptlets = function(d) {
|
const injectScriptlets = function(d) {
|
||||||
let script;
|
let script;
|
||||||
try {
|
try {
|
||||||
@ -105,12 +104,11 @@ const contentscriptCode = (( ) => {
|
|||||||
decodeURIComponent(scriptlets))
|
decodeURIComponent(scriptlets))
|
||||||
);
|
);
|
||||||
(d.head || d.documentElement).appendChild(script);
|
(d.head || d.documentElement).appendChild(script);
|
||||||
|
self.uBO_scriptletsInjected = true;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
if ( script ) {
|
if ( script ) {
|
||||||
if ( script.parentNode ) {
|
script.remove();
|
||||||
script.parentNode.removeChild(script);
|
|
||||||
}
|
|
||||||
script.textContent = '';
|
script.textContent = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* globals browser */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -933,10 +933,7 @@ vAPI.Tabs = class extends vAPI.Tabs {
|
|||||||
const pageStore = µb.pageStoreFromTabId(tabId);
|
const pageStore = µb.pageStoreFromTabId(tabId);
|
||||||
if ( pageStore === null ) { return; }
|
if ( pageStore === null ) { return; }
|
||||||
pageStore.setFrameURL(details);
|
pageStore.setFrameURL(details);
|
||||||
if (
|
if ( pageStore.getNetFilteringSwitch() ) {
|
||||||
vAPI.webextFlavor.soup.has('firefox') === false &&
|
|
||||||
pageStore.getNetFilteringSwitch()
|
|
||||||
) {
|
|
||||||
scriptletFilteringEngine.injectNow(details);
|
scriptletFilteringEngine.injectNow(details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* globals browser */
|
||||||
|
|
||||||
'use strict';
|
'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 = {
|
const webRequest = {
|
||||||
onBeforeRequest,
|
onBeforeRequest,
|
||||||
|
|
||||||
@ -1148,6 +1155,19 @@ const webRequest = {
|
|||||||
{ urls: [ 'http://*/*', 'https://*/*' ] },
|
{ urls: [ 'http://*/*', 'https://*/*' ] },
|
||||||
[ 'blocking', 'responseHeaders' ]
|
[ '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 });
|
vAPI.net.unsuspend({ all: true });
|
||||||
};
|
};
|
||||||
})(),
|
})(),
|
||||||
|
Loading…
Reference in New Issue
Block a user