One option for running a content script is to match one or more URLs to run it automatically. From the web site:
"content_scripts": [
{
"matches": ["*://*.mozilla.org/*"],
"js": ["borderify.js"]
}
]
Is it possible to update this dynamically? That is, can I add or remove to the macthes
array using JavaScript?
My next step would be to save changes in storage, and reload that next time.
My plan is to allow my addon to automatically run for selected URLs, to allow users to edit these URLs.
Use "matches": ["*://*/*"],
to match any URL.
And check the document.URL
in the content script to see if it matches any among user-defined URLs retrieved by calling browser.storage.local.get
. If document.URL
doesn't match, do nothing.