I am building a browser extension. I want to trigger a notification when the user clicks on the extension's icon. When I try to load the extension in Chrome, I get this error: Service worker registration failed
As the source of the error, it highlights "background.js" in the manifest (which you find further down). No further information is given. However, the problem only occurs if I have the first snippet in background.ts, as indicated by the comments:
import { browser } from "webextension-polyfill-ts";
// This code prevents the compiled extension to be loaded into Chrome
browser.browserAction.onClicked.addListener(() => {
console.log('browserAction.onClicked');
});
// I also have this code in the file, which works just fine.
browser.runtime.onMessage.addListener(() => {
console.log('browser.runtime.onMessage');
});
(Note that this is of course compiled into Javascript)
Of course I suspected a permissions issue, but could not find anything suspicious. Here is the complete manifest:
{
"name": "Test",
"description": "Test",
"version": "0.0.1",
"manifest_version": 3,
"permissions": ["storage", "activeTab", "scripting"],
"background": {
"service_worker": "background.js"
},
"action": {
"default_title": "Click to show an alert"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"js/content-script.js"
]
}
],
"content_security_policy": {}
}
Any thoughts? Thanks!