Skip to content

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

@tophf

Description

@tophf

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:

  • reloading the tab without userscripts intentionally (a feature in the extension), but still be able to see the list of matching scripts
  • syntax error in one of the userscripts (we don't want to use eval to overcome this problem)
  • extension was just installed in Chrome but the tab wasn't yet injected - we want to show the matching scripts with a hint to reload the tab or to run them now (when chrome.userScripts.execute is implemented)
  • URL host permission is not yet granted, i.e. the extension can't show the list without asking the permission
  • userscript that runs only on demand (when chrome.userScripts.execute is implemented) and we don't want to register it to avoid unnecessarily injecting a possibly huge amount of code
  • userscript was created and registered after the tab was loaded - we want to show it in the list with a hint that it'll run after reloading the tab or with a button to run it immediately (when chrome.userScripts.execute is implemented)
  • filtering in the script management UI of the extension (dashboard) i.e. to show only scripts that match an arbitrary URL.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions