events.html revision 513209b27ff55e2841eac0e4120199c23acce758
1<!DOCTYPE html><!-- This page is a placeholder for generated extensions api doc. Note:
2    1) The <head> information in this page is significant, should be uniform
3       across api docs and should be edited only with knowledge of the
4       templating mechanism.
5    3) All <body>.innerHTML is genereated as an rendering step. If viewed in a
6       browser, it will be re-generated from the template, json schema and
7       authored overview content.
8    4) The <body>.innerHTML is also generated by an offline step so that this
9       page may easily be indexed by search engines.
10--><html xmlns="http://www.w3.org/1999/xhtml"><head>
11    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
12    <link href="css/ApiRefStyles.css" rel="stylesheet" type="text/css">
13    <link href="css/print.css" rel="stylesheet" type="text/css" media="print">
14    <script type="text/javascript" src="/third_party/jstemplate/jstemplate_compiled.js">
15    </script>
16    <script type="text/javascript" src="js/api_page_generator.js"></script>
17    <script type="text/javascript" src="js/bootstrap.js"></script>
18    <script type="text/javascript" src="js/sidebar.js"></script>
19  <title>Events - Google Chrome Extensions - Google Code</title></head>
20  <body>  <div id="gc-container" class="labs">
21      <div id="devModeWarning">
22        You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files.
23      </div>
24      <!-- SUBTEMPLATES: DO NOT MOVE FROM THIS LOCATION -->
25      <!-- In particular, sub-templates that recurse, must be used by allowing
26           jstemplate to make a copy of the template in this section which
27           are not operated on by way of the jsskip="true" -->
28      <div style="display:none">
29
30        <!-- VALUE -->
31        <div id="valueTemplate">
32          <dt>
33            <var>paramName</var>
34              <em>
35
36                <!-- TYPE -->
37                <div style="display:inline">
38                  (
39                    <span class="optional">optional</span>
40                    <span class="enum">enumerated</span>
41                    <span id="typeTemplate">
42                      <span>
43                        <a> Type</a>
44                      </span>
45                      <span>
46                        <span>
47                          array of <span><span></span></span>
48                        </span>
49                        <span>paramType</span>
50                        <span></span>
51                      </span>
52                    </span>
53                  )
54                </div>
55
56              </em>
57          </dt>
58          <dd class="todo">
59            Undocumented.
60          </dd>
61          <dd>
62            Description of this parameter from the json schema.
63          </dd>
64          <dd>
65            This parameter was added in version
66            <b><span></span></b>.
67            You must omit this parameter in earlier versions,
68            and you may omit it in any version.  If you require this
69            parameter, the manifest key
70            <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
71            can ensure that your extension won't be run in an earlier browser version.
72          </dd>
73
74          <!-- OBJECT PROPERTIES -->
75          <dd>
76            <dl>
77              <div>
78                <div>
79                </div>
80              </div>
81            </dl>
82          </dd>
83
84          <!-- FUNCTION PARAMETERS -->
85          <dd>
86            <div></div>
87          </dd>
88
89        </div> <!-- /VALUE -->
90
91        <div id="functionParametersTemplate">
92          <h5>Parameters</h5>
93          <dl>
94            <div>
95              <div>
96              </div>
97            </div>
98          </dl>
99        </div>
100      </div> <!-- /SUBTEMPLATES -->
101
102  <a id="top"></a>
103    <div id="skipto">
104      <a href="#gc-pagecontent">Skip to page content</a>
105      <a href="#gc-toc">Skip to main navigation</a>
106    </div>
107    <!-- API HEADER -->
108    <table id="header" width="100%" cellspacing="0" border="0">
109      <tbody><tr>
110        <td valign="middle"><a href="http://code.google.com/"><img src="images/code_labs_logo.gif" height="43" width="161" alt="Google Code Labs" style="border:0; margin:0;"></a></td>
111        <td valign="middle" width="100%" style="padding-left:0.6em;">
112          <form action="http://www.google.com/cse" id="cse" style="margin-top:0.5em">
113            <div id="gsc-search-box">
114              <input type="hidden" name="cx" value="002967670403910741006:61_cvzfqtno">
115              <input type="hidden" name="ie" value="UTF-8">
116              <input type="text" name="q" value="" size="55">
117              <input class="gsc-search-button" type="submit" name="sa" value="Search">
118              <br>
119              <span class="greytext">e.g. "page action" or "tabs"</span>
120            </div>
121          </form>
122
123          <script type="text/javascript" src="http://www.google.com/jsapi"></script>
124          <script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script>
125          <script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse&t13n_langs=en"></script>
126          <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse&lang=en"></script>
127        </td>
128      </tr>
129    </tbody></table>
130
131    <div id="codesiteContent" class="">
132
133      <a id="gc-topnav-anchor"></a>
134      <div id="gc-topnav">
135        <h1>Google Chrome Extensions (<a href="http://code.google.com/labs/">Labs</a>)</h1>
136        <ul id="home" class="gc-topnav-tabs">
137          <li id="home_link">
138            <a href="index.html" title="Google Chrome Extensions home page">Home</a>
139          </li>
140          <li id="docs_link">
141            <a href="docs.html" title="Official Google Chrome Extensions documentation">Docs</a>
142          </li>
143          <li id="faq_link">
144            <a href="faq.html" title="Answers to frequently asked questions about Google Chrome Extensions">FAQ</a>
145          </li>
146          <li id="samples_link">
147            <a href="samples.html" title="Sample extensions (with source code)">Samples</a>
148          </li>
149          <li id="group_link">
150            <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions" title="Google Chrome Extensions developer forum">Group</a>
151          </li>
152        </ul>
153      </div> <!-- end gc-topnav -->
154
155    <div class="g-section g-tpl-170">
156      <!-- SIDENAV -->
157      <div class="g-unit g-first" id="gc-toc">
158        <ul>
159          <li><a href="getstarted.html">Getting Started</a></li>
160          <li><a href="overview.html">Overview</a></li>
161          <li><a href="whats_new.html">What's New?</a></li>
162          <li><h2><a href="devguide.html">Developer's Guide</a></h2>
163            <ul>
164              <li>Browser UI
165                <ul>
166                  <li><a href="browserAction.html">Browser Actions</a></li>
167                  <li><a href="contextMenus.html">Context Menus</a></li>
168                  <li><a href="notifications.html">Desktop Notifications</a></li>
169                  <li><a href="options.html">Options Pages</a></li>
170                  <li><a href="override.html">Override Pages</a></li>
171                  <li><a href="pageAction.html">Page Actions</a></li>
172                  <li><a href="themes.html">Themes</a></li>
173                </ul>
174              </li>
175              <li>Browser Interaction
176                <ul>
177                  <li><a href="bookmarks.html">Bookmarks</a></li>
178                  <li><a href="cookies.html">Cookies</a></li>
179                  <li class="leftNavSelected">Events</li>
180                  <li><a href="history.html">History</a></li>
181                  <li><a href="management.html">Management</a></li>
182                  <li><a href="tabs.html">Tabs</a></li>
183                  <li><a href="windows.html">Windows</a></li>
184                </ul>
185              </li>
186              <li>Implementation
187                <ul>
188                  <li><a href="a11y.html">Accessibility</a></li>
189                  <li><a href="background_pages.html">Background Pages</a></li>
190                  <li><a href="content_scripts.html">Content Scripts</a></li>
191                  <li><a href="xhr.html">Cross-Origin XHR</a></li>
192                  <li><a href="idle.html">Idle</a></li>
193                  <li><a href="i18n.html">Internationalization</a></li>
194                  <li><a href="messaging.html">Message Passing</a></li>
195                  <li><a href="npapi.html">NPAPI Plugins</a></li>
196                </ul>
197              </li>
198              <li>Finishing
199                <ul>
200                  <li><a href="hosting.html">Hosting</a></li>
201                  <li><a href="external_extensions.html">Other Deployment Options</a></li>
202                </ul>
203              </li>
204            </ul>
205          </li>
206          <li><h2><a href="tutorials.html">Tutorials</a></h2>
207            <ul>
208              <li><a href="tut_debugging.html">Debugging</a></li>
209              <li><a href="tut_analytics.html">Google Analytics</a></li>
210              <li><a href="tut_oauth.html">OAuth</a></li>
211            </ul>
212          </li>
213          <li><h2>Reference</h2>
214            <ul>
215              <li>Formats
216                <ul>
217                  <li><a href="manifest.html">Manifest Files</a></li>
218                  <li><a href="match_patterns.html">Match Patterns</a></li>
219                  <!-- <li>Packages (.crx)</li> -->
220                </ul>
221              </li>
222              <li><a href="api_index.html">chrome.* APIs</a></li>
223              <li><a href="api_other.html">Other APIs</a></li>
224            </ul>
225          </li>
226         <li><h2><a href="samples.html">Samples</a></h2></li>
227        </ul>
228      </div>
229      <script>
230        initToggles();
231      </script>
232
233    <div class="g-unit" id="gc-pagecontent">
234      <div id="pageTitle">
235        <h1 class="page_title">Events</h1>
236      </div>
237        <!-- TABLE OF CONTENTS -->
238        <div id="toc" style="display: none; ">
239          <h2>Contents</h2>
240          <ol>
241            <li>
242              <a>h2Name</a>
243              <ol>
244                <li>
245                  <a>h3Name</a>
246                </li>
247              </ol>
248            </li>
249              <li>
250                <a href="#apiReference">API reference</a>
251                <ol>
252                  <li>
253                    <a href="#properties">Properties</a>
254                    <ol>
255                      <li>
256                        <a href="#property-anchor">propertyName</a>
257                      </li>
258                    </ol>
259                  </li>
260                  <li>
261                    <a href="#methods">Methods</a>
262                    <ol>
263                      <li>
264                        <a href="#method-anchor">methodName</a>
265                      </li>
266                    </ol>
267                  </li>
268                  <li>
269                    <a href="#events">Events</a>
270                    <ol>
271                      <li>
272                        <a href="#event-anchor">eventName</a>
273                      </li>
274                    </ol>
275                  </li>
276                  <li>
277                    <a href="#types">Types</a>
278                    <ol>
279                      <li>
280                        <a href="#id-anchor">id</a>
281                      </li>
282                    </ol>
283                  </li>
284                </ol>
285              </li>
286          </ol>
287        </div>
288        <!-- /TABLE OF CONTENTS -->
289
290        <!-- Standard content lead-in for experimental API pages -->
291        <p id="classSummary" style="display: none; ">
292          For information on how to use experimental APIs, see the <a href="experimental.html">chrome.experimental.* APIs</a> page.
293        </p>
294
295        <!-- STATIC CONTENT PLACEHOLDER -->
296        <div id="static"><p>
297An <code>Event</code> is an object
298that allows you to be notified
299when something interesting happens.
300Here's an example of using the
301<code>chrome.tabs.onCreated</code> event
302to be notified whenever there's a new tab:
303</p>
304
305<pre>chrome.tabs.onCreated.<b>addListener(function(</b>tab<b>) {</b>
306  appendToLog('tabs.onCreated --'
307              + ' window: ' + tab.windowId
308              + ' tab: '    + tab.id
309              + ' index: '  + tab.index
310              + ' url: '    + tab.url);
311<b>});</b>
312</pre>
313
314<p>
315As the example shows,
316you register for notification using <code>addListener()</code>.
317The argument to <code>addListener()</code>
318is always a function that you define to handle the event,
319but the parameters to the function depend on
320which event you're handling.
321Checking the documentation for
322<a href="tabs.html#event-onCreated"><code>chrome.tabs.onCreated</code></a>,
323you can see that the function has a single parameter:
324a <a href="tabs.html#type-Tab">Tab</a> object
325that has details about the newly created tab.
326</p>
327
328<h2>
329Methods
330</h2>
331
332<p>
333You can invoke the following methods on any <code>Event</code> object:
334</p>
335
336<pre>void addListener(function callback(...))
337void removeListener(function callback(...))
338bool hasListener(function callback(...))
339</pre>
340
341<!-- [PENDING: explain removeListener and hasListener] -->
342</div>
343
344        <!-- API PAGE -->
345        <div class="apiPage" style="display: none; ">
346        <a name="apiReference"></a>
347        <h2>API reference: chrome.apiname </h2>
348
349          <!-- PROPERTIES -->
350          <div class="apiGroup">
351            <a name="properties"></a>
352            <h3 id="properties">Properties</h3>
353
354            <div>
355              <a></a>
356              <h4>getLastError</h4>
357              <div class="summary">
358                <!-- Note: intentionally longer 80 columns -->
359                <span>chrome.extension</span><span>lastError</span>
360              </div>
361              <div>
362              </div>
363            </div>
364
365          </div> <!-- /apiGroup -->
366
367          <!-- METHODS -->
368          <div class="apiGroup" id="methods">
369            <a name="methods"></a>
370            <h3>Methods</h3>
371
372            <!-- iterates over all functions -->
373            <div class="apiItem">
374              <a></a> <!-- method-anchor -->
375              <h4>method name</h4>
376
377              <div class="summary"><span>void</span>
378                  <!-- Note: intentionally longer 80 columns -->
379                  <span>chrome.module.methodName</span>(<span><span>, </span><span></span>
380                      <var><span></span></var></span>)</div>
381
382              <div class="description">
383                <p class="todo">Undocumented.</p>
384                <p>
385                  A description from the json schema def of the function goes here.
386                </p>
387
388                <!-- PARAMETERS -->
389                <h4>Parameters</h4>
390                <dl>
391                  <div>
392                    <div>
393                    </div>
394                  </div>
395                </dl>
396
397                <!-- RETURNS -->
398                <h4>Returns</h4>
399                <dl>
400                  <div>
401                    <div>
402                    </div>
403                  </div>
404                </dl>
405
406                <!-- CALLBACK -->
407                <div>
408                  <div>
409                  <h4>Callback function</h4>
410                  <p>
411                    The callback <em>parameter</em> should specify a function
412                    that looks like this:
413                  </p>
414                  <p>
415                    If you specify the <em>callback</em> parameter, it should
416                    specify a function that looks like this:
417                  </p>
418
419                  <!-- Note: intentionally longer 80 columns -->
420                  <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>;</pre>
421                  <dl>
422                    <div>
423                      <div>
424                      </div>
425                    </div>
426                  </dl>
427                  </div>
428                </div>
429
430                <!-- MIN_VERSION -->
431                <p>
432                  This function was added in version <b><span></span></b>.
433                  If you require this function, the manifest key
434                  <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
435                  can ensure that your extension won't be run in an earlier browser version.
436                </p>
437              </div> <!-- /description -->
438
439            </div>  <!-- /apiItem -->
440
441          </div>  <!-- /apiGroup -->
442
443          <!-- EVENTS -->
444          <div class="apiGroup">
445            <a name="events"></a>
446            <h3 id="events">Events</h3>
447
448            <!-- iterates over all events -->
449            <div class="apiItem">
450              <a></a>
451              <h4>event name</h4>
452
453              <div class="summary">
454                <!-- Note: intentionally longer 80 columns -->
455                <span class="subdued">chrome.bookmarks</span><span>onEvent</span><span class="subdued">.addListener</span>(function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>);
456              </div>
457
458              <div class="description">
459                <p class="todo">Undocumented.</p>
460                <p>
461                  A description from the json schema def of the event goes here.
462                </p>
463
464                <!-- PARAMETERS -->
465                <h4>Parameters</h4>
466                <dl>
467                  <div>
468                    <div>
469                    </div>
470                  </div>
471                </dl>
472
473              </div> <!-- /decription -->
474
475            </div> <!-- /apiItem -->
476
477          </div> <!-- /apiGroup -->
478
479          <!-- TYPES -->
480          <div class="apiGroup">
481            <a name="types"></a>
482            <h3 id="types">Types</h3>
483
484            <!-- iterates over all types -->
485            <div class="apiItem">
486              <a></a>
487              <h4>type name</h4>
488
489              <div>
490              </div>
491
492            </div> <!-- /apiItem -->
493
494          </div> <!-- /apiGroup -->
495
496        </div> <!-- /apiPage -->
497      </div> <!-- /gc-pagecontent -->
498    </div> <!-- /g-section -->
499  </div> <!-- /codesiteContent -->
500    <div id="gc-footer" --="">
501      <div class="text">
502  <p>
503  Except as otherwise <a href="http://code.google.com/policies.html#restrictions">noted</a>,
504  the content of this page is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons
505  Attribution 3.0 License</a>, and code samples are licensed under the
506  <a rel="license" href="http://code.google.com/google_bsd_license.html">BSD License</a>.
507  </p>
508  <p>
509  ©2010 Google
510  </p>
511
512<!-- begin analytics -->
513<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
514<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>
515
516<script type="text/javascript">
517  // chrome doc tracking
518  try {
519    var engdocs = _gat._getTracker("YT-10763712-2");
520    engdocs._trackPageview();
521  } catch(err) {}
522
523  // code.google.com site-wide tracking
524  try {
525    _uacct="UA-18071-1";
526    _uanchor=1;
527    _uff=0;
528    urchinTracker();
529  }
530  catch(e) {/* urchinTracker not available. */}
531</script>
532<!-- end analytics -->
533      </div>
534    </div> <!-- /gc-footer -->
535  </div> <!-- /gc-container -->
536</body></html>
537