Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the BSD License.
©2011 Google
An Event
is an object
that allows you to be notified
when something interesting happens.
Here's an example of using the
chrome.tabs.onCreated
event
to be notified whenever there's a new tab:
chrome.tabs.onCreated.addListener(function(tab) { appendToLog('tabs.onCreated --' + ' window: ' + tab.windowId + ' tab: ' + tab.id + ' index: ' + tab.index + ' url: ' + tab.url); });
As the example shows,
you register for notification using addListener()
.
The argument to addListener()
is always a function that you define to handle the event,
but the parameters to the function depend on
which event you're handling.
Checking the documentation for
chrome.tabs.onCreated
,
you can see that the function has a single parameter:
a Tab object
that has details about the newly created tab.
You can invoke the following methods on any Event
object:
void addListener(function callback(...)) void removeListener(function callback(...)) bool hasListener(function callback(...))