w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
576 stars 50 forks source link

userScripts API: method to get matching ids for a URL #646

Open tophf opened 3 days ago

tophf commented 3 days ago

Something like chrome.userScripts.getMatchingIds({url: string, allFrames: boolean}) that returns a Promise resolved to an array of ids of the registered userscripts. When the allFrames parameter is omitted/null/undefined the allFrames flag in RegisteredUserScript is ignored.

Necessary to show the list of matching scripts in the popup and a number of running scripts in the icon badge (e.g. # of scripts, unique # of scripts, or # per main_frame/sub_frame).

The current workaround is to get this list from the running scripts in the tab, but it won't help in these cases:

Another workaround is to perform matching manually, but it's wasteful when there's a lot of scripts (some scripts may have hundreds of matching patterns) and it duplicates the existing matching mechanism in the browser.