Cross Browser Extensions
Code Camp NYC 2019
@imJenal
@imJenal
Browser Add-ons extend and modify the functionality of the browser.
@imJenal
Text
@imJenal
Source: theedublogger.com
@imJenal
@imJenal
@imJenal
Source: https://www.ghostery.com/
@imJenal
@imJenal
@imJenal
@imJenal
Source: https://addons.mozilla.org/
@imJenal
@imJenal
@imJenal
@imJenal
{
"manifest_version": 2,
"name": "PrivateX",
"version": "0.0.1",
"description": "Summary of PrivateX.",
"icons": {
"32": "icons/icon-32.png",
"48": "icons/icon-48.png",
},
"permissions": [
"tabs"
],
"page_action": {
"browser_style": true,
"default_icon": {
"48": "icons/icon-48.png"
},
"default_title": "Click here for Private browsing!"
},
"background": {
"scripts": ["background.js"]
}
}
@imJenal
Executes as soon as the extension is loaded
Stay loaded until the extension is disabled or uninstalled
Use any of the WebExtension APIs in the script
"background": {
"scripts": ["background-script.js"]
}
@imJenal
Similar to loading normal scripts in the page
Can access DOM structure and use a small subset of the Web Extension APIs
Exchange messages with their background scripts and can in this way indirectly access all the Web Extension APIs
"content_scripts": [
{
"matches": ["*://*.mozilla.org/*"],
"js": ["jquery.js", "content-script.js"]
}
]
@imJenal
"browser_action": {
"default_icon": {
"19": "icon-19.png",
"48": "icon-48.png"
},
"default_title": "Title",
"default_popup": "popup.html"
}
@imJenal
"page_action": {
"default_icon": {
"16": "icon-16.png",
"48": "icon-48.png"
},
"default_title": "Title",
"default_popup": "popup.html"
}
]]
@imJenal
"options_ui": {
"page": "options.html",
"browser_style": true
},
@imJenal
@imJenal
@imJenal
@imJenal
browser.notifications.create(alertUser, {
"type": "basic",
"iconUrl": icon.png",
"title": "Word Count",
"message": "Words",
});
@imJenal
const delayInMinutes = 5;
const periodInMinutes = 2;
browser.alarms.create("my-periodic-alarm", {
delayInMinutes,
periodInMinutes
});
@imJenal
function onCreated(tab) {...}
function onError(error) {...}
function handleCreated(tab) {...}
browser.browserAction.onClicked.addListener((tab) => {
var creating = browser.tabs.create({
url:"https://example.org"
});
creating.then(onCreated, onError);
});
browser.tabs.onCreated.addListener(handleCreated);
@imJenal
function onCreated(windowInfo) {...}
function onError(error) {...}
browser.browserAction.onClicked.addListener((tab) => {
var creating = browser.windows.create({
url: ["https://developer.mozilla.org",
"https://addons.mozilla.org"]
});
creating.then(onCreated, onError);
});
@imJenal
@imJenal
chrome.browserAction.setIcon();
browser.browserAction.setIcon();
@imJenal
@imJenal
@imJenal
A command line tool to help build, run, and test WebExtensions.
@imJenal
npm install --global web-ext
@imJenal
@imJenal
@imJenal
@imJenal
IRC Channels: #webextensions, #extdev, #addons
Mailing List: https://mail.mozilla.org/listinfo/dev-addons
Telegram: @addonschat
https://slides.com/jenal/codecampyc2019