Chrome Extensions are a whole other world of opportunity to build web-enabled tools!
Extensions are small programs that can modify and enhance the functionality of the Chrome browser. You write them using web standard web technologies (HTML, JavaScript, and CSS).
Chrome Extensions (or "Apps") allow you to create in-browser tools which add functionality to the browsing experience. In our case we want to let the person
Browser Actions allow you to add an icon to the browser e.g: See: https://developer.chrome.com/extensions/browserAction
Example of a simple Browser Action is an icon which, when clicked alters the page background. See: examples/make_page_red
Uses the bookmarks API to show a list of the person's bookmarks
when they click on the icon (browser_action
)
See: examples/my_bookmarks
src
of Icon when clickedImagine your app wants to change the icon in response to an event or a notification: That's quite easy with the following line:
chrome.browserAction.setIcon({path:"icon-notification.png"});
see: examples/set_icon_path
Use the chrome.browsingData
API to remove browsing data from a user's local profile.
The API only allows you to erase
history, so its only useful for a limited
set of applications.
see: https://developer.chrome.com/extensions/browsingData
Using the commands.onCommand
we can issue keyboard commands to trigger events in our extension.
The commands are defined in the manifest.json
file as:
"commands": {
"toggle-feature": {
"suggested_key": { "default": "Ctrl+Shift+Y" },
"description": "Send a 'toggle-feature' event to the extension"
},
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+F",
"mac": "MacCtrl+Shift+F"
}
}
}
This can be useful for opening a background page (popup) to read content, e.g: imaging if your extension provided an instant messaging facility and you could see the latest messages from any page without needing to have the messenger open.
see: https://developer.chrome.com/extensions/commands
desktopCapture
allows you to capture the client's screen.
see: examples/desktop_capture and: https://developer.chrome.com/extensions/desktopCapture
The signedInDevices
API gives you a list of all the devices the
person has signed into using their Google account:
see: examples/my_devices API: https://developer.chrome.com/extensions/signedInDevices
So you want to show people notifications in Chrome...?
see: examples/notifications for "toast" notifier. API: https://developer.chrome.com/apps/notifications
'declarativeWebRequest' requires Google Chrome beta channel or newer
See:
Get the page visit history: https://developer.chrome.com/extensions/history#method-getVisits
Q: Can we have both page_action
and browser_action
?
A: No. But you can create multiple extensions and have them inter-communicate
see: http://stackoverflow.com/questions/14519458/google-chrome-extension-browser-page-action
and: https://developer.chrome.com/extensions/extension#event-onMessageExternal
Q: How can we check when the Tab/Page has finished loading?
A: Add an event listener:
chrome.tabs.onUpdated.addListener(function(tabId , info) {
if (info.status == "complete") {
// your code ...
}
});