Chrome, HTML5, JavaScript, webdev

Chrome Extensions – The New Event Pages

Since the first days of Chrome extensions it was clear that they are very powerful way to extend your browser and make it do stuff you care about. However, while it was good, we knew that it can get better… and this is why we have in dev channel the ‘Event Pages’. Let’s start by defining what are those pages:

  • Background pages – give your extensions the ability to have a single long-running script to manage some task(s) in the background. This can be a certain state of your app or long pulling of information that you wish to show the user (e.g. amount of unread emails).
  • Event pages – are very similar to background pages, with one important difference: event pages are loaded only when they are needed. When the event page is not actively doing something, it is unloaded, freeing memory and other system resources. Please remember this feature is currently only in dev mode.

It seems that with Event Pages our Chrome will be able to  reduce the memory foot print that is used by some idle extensions. It’s an important evolution from the state of background pages that run all the time. An event page only runs when it is handling events. Once an event page becomes idle, it is unloaded, freeing memory until the next time it’s needed. To help event pages support some important use cases, we’re also have new APIs.

  • The alarms API allows an extension to wake itself up at set times, to support features like: cron jobs type of activity, periodically syncing, anything you wish to do over time in specific timing.
  • chrome.runtime new events let extensions know when they have been installed, or when their event page is being unloaded. It is also giving the developer an option to have a ‘last error’ handler.
  • chrome.declarativeWebRequest – A declarative version of the webRequest API lets extensions do network interception without the need for a background page at all. It also works much faster than the chrome.webRequest API because you can register rules that are evaluated in the browser rather than the JavaScript engine which reduces roundtrip latencies and allows for very high efficiency.

Final Notes

  • Learn more from the event page documentation.
  • There is a good source for more information on Chrome Extensions in Chromium blog
  • There are so many option to use the new event pages with the bluetooth API
  • Btw, @rem did it again with a new (amazing) version of JSbin – Go check it out and see how great logos ‘steal’ the show… Why I’ve added it here? because it’s a powerful online tool that let you test your app/extension and share your code before you upload it to Chrome web store. I’ve used both jsbin and jsfiddle in order to get feedback on some short code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s