Skip to content

Commit 6af4494

Browse files
committed
[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.
1 parent 607bba6 commit 6af4494

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

platform/mv3/make-scriptlets.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function init() {
5959
const entry = {
6060
name: fn.name,
6161
code: fn.toString(),
62+
world: scriptlet.world || 'MAIN',
6263
dependencies: scriptlet.dependencies,
6364
requiresTrust: scriptlet.requiresTrust === true,
6465
};
@@ -96,6 +97,7 @@ export function compile(details) {
9697
scriptletFiles.set(scriptletToken, {
9798
name: resourceEntry.name,
9899
code: createScriptletCoreCode(scriptletToken),
100+
world: resourceEntry.world,
99101
args: new Map(),
100102
hostnames: new Map(),
101103
entities: new Map(),
@@ -165,6 +167,7 @@ export async function commit(rulesetId, path, writeFn) {
165167
);
166168
content = safeReplace(content, /\$rulesetId\$/, rulesetId, 0);
167169
content = safeReplace(content, /\$scriptletName\$/, details.name, 0);
170+
content = safeReplace(content, '$world$', details.world);
168171
content = safeReplace(content,
169172
'self.$argsList$',
170173
JSON.stringify(Array.from(details.args.keys()).map(a => JSON.parse(a)))

platform/mv3/scriptlets/scriptlet.template.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ argsList.length = 0;
132132
// 'MAIN' world not yet supported in Firefox, so we inject the code into
133133
// 'MAIN' ourself when environment in Firefox.
134134

135+
const targetWorld = '$world$';
136+
135137
// Not Firefox
136-
if ( typeof wrappedJSObject !== 'object' ) {
138+
if ( typeof wrappedJSObject !== 'object' || targetWorld === 'ISOLATED' ) {
137139
return uBOL_$scriptletName$();
138140
}
139141

0 commit comments

Comments
 (0)