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: // Library of resources is located at:
// https://github.com/gorhill/uBlock/blob/master/assets/ublock/resources.txt // 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.injectScriptlet(document, scriptlets);
vAPI.injectedScripts = scriptlets; vAPI.injectedScripts = scriptlets;
} }
@ -1362,9 +1363,7 @@ 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: needScriptlets: typeof self.uBO_scriptletsInjected !== 'boolean',
typeof self.uBO_scriptletsInjected === 'boolean' &&
self.uBO_scriptletsInjected,
}).then(response => { }).then(response => {
bootstrapPhase1(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 // 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 ( request.scriptletsInjected !== true ) { if ( request.needScriptlets ) {
scriptletFilteringEngine.injectNow(request); response.scriptlets = scriptletFilteringEngine.injectNow(request);
} }
// https://github.com/NanoMeow/QuickReports/issues/6#issuecomment-414516623 // https://github.com/NanoMeow/QuickReports/issues/6#issuecomment-414516623

View File

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