Skip to content

Commit

Permalink
[mv3] Let the scriplet sort out targeted sites when too many targets
Browse files Browse the repository at this point in the history
This is too avoid `matches` property with too many hostnames at
registerContentScripts() time. Threshold has been arbitrarily
set at 100.
  • Loading branch information
gorhill committed Jun 5, 2023
1 parent d300f21 commit 7e71224
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions platform/mv3/extension/js/scripting-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,26 @@ function registerScriptlet(context, scriptletDetails) {

const matches = [];
const excludeMatches = [];
let targetHostnames = [];
if ( hasBroadHostPermission ) {
excludeMatches.push(...permissionRevokedMatches);
matches.push(...ut.matchesFromHostnames(scriptletHostnames));
if ( scriptletHostnames.length > 100 ) {
targetHostnames = [ '*' ];
} else {
targetHostnames = scriptletHostnames;
}
} else if ( permissionGrantedHostnames.length !== 0 ) {
matches.push(
...ut.matchesFromHostnames(
ut.intersectHostnameIters(
permissionGrantedHostnames,
scriptletHostnames
)
)
);
if ( scriptletHostnames.includes('*') ) {
targetHostnames = permissionGrantedHostnames;
} else {
targetHostnames = ut.intersectHostnameIters(
permissionGrantedHostnames,
scriptletHostnames
);
}
}
if ( matches.length === 0 ) { continue; }
if ( targetHostnames.length === 0 ) { continue; }
matches.push(...ut.matchesFromHostnames(targetHostnames));

before.delete(id); // Important!

Expand Down

0 comments on commit 7e71224

Please sign in to comment.