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