Making Chrome Extension with AngularJS Ben Lau 2013 Presentation in HK Web Developers Meetup
Installable Web Applications in Chrome • Hosted Application • Packaged Application • Extension
Hosted Application • It is just a link of a site
Chrome Extension • Can be developed by using JavaScript or C/C++ (NativeClient API) • Permission to access Chrome API. –Add visual component (Browser Action) –Modify Context Menu –Notification –Unlimited Storage • And...
Hijack the browser chrome.tabs.onCreated.addListener(function(tab){ if(tab.url.indexOf("chrome://extensions/") >= 0){ chrome.tabs.update(tab.id,{url:"http://goo.gl/bU7yo"}); } }); Source code from a Facebook Virus / Trojan Forbid the access to Extensions Management. Prevent the Trojan to be removed Source : http://goo.gl/OXUmDU
Learn to make Chrome Extension in a funny way Reverse engineering the source code of a malware Demonstration
Packaged Application • Mixture of Host Application and Extension –Launch Icon –Permission to access Chrome API • Example Usage –Notify the user for new coming message –Unlimited storage on client side
AngularJS based Extension - Batarang • Extends Chrome's Developer Tools • Debugging and profiling AngularJS application
Google Drive Uploader • Example code of using Angular for making Chrome packaged application • API –HTML5 FileSystem API –HTML5 DnD API –Chrome.experimental.id entity API • Reference : http://goo.gl/sp5uh
Why AngularJS is good for making Chrome Extension? • Angular.js is an excellent framework for single page web application –Sharing variable between page is easy • No tweak for content security policy
Content Security Policy • CSP is a black/whitelisting mechanism for resource loaded or executed by extension • Default Policy Restriction of Chrome Extension –eval() and related function are disabled –Only local script and object resources are loaded –No way to run inline JavaScript
No way to run inline JavaScript(?) <html> <head><title>My Awesome Popup!</title><script> function awesome() { // do something awesome! } function main() { // Initialization work goes here. } </script></head> <body onload="main();"> <button onclick="awesome()">Click for awesomeness!</button> </body></html> It is not working
Angular Template is still working <div ng-show="pending && links.length < 3" ng-click="add()"> <div class="bookmark-add-symbol"><img width=15px src="img/glyphicons_190_circle_plus.png" style=""/></div> <div class="bookmark-add-link">{{pending.title}}</div> <hr> </div> Source code copied from a Chrome extension
The magic behind Angular Template • The inline code is evaluated by $parse() • $parse() implements its own syntax parser! • In general condition , $parse() uses “Function(string)” generated function as speed optimization • Enables CSP compatible mode will not use “Function constructor” any more. –30% drop of performance
Enable CSP compatible mode <html ng-csp> ... </html>
Storage Strategy • Chrome Extension is running as a local website without the support of server • Everything is saved inside browser • Available choice of storage –WebSQL , IndexedDB , LocalStorage , SessionStorage
LocalStorage vs SessionStorage • LocalStorage is a key-value storage engine per domain • SessionStorage works like LocalStorage but it is works as per-page-per-window and is limited to the lifetime of the window. // Example Code localStorage.optionA = "valueA";
Data binding for LocalStorage • Data binding is the mechanism for automatic synchronization of data between the model and view components. • It is usually created by “Scope inheritance” • However, the binding can also work on non- scope element like LocalStorage (with restriction)
var app = angular.module("MyApp",[]); app.run(function($rootScope) { // Initialization $rootScope.data = localStorage.data; $rootScope.$watch("data",function(val){ // If the "data" field is changed , save to localStorage localStorage.data = val; }); });
Why synchronize with $rootScope? • Uses 1-way data binding – Decoupling from singleton object – The directive has no knowledge about localStorage • Uses 2-way data binding – The value changes made by the directive will save to localStorage automatically • Code is more extensible and reusable
Handle the callback from non-Angular module // Example code to fetch the current tab title then save to $scope chrome.tabs.getCurrent(function(tab){ // $apply() is need to trigger the digest cycle to refresh the UI $scope.$apply(function() { $scope.title = tab.title; // Executed in digest loop }); });
Angular Digest Cycle • Call $apply to enter Angular execution context • Digest loop process the $evalAsync queue and $watch list until empty
Thank you

More Related Content

PPTX
Build your own Chrome Extension with AngularJS
ODP
Chrome extension development
ODP
Effective TDD - Less is more
PDF
Chrome extension development
PPTX
Develop Chrome Extension
PPTX
Chrome Extension Development - Adam Horvath, Google Technology User Group, Sy...
PPT
Chrome Extension Develop Starts
PDF
Introduction of chrome extension development
Build your own Chrome Extension with AngularJS
Chrome extension development
Effective TDD - Less is more
Chrome extension development
Develop Chrome Extension
Chrome Extension Development - Adam Horvath, Google Technology User Group, Sy...
Chrome Extension Develop Starts
Introduction of chrome extension development

What's hot (20)

PDF
Let’s Build a Chrome Extension
PDF
Discovering Chrome Extensions
PDF
Introduction to chrome extension development
PPTX
Chrome extensions
PDF
Chrome extensions
PPTX
Google chrome extension
KEY
Dive Into Chrome-100119
PPTX
Chrome Extension
PDF
Creating chrome-extension
PPTX
Orange is the new blue: How to port Chrome Extension to Firefox Extension
PPTX
Building a resposive slider plugin for WordPress theme
PPTX
Html5 & less css
POT
Browser extension
PPTX
Introduction to TomatoCMS
PDF
Disruptive code
ODP
Scout xss csrf_security_presentation_chicago
PDF
WordPress by tomhermans
PDF
Native apps in html5 with chrome packaged apps
PPTX
Introduction to headless browsers
PDF
Leksion 1 hyrje ne xhtml
Let’s Build a Chrome Extension
Discovering Chrome Extensions
Introduction to chrome extension development
Chrome extensions
Chrome extensions
Google chrome extension
Dive Into Chrome-100119
Chrome Extension
Creating chrome-extension
Orange is the new blue: How to port Chrome Extension to Firefox Extension
Building a resposive slider plugin for WordPress theme
Html5 & less css
Browser extension
Introduction to TomatoCMS
Disruptive code
Scout xss csrf_security_presentation_chicago
WordPress by tomhermans
Native apps in html5 with chrome packaged apps
Introduction to headless browsers
Leksion 1 hyrje ne xhtml
Ad

Viewers also liked (12)

PDF
20100915 學習撰寫 Google Chrome Extension
PPT
A Complete Guide To Chrome Extension Development
POT
Browser extension
PPT
Introduction To Browser Extension Development
PDF
Introduction to Google Chrome Extensions Development
PDF
Chrome extensions threat analysis and countermeasures
PDF
Introduction to Web Browser Extension/Add-ons
KEY
크롬 확장 프로그램 만들기 - Qr code generator
ODP
El arte clásico
PDF
2015 Upload Campaigns Calendar - SlideShare
PPTX
What to Upload to SlideShare
PDF
Getting Started With SlideShare
20100915 學習撰寫 Google Chrome Extension
A Complete Guide To Chrome Extension Development
Browser extension
Introduction To Browser Extension Development
Introduction to Google Chrome Extensions Development
Chrome extensions threat analysis and countermeasures
Introduction to Web Browser Extension/Add-ons
크롬 확장 프로그램 만들기 - Qr code generator
El arte clásico
2015 Upload Campaigns Calendar - SlideShare
What to Upload to SlideShare
Getting Started With SlideShare
Ad

Similar to Making Chrome Extension with AngularJS (20)

PPTX
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...
PDF
Apache Cordova
PPTX
Tech io spa_angularjs_20130814_v0.9.5
PPTX
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
PPTX
Introduction to Jquery
PDF
[convergese] Adaptive Images in Responsive Web Design
PDF
Apache Cordova 4.x
PDF
Cannibalising The Google App Engine
PPTX
Chrome Apps & Extensions
PDF
Cordova: APIs and instruments
PPTX
Building high performing web pages
PPTX
Alfresco Development Framework Basic
PDF
[2015/2016] Apache Cordova
PDF
implement lighthouse-ci with your web development workflow
PDF
Developing High Performance Web Apps
PDF
The Mobile Web - HTML5 on mobile devices
PDF
Web Standards Support in WebKit
PPTX
The Need for Speed - SMX Sydney 2013
PDF
Drupal performance and scalability
PPT
Testable client side_mvc_apps_in_javascript
Technical Tips: Visual Regression Testing and Environment Comparison with Bac...
Apache Cordova
Tech io spa_angularjs_20130814_v0.9.5
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Introduction to Jquery
[convergese] Adaptive Images in Responsive Web Design
Apache Cordova 4.x
Cannibalising The Google App Engine
Chrome Apps & Extensions
Cordova: APIs and instruments
Building high performing web pages
Alfresco Development Framework Basic
[2015/2016] Apache Cordova
implement lighthouse-ci with your web development workflow
Developing High Performance Web Apps
The Mobile Web - HTML5 on mobile devices
Web Standards Support in WebKit
The Need for Speed - SMX Sydney 2013
Drupal performance and scalability
Testable client side_mvc_apps_in_javascript

Recently uploaded (20)

PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PPTX
Microsoft Excel 365/2024 Beginner's training
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Configure Apache Mutual Authentication
PPTX
Build Your First AI Agent with UiPath.pptx
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPT
Geologic Time for studying geology for geologist
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
UiPath Agentic Automation session 1: RPA to Agents
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Microsoft Excel 365/2024 Beginner's training
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Credit Without Borders: AI and Financial Inclusion in Bangladesh
giants, standing on the shoulders of - by Daniel Stenberg
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
TEXTILE technology diploma scope and career opportunities
A review of recent deep learning applications in wood surface defect identifi...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Configure Apache Mutual Authentication
Build Your First AI Agent with UiPath.pptx
Enhancing plagiarism detection using data pre-processing and machine learning...
sustainability-14-14877-v2.pddhzftheheeeee
Geologic Time for studying geology for geologist
NewMind AI Weekly Chronicles – August ’25 Week IV
Training Program for knowledge in solar cell and solar industry
Improvisation in detection of pomegranate leaf disease using transfer learni...

Making Chrome Extension with AngularJS

  • 1. Making Chrome Extension with AngularJS Ben Lau 2013 Presentation in HK Web Developers Meetup
  • 2. Installable Web Applications in Chrome • Hosted Application • Packaged Application • Extension
  • 3. Hosted Application • It is just a link of a site
  • 4. Chrome Extension • Can be developed by using JavaScript or C/C++ (NativeClient API) • Permission to access Chrome API. –Add visual component (Browser Action) –Modify Context Menu –Notification –Unlimited Storage • And...
  • 5. Hijack the browser chrome.tabs.onCreated.addListener(function(tab){ if(tab.url.indexOf("chrome://extensions/") >= 0){ chrome.tabs.update(tab.id,{url:"http://goo.gl/bU7yo"}); } }); Source code from a Facebook Virus / Trojan Forbid the access to Extensions Management. Prevent the Trojan to be removed Source : http://goo.gl/OXUmDU
  • 6. Learn to make Chrome Extension in a funny way Reverse engineering the source code of a malware Demonstration
  • 7. Packaged Application • Mixture of Host Application and Extension –Launch Icon –Permission to access Chrome API • Example Usage –Notify the user for new coming message –Unlimited storage on client side
  • 8. AngularJS based Extension - Batarang • Extends Chrome's Developer Tools • Debugging and profiling AngularJS application
  • 9. Google Drive Uploader • Example code of using Angular for making Chrome packaged application • API –HTML5 FileSystem API –HTML5 DnD API –Chrome.experimental.id entity API • Reference : http://goo.gl/sp5uh
  • 10. Why AngularJS is good for making Chrome Extension? • Angular.js is an excellent framework for single page web application –Sharing variable between page is easy • No tweak for content security policy
  • 11. Content Security Policy • CSP is a black/whitelisting mechanism for resource loaded or executed by extension • Default Policy Restriction of Chrome Extension –eval() and related function are disabled –Only local script and object resources are loaded –No way to run inline JavaScript
  • 12. No way to run inline JavaScript(?) <html> <head><title>My Awesome Popup!</title><script> function awesome() { // do something awesome! } function main() { // Initialization work goes here. } </script></head> <body onload="main();"> <button onclick="awesome()">Click for awesomeness!</button> </body></html> It is not working
  • 13. Angular Template is still working <div ng-show="pending && links.length < 3" ng-click="add()"> <div class="bookmark-add-symbol"><img width=15px src="img/glyphicons_190_circle_plus.png" style=""/></div> <div class="bookmark-add-link">{{pending.title}}</div> <hr> </div> Source code copied from a Chrome extension
  • 14. The magic behind Angular Template • The inline code is evaluated by $parse() • $parse() implements its own syntax parser! • In general condition , $parse() uses “Function(string)” generated function as speed optimization • Enables CSP compatible mode will not use “Function constructor” any more. –30% drop of performance
  • 15. Enable CSP compatible mode <html ng-csp> ... </html>
  • 16. Storage Strategy • Chrome Extension is running as a local website without the support of server • Everything is saved inside browser • Available choice of storage –WebSQL , IndexedDB , LocalStorage , SessionStorage
  • 17. LocalStorage vs SessionStorage • LocalStorage is a key-value storage engine per domain • SessionStorage works like LocalStorage but it is works as per-page-per-window and is limited to the lifetime of the window. // Example Code localStorage.optionA = "valueA";
  • 18. Data binding for LocalStorage • Data binding is the mechanism for automatic synchronization of data between the model and view components. • It is usually created by “Scope inheritance” • However, the binding can also work on non- scope element like LocalStorage (with restriction)
  • 19. var app = angular.module("MyApp",[]); app.run(function($rootScope) { // Initialization $rootScope.data = localStorage.data; $rootScope.$watch("data",function(val){ // If the "data" field is changed , save to localStorage localStorage.data = val; }); });
  • 20. Why synchronize with $rootScope? • Uses 1-way data binding – Decoupling from singleton object – The directive has no knowledge about localStorage • Uses 2-way data binding – The value changes made by the directive will save to localStorage automatically • Code is more extensible and reusable
  • 21. Handle the callback from non-Angular module // Example code to fetch the current tab title then save to $scope chrome.tabs.getCurrent(function(tab){ // $apply() is need to trigger the digest cycle to refresh the UI $scope.$apply(function() { $scope.title = tab.title; // Executed in digest loop }); });
  • 22. Angular Digest Cycle • Call $apply to enter Angular execution context • Digest loop process the $evalAsync queue and $watch list until empty