From 7e712246a99a662225b881befc9c44605c09b192 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 5 Jun 2023 12:14:37 -0400 Subject: [PATCH] [mv3] Let the scriplet sort out targeted sites when too many targets This is too avoid `matches` property with too many hostnames at registerContentScripts() time. Threshold has been arbitrarily set at 100. --- .../mv3/extension/js/scripting-manager.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/platform/mv3/extension/js/scripting-manager.js b/platform/mv3/extension/js/scripting-manager.js index 0897e7d9a..2447acafa 100644 --- a/platform/mv3/extension/js/scripting-manager.js +++ b/platform/mv3/extension/js/scripting-manager.js @@ -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!