Cross Browser Extensions
Geekcamp Singapore 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
A cross-browser system for developing browser add-ons
@imJenal
@imJenal
@imJenal
{
"manifest_version": 2,
"name": "PrivateX",
"version": "0.0.1",
"description": "Summary of PrivateX.",
"homepage_url": "https://github.com/jyotsna17gupta/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/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
Exchange messages with their background scripts and can in this way indirectly access all the WebExtension APIs
"content_scripts": [
{
"matches": ["*://*.mozilla.org/*"],
"js": ["jquery.js", "content-script.js"]
}
]
@imJenal
"browser_action": {
"default_icon": {
"19": "button/geo-19.png",
"38": "button/geo-38.png"
},
"default_title": "Whereami?",
"default_popup": "popup/choose_beast.html"
}
@imJenal
"page_action": {
"default_icon": {
"16": "icons/icon-16.png",
"48": "icons/icon-48.png"
},
"default_title": "Title",
"default_popup": "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": "PrivateX",
"message": "This website is tracking you!",
});
@imJenal
const delayInMinutes = 5;
const periodInMinutes = 2;
browser.alarms.create("my-periodic-alarm", {
delayInMinutes,
periodInMinutes
});
@imJenal
function onCreated(tab) {
console.log(`Created new tab: ${tab.id}`)
}
function onError(error) {
console.log(`Error: ${error}`);
}
browser.browserAction.onClicked.addListener(function() {
var creating = browser.tabs.create({
url:"https://example.org"
});
creating.then(onCreated, onError);
});
function handleCreated(tab) {
console.log(tab.id);
}
browser.tabs.onCreated.addListener(handleCreated);
@imJenal
function onCreated(windowInfo) {
console.log(`Created window: ${windowInfo.id}`);
}
function onError(error) {
console.log(`Error: ${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
var target = "https://developer.mozilla.org/*";
function logResponse(responseDetails) {
console.log(responseDetails.url);
console.log(responseDetails.statusCode);
}
browser.webRequest.onCompleted.addListener(
logResponse,
{urls: [target]}
);
@imJenal
@imJenal
@imJenal
@imJenal
A command line tool to help build, run, and test WebExtensions.
@imJenal
npm install --global web-ext
@imJenal
@imJenal
IRC Channels: #webextensions, #extdev, #addons
Mailing List: https://mail.mozilla.org/listinfo/dev-addons
Telegram: @addonschat
@imJenal
@ imJenal