diff --git a/platform/mv3/extension/js/scripting-manager.js b/platform/mv3/extension/js/scripting-manager.js index 814343ebe..23a6444ea 100644 --- a/platform/mv3/extension/js/scripting-manager.js +++ b/platform/mv3/extension/js/scripting-manager.js @@ -450,8 +450,8 @@ function registerScriptlet(context, scriptletDetails) { targetHostnames = permissionGrantedHostnames; } else { targetHostnames = ut.intersectHostnameIters( - permissionGrantedHostnames, - scriptletHostnames + scriptletHostnames, + permissionGrantedHostnames ); } } diff --git a/platform/mv3/extension/js/utils.js b/platform/mv3/extension/js/utils.js index b32104f94..7bf6e1350 100644 --- a/platform/mv3/extension/js/utils.js +++ b/platform/mv3/extension/js/utils.js @@ -47,6 +47,13 @@ const isDescendantHostname = (hna, hnb) => { return hna.charCodeAt(hna.length - hnb.length - 1) === 0x2E /* '.' */; }; +/** + * Returns whether a hostname is part of a collection, or is descendant of an + * item in the collection. + * @param hna - the hostname representing the needle. + * @param iterb - an iterable representing the haystack of hostnames. + */ + const isDescendantHostnameOfIter = (hna, iterb) => { const setb = iterb instanceof Set ? iterb : new Set(iterb); if ( setb.has('all-urls') || setb.has('*') ) { return true; } @@ -60,6 +67,13 @@ const isDescendantHostnameOfIter = (hna, iterb) => { return false; }; +/** + * Returns all hostnames in the first collection which are equal or descendant + * of hostnames in the second collection. + * @param itera - an iterable which hostnames must be filtered out. + * @param iterb - an iterable which hostnames must be matched. + */ + const intersectHostnameIters = (itera, iterb) => { const setb = iterb instanceof Set ? iterb : new Set(iterb); if ( setb.has('all-urls') || setb.has('*') ) { return Array.from(itera); }