I want to run the chrome extension script for a URL that matches a specific Regex pattern, for example /https:\/\/(?!en).*\.wikipedia\.org\/wiki/ which should match all wikipedia URLs that are not in English. However using the regex in my filter results in an error when loading the extension:
Service worker registration failed
Uncaught TypeError: Could not add listener
Here is the code I am using:
const filter = { url: [ { urlMatches: "https://(?!en).*\.wikipedia\.org/wiki" } ] } chrome.webNavigation.onBeforeNavigate.addListener((details) => { console.info("test"); }, filter); Manifest.json:
{ "name": "Test", "description": "", "version": "1.0", "manifest_version": 3, "background": { "service_worker": "script.js" }, "permissions": [ "webNavigation" ] } I think there is something wrong with my regex (I do not get any error when providing a full URL), but I am not sure what.
How do I get this to work?
"^https://(?!en).*\.wikipedia\.org/wiki.*$". The example at the doc has anchors: developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/…