I'm learning add-ons (browser extensions) development for Mozilla Firefox. I want to create an add-on that lets the user open a new Firefox window containing multiple tabs when he/she presses a keyboard key combination. I'm using windows.create()
, since it seems to be the perfect choice. Currently, my manifest.json
file is:
{
"manifest_version": 2,
...
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["test.js"]
}
]
}
and the test.js
file is:
(function () {
document.addEventListener("keydown", function (e) {
if (e.ctrlKey && e.shiftKey && e.code === "KeyU") {
alert("A");
function onCreated(windowInfo) {
alert(`Created window: ${windowInfo.id}`);
}
function onError(error) {
alert(`Error: ${error}`);
}
let creating = browser.windows.create({
url: ["https://translate.google.com/"]
});
creating.then(onCreated, onError);
alert("C");
}
});
})();
However, it doesn't work. alert("A");
shows a popup, while alert("C");
doesn't. The error is clearly in the middle, among those browser.windows.create
lines, but I'm not able to figure out what's wrong. I'm following the tutorial from Firefox docs.