I want to create a Firefox add-on but it doesn't work out at all. I tried to find the solution but I found nothing useful yet. Firefox version is 94.0 (64-bit).
The structure of the add-on:
manifest.json
{
"manifest_version": 2,
"name": "Popup",
"version": "1.0",
"content_scripts": [{
"js": ["background.js"],
"matches": [ "*://example/aaa/*", "*://examp.aaa.bb.cc/*"],
"all_frames": true }],
"permissions": ["tabs", "http://*/*", "https://*/*"],
"icons": {
"16": "icons/l16.png",
"32": "icons/l32.png",
"48": "icons/l48.png",
"128": "icons/l128.png"}
}
background.js
//background.js
const apps = [
['AAA', 'https://example/aaa/'],
['BBB', 'http://examp.aaa.bb.cc/']
]
browser.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
browser.tabs.query({ 'active': true, 'lastFocusedWindow': true, 'currentWindow': true },
(tabs) => {
let url = tabs[0].url;
const i = apps.findIndex(u => url.includes(u[1]));
if (i > -1 && !sessionStorage.getItem(url)) {
sessionStorage.setItem(url, url);
browser.tabs.update( tabs[0].id, { url: `http://popup.aaa.bb.cc?title=${apps[i][0]}`} );
}
});
})
I create a zip from this folder and the two files and then I upload it as temporary extension, because when I try to upload it as a normal add-on Firefox says it is corrupted. So the uploaded add-n in temporary extension container gives back "Error: Can't find profile directory.". Chrome much more simpler.
Your background scripts need to be separated from your content scripts in the manifest.
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [{
"matches": ["*://example/aaa/*", "*://examp.aaa.bb.cc/*"],
"js": [
"content.js"
]
}],