• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<p>
2An <code>Event</code> is an object
3that allows you to be notified
4when something interesting happens.
5Here's an example of using the
6<code>chrome.tabs.onCreated</code> event
7to be notified whenever there's a new tab:
8</p>
9
10<pre>
11chrome.tabs.onCreated.<b>addListener(function(</b>tab<b>) {</b>
12  appendToLog('tabs.onCreated --'
13              + ' window: ' + tab.windowId
14              + ' tab: '    + tab.id
15              + ' index: '  + tab.index
16              + ' url: '    + tab.url);
17<b>});</b>
18</pre>
19
20<p>
21As the example shows,
22you register for notification using <code>addListener()</code>.
23The argument to <code>addListener()</code>
24is always a function that you define to handle the event,
25but the parameters to the function depend on
26which event you're handling.
27Checking the documentation for
28<a href="tabs.html#event-onCreated"><code>chrome.tabs.onCreated</code></a>,
29you can see that the function has a single parameter:
30a <a href="tabs.html#type-Tab">Tab</a> object
31that has details about the newly created tab.
32</p>
33
34<h2>
35Methods
36</h2>
37
38<p>
39You can invoke the following methods on any <code>Event</code> object:
40</p>
41
42<pre>
43void addListener(function callback(...))
44void removeListener(function callback(...))
45bool hasListener(function callback(...))
46</pre>
47
48<!-- [PENDING: explain removeListener and hasListener] -->
49