Develop a Chrome
Extension in 2018
Oleksandr Golovatyi
Senior Front End Developer at AppsFlyer,
Co-Founder & Trainer at ”FullStack Academy Kiev”
Develop a Chrome Extension in 2018
•Why build Chrome extension?
•Structure and Architecture
•Test and deploy your Chrome extension
•Chrome extension boilerplate by React
•Examples of Chrome extensions
Chrome Extension?
Extensions - small software programs that
customize the browsing experience.
Examples of Chrome Extension
Examples of Chrome Extension
Examples of Chrome Extension
Why build a Chrome extension?
Source: http://gs.statcounter.com/browser-market-share
Why build a Chrome extension?
•Chrome – most popular browser
•Integration with Chrome
•Could Extend Chrome & any web site
•Standard Web Stack (JS, HTML, CSS)
Chrome Extension Structure
.crx zipped file
Chrome Web Store
Manifest File
{
"manifest_version": "2.1",
"name": "My Extension Name",
"version": ”0.0.1"
}
Manifest File (more …)
{
"description": "Gets information from Google.",
"icons": {
"128": "icon_128.png"
},
"background": {
"persistent": false,
"scripts": ["bg.js"]
},
"permissions": ["http://*.google.com/", "https://*.google.com/"],
"browser_action": {
"default_title": "",
"default_icon": "icon_19.png",
"default_popup": "popup.html"
}
}
Chrome Extension Architecture
•Manifest
•Background Script
•UI Elements
•Content Script
•Options Page
Background Script
The background script is the extension's event handler; it
contains listeners for browser events that are important to
the extension.
{
"name": ”My Extension Name",
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
UI Elements
•Popup
•Tooltip
•Context Menu
•Omnibox
UI Elements: Popup
HTML file that is displayed in a
special window when the user clicks
the toolbar icon.
UI Elements: Popup
{
"name": ”My Extension Name",
...
"browser_action": {
"default_popup":"popup.html"
}
...
}
UI Elements: Popup
UI Elements: Tooltip
Short descriptions or instructions to users when
hovering over the browser icon.
UI Elements: Context Menu
UI Elements: Context Menu
{
"name": ”My Extension Name",
...
"permissions": ["contextMenus", "storage"],
"icons": {
"16": "globalGoogle16.png",
"48": "globalGoogle48.png",
"128": "globalGoogle128.png"
}
...
}
UI Elements: Context Menu
var contexts = ["page", "selection", "link"];
for (var i = 0; i < contexts.length; i++) {
var context = contexts[i];
var title = "Test '" + context + "' menu item";
var id = chrome.contextMenus.create({
"title": title, "contexts": [context],
"onclick": genericOnClick
});
}
UI Elements: Omnibox
The omnibox API allows you to register a
keyword with Google Chrome's address bar
Content scripts
Content scripts read and modify the DOM of web
pages the browser visits.
Content scripts
Options Page
{
"name": "My Extension Name",
...
"options_page": "options.html",
...
}
Options Page
chrome://extensions, locating the desired extension,
clicking Details, then selection the options link
Chrome APIs
•Stable APIs
•Beta APIs
•Dev APIs
•Experimental APIs
Chrome APIs: Stable APIs
• Bookmarks
• Commands
• contextMenus
• Cookies
• desktopCapture
• Downloads
• Events
• History
• Identity (OAuth2)
• Tabs
• Sessions
• Storage
Test Chrome Extension
React Chrome Extension Repo
https://github.com/FullStack-Academy-Kiev/react-chrome-extension
Q & A
Thank you

Develop Chrome Extension