Further ensure scriptlets are actually injected

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/ye6abt/

Possibly because the Opera sidebar window is a special
case, it appears the scriptlets must be injected at a
later time.

Use a global isolated window variable to detect whether
the scriptlets have really be injected, and ultimately
inject them at main content script time when it is found
they haven't been injected at that point.
This commit is contained in:
Raymond Hill 2022-10-27 15:52:03 -04:00
parent 0a55767ea3
commit d1f8a05d2d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 16 additions and 13 deletions

View File

@ -1331,7 +1331,8 @@ vAPI.DOMFilterer = class {
// Library of resources is located at:
// https://github.com/gorhill/uBlock/blob/master/assets/ublock/resources.txt
if ( scriptlets ) {
if ( scriptlets && typeof self.uBO_scriptletsInjected !== 'boolean' ) {
self.uBO_scriptletsInjected = true;
vAPI.injectScriptlet(document, scriptlets);
vAPI.injectedScripts = scriptlets;
}
@ -1362,9 +1363,7 @@ vAPI.DOMFilterer = class {
vAPI.messaging.send('contentscript', {
what: 'retrieveContentScriptParameters',
url: vAPI.effectiveSelf.location.href,
scriptletsInjected:
typeof self.uBO_scriptletsInjected === 'boolean' &&
self.uBO_scriptletsInjected,
needScriptlets: typeof self.uBO_scriptletsInjected !== 'boolean',
}).then(response => {
bootstrapPhase1(response);
});

View File

@ -773,8 +773,8 @@ 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 ( request.scriptletsInjected !== true ) {
scriptletFilteringEngine.injectNow(request);
if ( request.needScriptlets ) {
response.scriptlets = scriptletFilteringEngine.injectNow(request);
}
// https://github.com/NanoMeow/QuickReports/issues/6#issuecomment-414516623

View File

@ -432,13 +432,17 @@ scriptletFilteringEngine.injectNow = function(details) {
matchAboutBlank: true,
runAt: 'document_start',
});
if ( logEntries === undefined ) { return; }
promise.then(results => {
if ( Array.isArray(results) === false || results[0] !== 0 ) { return; }
for ( const entry of logEntries ) {
logOne(entry.tabId, entry.url, entry.token);
}
});
if ( logEntries !== undefined ) {
promise.then(results => {
if ( Array.isArray(results) === false || results[0] !== 0 ) {
return;
}
for ( const entry of logEntries ) {
logOne(entry.tabId, entry.url, entry.token);
}
});
}
return scriptlets;
};
scriptletFilteringEngine.toSelfie = function() {