Intership at GDP Labs
Summer 2015
Extensions are small software programs that can modify and enhance the functionality of the Chrome browser. You write them using web technologies such as HTML, JavaScript, and CSS
Extensions bundle all their files into a single file that the user downloads and installs.
Omnibox => Tools => Extension Or https://chrome.google.com/webstore/developer/dashboard
Files
The manifest file, called manifest.json, gives information about the extension, such as the most important files and the capabilities that the extension might use
manifest_version : latest version : 2
version : increse the version every update the extension
default_locale : Specifies the subdirectory of _locales that contains the default strings for this extension
browser_action : Use browser actions to put icons in the main Google Chrome toolbar, to the right of the address bar. In addition to its icon, a browser action can also have a tooltip, a badge, and a popup.
background : A common need for extensions is to have a single long-running script to manage some task or state. Background pages to the rescue.
Content Script : Content scripts are JavaScript files that run in the context of web pages
Permissions : To use most chrome.* APIs, your extension or app must declare its intent in the "permissions" field of the manifest
web_accessible_resources : An array of strings specifying the paths of packaged resources that are expected to be usable in the context of a web page. These paths are relative to the package root, and may contain wildcards
Background : function getState(){ return something; }
Extension : var x = chrome.extension.getBackgroundPage().getState();
Extension : chrome.tabs.executeScript( null , {file : 'js/inject.js'});
Extension :
chrome.tabs.executeScript( null , {code : 'document.body.style.backgroundColor="red"' });
content script : $('<iframe id ="ombaqExtensionBody" class = "main_ombaq" style = "z-index:12121212" src="'+content+'"><p>Your browser does not support iframes.</p></iframe>').appendTo(document.body);
content : 'chrome-extension://'+getIdExtension()+'/html/main.html'
function getIdExtension(){
return chrome.runtime.id;
}
iframe : var port = chrome.extension.connect({name: "Sample Communication"}); port.postMessage("something"); port.onMessage.addListener(function(msg) {alert(msg) }); background: chrome.extension.onConnect.addListener(function(port) { port.onMessage.addListener(function(msg) { // doing something }); });
iframe : <html> <body> <button id="mybutton">click me</button> </body> </html> content script: var button = document.getElementById("mybutton"); button.addEventListener("click", function() { // do something }, false);