build your own chrome extension with angularjs

21
build a chrome extension with angular.js JSRomandie, May 2014 @flrent

Upload: flrent

Post on 26-Jan-2015

128 views

Category:

Technology


6 download

DESCRIPTION

What are Chrome Extensions? What can you do? Explanation of Content scripts, Background pages and Popup Use Angular with CSP mode Build and distribute your app

TRANSCRIPT

Page 1: Build your own Chrome Extension with AngularJS

build a chrome extension with angular.js

JSRomandie, May 2014@flrent

Page 2: Build your own Chrome Extension with AngularJS

summary

1) what is a chrome extension ?

2) the chrome platform (manifest, APIs)

3) angular!4) distribution (internal/store)5) Get started and feedback

Page 3: Build your own Chrome Extension with AngularJS

what is a chrome extension ?

Page 4: Build your own Chrome Extension with AngularJS

what can you do with a chrome extension ?

get/modify tabs content (!)

browser popup

leverage web products build a dev tool

capture tab screen

use storage (local/sync)

send desktop notifications

take control of the browser(!)

context menus

Page 5: Build your own Chrome Extension with AngularJS

3 kinds

https://developer.chrome.com/extensions/overview

browser action - page action - popup

Page 6: Build your own Chrome Extension with AngularJS

chrome extension layers

http://www.penguinhustle.com/blog/how-to-write-your-first-chrome-extension/

Page 7: Build your own Chrome Extension with AngularJS

content scripts- run in tabs- DOM access- isolated scope - limited chrome.* APIs access- access to resources via

‘web_accessible_resources’ property

Page 8: Build your own Chrome Extension with AngularJS

background pages / events pages

- runs in background- html and js- full chrome.* APIs access

Page 9: Build your own Chrome Extension with AngularJS

popup scripts

- active only when popup is open

- html and js- chrome.* APIs access

Page 10: Build your own Chrome Extension with AngularJS

the chrome manifest

https://developer.chrome.com/extensions/manifest

app content

app meta

app permissions & resources

Page 11: Build your own Chrome Extension with AngularJS

the (BB) chrome manifest

https://developer.chrome.com/extensions/manifest

{ "name": "BugBuster CSS Selector", "version": "0.2.0", "manifest_version": 2, "description": "__MSG_appDescription__", "icons": { "16": "images/icon-16.png", "128": "images/icon-128.png" }, "default_locale": "en", "background": { "page": "messager.html" }, "browser_action": { "default_icon": { "19": "images/icon-19.png", "38": "images/icon-38.png" }, "default_title": "BugBuster - Web Application Testing Made Easy", "default_popup": "recorder.html" }, "externally_connectable": { "matches": [ "*://*.bugbuster.com/*", "*://bugbuster.dev/*" ] }, "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'", "web_accessible_resources": [ "http://fonts.googleapis.com/", "48.png", "https://*.google-analytics.com/**/*" ],

"permissions": [ "http://*/*", "https://*/*", "contextMenus", "storage", "notifications", "clipboardRead", "clipboardWrite", "tabs", "<all_urls>" ], "content_scripts": [ { "matches": [ "http://*/*", "https://*/*" ], "exclude_matches": [ "http://localhost/*", "http://bugbuster.dev/*", "https://app.bugbuster.com/*" ], "css": [ "selector.css" ], "js": [ "selector.js" ], "run_at": "document_end", "all_frames": false } ]}

Page 12: Build your own Chrome Extension with AngularJS

communication

http://www.penguinhustle.com/blog/how-to-write-your-first-chrome-extension/

Page 13: Build your own Chrome Extension with AngularJS

communication : one time requests- sending from content script

- sending from background scripts

- receiving from both

Page 14: Build your own Chrome Extension with AngularJS

communication : long-lived connections- opening a channel from content script

- receving on the background page

Page 15: Build your own Chrome Extension with AngularJS

communication : others

- cross-extension messaging

- web pages messaging

- native messaging

Page 16: Build your own Chrome Extension with AngularJS

permissions/APIs

• background• bookmarks• clipboardRead• clipboardWrite• contentSettings• contextMenus• cookies• history• idle

• management• notifications• pageCapture• tabs• topSites• webNavigation• webRequest• webRequestBlocking

chrome.permissions.request({permissions: ['tabs'], origins: ['http://www.google.com/’]}, function(granted) {}

);

Page 17: Build your own Chrome Extension with AngularJS

angular.js

state manager

Content-Security-Policy compliant framework - no inline JS- no inline event bindings- no eval

- restore state- services

https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Introducing_Content_Security_Policy

Page 18: Build your own Chrome Extension with AngularJS

distribution

manual distribution

Chrome Web Store- 5$ one time fee- stats- updates- soon to be required for Chrome Windows

- need active developer mode- CRX file- unpacked

http://blog.chromium.org/2013/11/protecting-windows-users-from-malicious.html

Page 19: Build your own Chrome Extension with AngularJS

getting started

scaffold project

- https://github.com/yeoman/generator-chrome-extension

- angular, bootstrap, jquery- background, popup, content

script- grunt build, bower- mocha, chai, sinon.js tests

Yeoman

- https://github.com/flrent/chrome-extension-angular-base

Page 20: Build your own Chrome Extension with AngularJS

personal feedback

- mindset change (scopes, APIs)

- (channel) messaging is hard

- updates/installations keep old context

- very powerful but be careful

Page 21: Build your own Chrome Extension with AngularJS

Thank you

Florent Lamoureuxworking at BugBuster

@flrent

https://github.com/flrent/chrome-extension-angular-base