1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-22 02:12:44 +01:00

Harden scriptlet injections

This commit make it so scriptlet injections will occur
at the earliest possible time on all platform.

This should also fix the case reported at:
- https://www.reddit.com/r/uBlockOrigin/comments/ye6abt/

Which is caused by the fact that there is no webNavigation
events being fired by the browser. In such case, the changes
here will make it so that uBO will detect that the scriptlet
were not injected and will inject them at main content script
injection time.
This commit is contained in:
Raymond Hill 2022-10-27 14:16:21 -04:00
parent 2d3d57fbc8
commit bccd5a0264
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 8 additions and 11 deletions

View File

@ -19,6 +19,8 @@
Home: https://github.com/gorhill/uBlock
*/
/* globals browser */
'use strict';
/******************************************************************************/
@ -149,7 +151,6 @@ const µBlock = { // jshint ignore:line
privacySettingsSupported: vAPI.browserSettings instanceof Object,
cloudStorageSupported: vAPI.cloud instanceof Object,
canFilterResponseData: typeof browser.webRequest.filterResponseData === 'function',
canInjectScriptletsNow: vAPI.webextFlavor.soup.has('chromium'),
// https://github.com/chrisaljoudi/uBlock/issues/180
// Whitelist directives need to be loaded once the PSL is available

View File

@ -1362,6 +1362,9 @@ vAPI.DOMFilterer = class {
vAPI.messaging.send('contentscript', {
what: 'retrieveContentScriptParameters',
url: vAPI.effectiveSelf.location.href,
scriptletsInjected:
typeof self.uBO_scriptletsInjected === 'boolean' &&
self.uBO_scriptletsInjected,
}).then(response => {
bootstrapPhase1(response);
});

View File

@ -773,10 +773,7 @@ const retrieveContentScriptParameters = async function(sender, request) {
// https://github.com/uBlockOrigin/uBlock-issues/issues/688#issuecomment-748179731
// For non-network URIs, scriptlet injection is deferred to here. The
// effective URL is available here in `request.url`.
if (
µb.canInjectScriptletsNow === false ||
isNetworkURI(sender.frameURL) === false
) {
if ( request.scriptletsInjected !== true ) {
scriptletFilteringEngine.injectNow(request);
}

View File

@ -95,6 +95,7 @@ const contentscriptCode = (( ) => {
) {
return;
}
self.uBO_scriptletsInjected = true;
const injectScriptlets = function(d) {
let script;
try {

View File

@ -41,7 +41,6 @@ import {
import {
domainFromHostname,
hostnameFromURI,
isNetworkURI,
originFromURI,
} from './uri-utils.js';
@ -930,11 +929,7 @@ vAPI.Tabs = class extends vAPI.Tabs {
const pageStore = µb.pageStoreFromTabId(tabId);
if ( pageStore === null ) { return; }
pageStore.setFrameURL(details);
if (
µb.canInjectScriptletsNow &&
isNetworkURI(url) &&
pageStore.getNetFilteringSwitch()
) {
if ( pageStore.getNetFilteringSwitch() ) {
scriptletFilteringEngine.injectNow(details);
}
}