mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +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:
parent
2d3d57fbc8
commit
bccd5a0264
@ -19,6 +19,8 @@
|
|||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* globals browser */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -149,7 +151,6 @@ const µBlock = { // jshint ignore:line
|
|||||||
privacySettingsSupported: vAPI.browserSettings instanceof Object,
|
privacySettingsSupported: vAPI.browserSettings instanceof Object,
|
||||||
cloudStorageSupported: vAPI.cloud instanceof Object,
|
cloudStorageSupported: vAPI.cloud instanceof Object,
|
||||||
canFilterResponseData: typeof browser.webRequest.filterResponseData === 'function',
|
canFilterResponseData: typeof browser.webRequest.filterResponseData === 'function',
|
||||||
canInjectScriptletsNow: vAPI.webextFlavor.soup.has('chromium'),
|
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/180
|
// https://github.com/chrisaljoudi/uBlock/issues/180
|
||||||
// Whitelist directives need to be loaded once the PSL is available
|
// Whitelist directives need to be loaded once the PSL is available
|
||||||
|
@ -1362,6 +1362,9 @@ vAPI.DOMFilterer = class {
|
|||||||
vAPI.messaging.send('contentscript', {
|
vAPI.messaging.send('contentscript', {
|
||||||
what: 'retrieveContentScriptParameters',
|
what: 'retrieveContentScriptParameters',
|
||||||
url: vAPI.effectiveSelf.location.href,
|
url: vAPI.effectiveSelf.location.href,
|
||||||
|
scriptletsInjected:
|
||||||
|
typeof self.uBO_scriptletsInjected === 'boolean' &&
|
||||||
|
self.uBO_scriptletsInjected,
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
bootstrapPhase1(response);
|
bootstrapPhase1(response);
|
||||||
});
|
});
|
||||||
|
@ -773,10 +773,7 @@ const retrieveContentScriptParameters = async function(sender, request) {
|
|||||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/688#issuecomment-748179731
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/688#issuecomment-748179731
|
||||||
// For non-network URIs, scriptlet injection is deferred to here. The
|
// For non-network URIs, scriptlet injection is deferred to here. The
|
||||||
// effective URL is available here in `request.url`.
|
// effective URL is available here in `request.url`.
|
||||||
if (
|
if ( request.scriptletsInjected !== true ) {
|
||||||
µb.canInjectScriptletsNow === false ||
|
|
||||||
isNetworkURI(sender.frameURL) === false
|
|
||||||
) {
|
|
||||||
scriptletFilteringEngine.injectNow(request);
|
scriptletFilteringEngine.injectNow(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ const contentscriptCode = (( ) => {
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
self.uBO_scriptletsInjected = true;
|
||||||
const injectScriptlets = function(d) {
|
const injectScriptlets = function(d) {
|
||||||
let script;
|
let script;
|
||||||
try {
|
try {
|
||||||
|
@ -41,7 +41,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
domainFromHostname,
|
domainFromHostname,
|
||||||
hostnameFromURI,
|
hostnameFromURI,
|
||||||
isNetworkURI,
|
|
||||||
originFromURI,
|
originFromURI,
|
||||||
} from './uri-utils.js';
|
} from './uri-utils.js';
|
||||||
|
|
||||||
@ -930,11 +929,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() ) {
|
||||||
µb.canInjectScriptletsNow &&
|
|
||||||
isNetworkURI(url) &&
|
|
||||||
pageStore.getNetFilteringSwitch()
|
|
||||||
) {
|
|
||||||
scriptletFilteringEngine.injectNow(details);
|
scriptletFilteringEngine.injectNow(details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user