Skip to content

Commit

Permalink
[mv3] Inject scriptlets in their intended target world
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Feb 24, 2025
1 parent e56ca0f commit 8a6b12a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions platform/mv3/extension/js/scripting-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function registerScriptlet(context, scriptletDetails) {
const scriptletList = scriptletDetails.get(rulesetId);
if ( scriptletList === undefined ) { continue; }

for ( const [ token, scriptletHostnames ] of scriptletList ) {
for ( const [ token, details ] of scriptletList ) {
const id = `${rulesetId}.${token}`;
const registered = before.get(id);

Expand All @@ -439,17 +439,17 @@ function registerScriptlet(context, scriptletDetails) {
let targetHostnames = [];
if ( hasBroadHostPermission ) {
excludeMatches.push(...permissionRevokedMatches);
if ( scriptletHostnames.length > 100 ) {
if ( details.hostnames.length > 100 ) {
targetHostnames = [ '*' ];
} else {
targetHostnames = scriptletHostnames;
targetHostnames = details.hostnames;
}
} else if ( permissionGrantedHostnames.length !== 0 ) {
if ( scriptletHostnames.includes('*') ) {
if ( details.hostnames.includes('*') ) {
targetHostnames = permissionGrantedHostnames;
} else {
targetHostnames = ut.intersectHostnameIters(
scriptletHostnames,
details.hostnames,
permissionGrantedHostnames
);
}
Expand All @@ -467,7 +467,7 @@ function registerScriptlet(context, scriptletDetails) {
excludeMatches,
matchOriginAsFallback: true,
runAt: 'document_start',
world: 'MAIN',
world: details.world,
};

// register
Expand Down
8 changes: 6 additions & 2 deletions platform/mv3/make-scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ 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)))
Expand All @@ -181,7 +180,12 @@ export async function commit(rulesetId, path, writeFn) {
JSON.stringify(Array.from(details.exceptions))
);
writeFn(`${path}/${rulesetId}.${name}`, content);
scriptletStats.push([ name.slice(0, -3), Array.from(details.matches).sort() ]);
scriptletStats.push([
name.slice(0, -3), {
hostnames: Array.from(details.matches).sort(),
world: details.world,
}
]);
}
return scriptletStats;
}
Expand Down

0 comments on commit 8a6b12a

Please sign in to comment.