{
"manifest_version": 2,
"name": "Hello World",
"version": "1.0.0",
"description": "Not sure yet, but will be useful.",
"icons": {
"48": "icons/icon-48.png"
},
"content_scripts": [
{
"matches": ["*://*.example.com/*"],
"js": ["content.js"]
}
],
"applications": {
"gecko": {
"id": "borderify@example.com",
"strict_min_version": "48.0"
}
},
"options_ui": {
"page": "settings.html"
},
"permissions": [
"cookies",
"activeTab"
]
}
CC-BY-NC-SA: ShockWatchWiki
Except for alert()
browser.api.onEvent.addListener((...eventDetails) => {
// handle event
}, {
// filter options
url: [ "https://example.com" ]
});
// Send a message and listen for a reply
browser.runtime.sendMessage("WebExtensions are ok.", (response) => {
console.log(response);
});
// Somewhere else:
const listener = (message, sender, reply) => {
if(message == "WebExtensions are ok.") {
reply("WebExtensions rock!");
}
};
browser.runtime.onMessage.addListener(listener);
console.log(browser.runtime.onMessage.hasListener(listener));
// Console
true
"WebExtensions rock!"
const callback = (result) => {
if (browser.extension.lastError) {
console.error(browser.extension.lastError);
} else {
console.log(result);
}
};
browser.cookies.set({
url: "https://developer.mozilla.org/"
}, logCookie);
// or thanks to promises
browser.cookies.set({
url: "https://developer.mozilla.org/"
}).then((result) => {
console.log(result);
}, (error) => {
console.error(error);
});
CC-BY-NC-SA: JMortonPhoto.com & OtoGodfrey.com
logins
proxy
Extension
WebExtension
Old Extension
Firefox
Opera
Edge