1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

[mv3] Honor scriptlets' target world in Firefox

When the target world of a scriptlet is the ISOLATED one,
skip Blob-based injection in Firefox, as the current world
is always the ISOLATED one. This should make ISOLATED
world-based scriptlets more reliable (i.e. execute sooner)
in Firefox.
This commit is contained in:
Raymond Hill 2023-10-21 07:11:12 -04:00
parent 607bba6eaf
commit 6af4494946
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 6 additions and 1 deletions

View File

@ -59,6 +59,7 @@ export function init() {
const entry = {
name: fn.name,
code: fn.toString(),
world: scriptlet.world || 'MAIN',
dependencies: scriptlet.dependencies,
requiresTrust: scriptlet.requiresTrust === true,
};
@ -96,6 +97,7 @@ export function compile(details) {
scriptletFiles.set(scriptletToken, {
name: resourceEntry.name,
code: createScriptletCoreCode(scriptletToken),
world: resourceEntry.world,
args: new Map(),
hostnames: new Map(),
entities: new Map(),
@ -165,6 +167,7 @@ export async function commit(rulesetId, path, writeFn) {
);
content = safeReplace(content, /\$rulesetId\$/, rulesetId, 0);
content = safeReplace(content, /\$scriptletName\$/, details.name, 0);
content = safeReplace(content, '$world$', details.world);
content = safeReplace(content,
'self.$argsList$',
JSON.stringify(Array.from(details.args.keys()).map(a => JSON.parse(a)))

View File

@ -132,8 +132,10 @@ argsList.length = 0;
// 'MAIN' world not yet supported in Firefox, so we inject the code into
// 'MAIN' ourself when environment in Firefox.
const targetWorld = '$world$';
// Not Firefox
if ( typeof wrappedJSObject !== 'object' ) {
if ( typeof wrappedJSObject !== 'object' || targetWorld === 'ISOLATED' ) {
return uBOL_$scriptletName$();
}