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>Desktop Notifications - 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 <!-- OBJECT METHODS --> 85 <dd> 86 <div></div> 87 </dd> 88 89 <!-- OBJECT EVENT FIELDS --> 90 <dd> 91 <div></div> 92 </dd> 93 94 <!-- FUNCTION PARAMETERS --> 95 <dd> 96 <div></div> 97 </dd> 98 99 </div> <!-- /VALUE --> 100 101 <div id="functionParametersTemplate"> 102 <h5>Parameters</h5> 103 <dl> 104 <div> 105 <div> 106 </div> 107 </div> 108 </dl> 109 </div> 110 </div> <!-- /SUBTEMPLATES --> 111 112 <a id="top"></a> 113 <div id="skipto"> 114 <a href="#gc-pagecontent">Skip to page content</a> 115 <a href="#gc-toc">Skip to main navigation</a> 116 </div> 117 <!-- API HEADER --> 118 <table id="header" width="100%" cellspacing="0" border="0"> 119 <tbody><tr> 120 <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> 121 <td valign="middle" width="100%" style="padding-left:0.6em;"> 122 <form action="http://www.google.com/cse" id="cse" style="margin-top:0.5em"> 123 <div id="gsc-search-box"> 124 <input type="hidden" name="cx" value="002967670403910741006:61_cvzfqtno"> 125 <input type="hidden" name="ie" value="UTF-8"> 126 <input type="text" name="q" value="" size="55"> 127 <input class="gsc-search-button" type="submit" name="sa" value="Search"> 128 <br> 129 <span class="greytext">e.g. "page action" or "tabs"</span> 130 </div> 131 </form> 132 133 <script type="text/javascript" src="http://www.google.com/jsapi"></script> 134 <script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script> 135 <script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse&t13n_langs=en"></script> 136 <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse&lang=en"></script> 137 </td> 138 </tr> 139 </tbody></table> 140 141 <div id="codesiteContent" class=""> 142 143 <a id="gc-topnav-anchor"></a> 144 <div id="gc-topnav"> 145 <h1>Google Chrome Extensions (<a href="http://code.google.com/labs/">Labs</a>)</h1> 146 <ul id="home" class="gc-topnav-tabs"> 147 <li id="home_link"> 148 <a href="index.html" title="Google Chrome Extensions home page">Home</a> 149 </li> 150 <li id="docs_link"> 151 <a href="docs.html" title="Official Google Chrome Extensions documentation">Docs</a> 152 </li> 153 <li id="faq_link"> 154 <a href="faq.html" title="Answers to frequently asked questions about Google Chrome Extensions">FAQ</a> 155 </li> 156 <li id="samples_link"> 157 <a href="samples.html" title="Sample extensions (with source code)">Samples</a> 158 </li> 159 <li id="group_link"> 160 <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions" title="Google Chrome Extensions developer forum">Group</a> 161 </li> 162 </ul> 163 </div> <!-- end gc-topnav --> 164 165 <div class="g-section g-tpl-170"> 166 <!-- SIDENAV --> 167 <div class="g-unit g-first" id="gc-toc"> 168 <ul> 169 <li><a href="getstarted.html">Getting Started</a></li> 170 <li><a href="overview.html">Overview</a></li> 171 <li><a href="whats_new.html">What's New?</a></li> 172 <li><h2><a href="devguide.html">Developer's Guide</a></h2> 173 <ul> 174 <li>Browser UI 175 <ul> 176 <li><a href="browserAction.html">Browser Actions</a></li> 177 <li><a href="contextMenus.html">Context Menus</a></li> 178 <li class="leftNavSelected">Desktop Notifications</li> 179 <li><a href="omnibox.html">Omnibox</a></li> 180 <li><a href="options.html">Options Pages</a></li> 181 <li><a href="override.html">Override Pages</a></li> 182 <li><a href="pageAction.html">Page Actions</a></li> 183 </ul> 184 </li> 185 <li>Browser Interaction 186 <ul> 187 <li><a href="bookmarks.html">Bookmarks</a></li> 188 <li><a href="cookies.html">Cookies</a></li> 189 <li><a href="events.html">Events</a></li> 190 <li><a href="history.html">History</a></li> 191 <li><a href="management.html">Management</a></li> 192 <li><a href="tabs.html">Tabs</a></li> 193 <li><a href="windows.html">Windows</a></li> 194 </ul> 195 </li> 196 <li>Implementation 197 <ul> 198 <li><a href="a11y.html">Accessibility</a></li> 199 <li><a href="background_pages.html">Background Pages</a></li> 200 <li><a href="content_scripts.html">Content Scripts</a></li> 201 <li><a href="xhr.html">Cross-Origin XHR</a></li> 202 <li><a href="idle.html">Idle</a></li> 203 <li><a href="i18n.html">Internationalization</a></li> 204 <li><a href="messaging.html">Message Passing</a></li> 205 <li><a href="npapi.html">NPAPI Plugins</a></li> 206 </ul> 207 </li> 208 <li>Finishing 209 <ul> 210 <li><a href="hosting.html">Hosting</a></li> 211 <li><a href="external_extensions.html">Other Deployment Options</a></li> 212 </ul> 213 </li> 214 </ul> 215 </li> 216 <li><h2><a href="apps.html">Packaged Apps</a></h2></li> 217 <li><h2><a href="tutorials.html">Tutorials</a></h2> 218 <ul> 219 <li><a href="tut_debugging.html">Debugging</a></li> 220 <li><a href="tut_analytics.html">Google Analytics</a></li> 221 <li><a href="tut_oauth.html">OAuth</a></li> 222 </ul> 223 </li> 224 <li><h2>Reference</h2> 225 <ul> 226 <li>Formats 227 <ul> 228 <li><a href="manifest.html">Manifest Files</a></li> 229 <li><a href="match_patterns.html">Match Patterns</a></li> 230 </ul> 231 </li> 232 <li><a href="permission_warnings.html">Permission Warnings</a></li> 233 <li><a href="api_index.html">chrome.* APIs</a></li> 234 <li><a href="api_other.html">Other APIs</a></li> 235 </ul> 236 </li> 237 <li><h2><a href="samples.html">Samples</a></h2></li> 238 <div class="line"> </div> 239 <li><h2>More</h2> 240 <ul> 241 <li><a href="http://code.google.com/chrome/webstore/docs/index.html">Chrome Web Store</a></li> 242 <li><a href="http://code.google.com/chrome/apps/docs/developers_guide.html">Hosted Apps</a></li> 243 <li><a href="themes.html">Themes</a></li> 244 </ul> 245 </li> 246 </ul> 247 </div> 248 <script> 249 initToggles(); 250 </script> 251 252 <div class="g-unit" id="gc-pagecontent"> 253 <div id="pageTitle"> 254 <h1 class="page_title">Desktop Notifications</h1> 255 </div> 256 <!-- TABLE OF CONTENTS --> 257 <div id="toc"> 258 <h2>Contents</h2> 259 <ol> 260 <li> 261 <a href="#manifest">Manifest</a> 262 <ol> 263 <li style="display: none; "> 264 <a>h3Name</a> 265 </li> 266 </ol> 267 </li><li> 268 <a href="#communication">Communicating with other views</a> 269 <ol> 270 <li style="display: none; "> 271 <a>h3Name</a> 272 </li> 273 </ol> 274 </li><li> 275 <a href="#examples"> Examples </a> 276 <ol> 277 <li style="display: none; "> 278 <a>h3Name</a> 279 </li> 280 </ol> 281 </li><li> 282 <a href="#api">API</a> 283 <ol> 284 <li style="display: none; "> 285 <a>h3Name</a> 286 </li> 287 </ol> 288 </li> 289 <li style="display: none; "> 290 <a href="#apiReference">API reference</a> 291 <ol> 292 <li> 293 <a href="#properties">Properties</a> 294 <ol> 295 <li> 296 <a href="#property-anchor">propertyName</a> 297 </li> 298 </ol> 299 </li> 300 <li> 301 <a>Methods</a> 302 <ol> 303 <li> 304 <a href="#method-anchor">methodName</a> 305 </li> 306 </ol> 307 </li> 308 <li> 309 <a>Events</a> 310 <ol> 311 <li> 312 <a href="#event-anchor">eventName</a> 313 </li> 314 </ol> 315 </li> 316 <li> 317 <a href="#types">Types</a> 318 <ol> 319 <li> 320 <a href="#id-anchor">id</a> 321 </li> 322 </ol> 323 </li> 324 </ol> 325 </li> 326 </ol> 327 </div> 328 <!-- /TABLE OF CONTENTS --> 329 330 <!-- Standard content lead-in for experimental API pages --> 331 <p id="classSummary" style="display: none; "> 332 For information on how to use experimental APIs, see the <a href="experimental.html">chrome.experimental.* APIs</a> page. 333 </p> 334 335 <!-- STATIC CONTENT PLACEHOLDER --> 336 <div id="static"><div id="pageData-name" class="pageData">Desktop Notifications</div> 337 <div id="pageData-showTOC" class="pageData">true</div> 338 339 <!-- BEGIN AUTHORED CONTENT --> 340 <p> 341 Use desktop notifications to notify users that something 342 important has happened. 343 Notifications appear outside the browser window. 344 As the following snapshots show, 345 the details of how notifications look 346 and where they're shown depend on the platform. 347 </p> 348 349 <img src="images/notification-windows.png" width="28%" style="margin:2em 0.5em 1em; border:1px solid black;" alt="Notifications on Microsoft Windows"> 350 <img src="images/notification-mac.png" width="28%" style="margin:2em 0.5em 1em; border:1px solid black;" alt="Notifications on Mac OS X"> 351 <img src="images/notification-linux.png" width="28%" style="margin:2em 0.5em 1em; border:1px solid black;" alt="Notifications on Ubuntu Linux"> 352 353 <p> 354 You create the notification window 355 using a bit of JavaScript and, optionally, 356 an HTML page packaged inside your extension. 357 </p> 358 359 360 <h2 id="manifest">Manifest</h2> 361 362 <p> 363 You can request the notification permission 364 in the <a href="manifest.html">extension manifest</a>, 365 like this: 366 </p> 367 368 <pre>{ 369 "name": "My extension", 370 ... 371 <b> "permissions": [ 372 "notifications" 373 ]</b>, 374 ... 375 }</pre> 376 377 <p class="note"> 378 <b>Note:</b> Extensions that declare 379 the <code>notifications</code> permission 380 are always allowed to create notifications. 381 There is no need to call 382 <code>webkitNotifications.checkPermission()</code>. 383 </p> 384 385 <h2 id="communication">Communicating with other views</h2> 386 387 <p> 388 You can communicate between a notification 389 and other views in your extension using 390 <a href="extension.html#method-getBackgroundPage">getBackgroundPage()</a> and 391 <a href="extension.html#method-getViews">getViews()</a>. For example: 392 </p> 393 394 <pre>// Inside a notification... 395 chrome.extension.getBackgroundPage().doThing(); 396 397 // From the background page... 398 chrome.extension.getViews({type:"notification"}).forEach(function(win) { 399 win.doOtherThing(); 400 }); 401 </pre> 402 403 404 <h2 id="examples"> Examples </h2> 405 406 <p> 407 You can find a simple example 408 of using notifications in the 409 <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/notifications/">examples/api/notifications</a> 410 directory. 411 For other examples 412 and for help in viewing the source code, 413 see <a href="samples.html">Samples</a>. 414 </p> 415 416 <p> 417 Also see html5rocks.com's 418 <a href="http://www.html5rocks.com/tutorials/notifications/quick/">notifications tutorial</a>. 419 Ignore the permission-related code; 420 it's unnecessary if you declare the "notifications" permission. 421 </p> 422 423 <h2 id="api">API</h2> 424 425 <p> 426 The desktop notification API for extensions 427 is the same one that 428 is available to normal web pages. 429 As the following code shows, 430 you first create either a simple text notification 431 or an HTML notification, 432 and then you show the notification. 433 </p> 434 435 <pre>// Create a simple text notification: 436 var notification = webkitNotifications.createNotification( 437 '48.png', // icon url - can be relative 438 'Hello!', // notification title 439 'Lorem ipsum...' // notification body text 440 ); 441 442 // Or create an HTML notification: 443 var notification = webkitNotifications.createHTMLNotification( 444 'notification.html' // html url - can be relative 445 ); 446 447 // Then show the notification. 448 notification.show(); 449 </pre> 450 451 <p>For complete API details, 452 see the <a href="http://dev.chromium.org/developers/design-documents/desktop-notifications/api-specification">Desktop notifications draft specification</a>.</p> 453 454 <!-- END AUTHORED CONTENT --> 455 </div> 456 457 <!-- API PAGE --> 458 <div class="apiPage" style="display: none; "> 459 <a name="apiReference"></a> 460 <h2>API reference: chrome.apiname </h2> 461 462 <!-- PROPERTIES --> 463 <div class="apiGroup"> 464 <a name="properties"></a> 465 <h3 id="properties">Properties</h3> 466 467 <div> 468 <a></a> 469 <h4>getLastError</h4> 470 <div class="summary"> 471 <!-- Note: intentionally longer 80 columns --> 472 <span>chrome.extension</span><span>lastError</span> 473 </div> 474 <div> 475 </div> 476 </div> 477 478 </div> <!-- /apiGroup --> 479 480 <!-- METHODS --> 481 <div id="methodsTemplate" class="apiGroup"> 482 <a></a> 483 <h3>Methods</h3> 484 485 <!-- iterates over all functions --> 486 <div class="apiItem"> 487 <a></a> <!-- method-anchor --> 488 <h4>method name</h4> 489 490 <div class="summary"><span>void</span> 491 <!-- Note: intentionally longer 80 columns --> 492 <span>chrome.module.methodName</span>(<span><span>, </span><span></span> 493 <var><span></span></var></span>)</div> 494 495 <div class="description"> 496 <p class="todo">Undocumented.</p> 497 <p> 498 A description from the json schema def of the function goes here. 499 </p> 500 501 <!-- PARAMETERS --> 502 <h4>Parameters</h4> 503 <dl> 504 <div> 505 <div> 506 </div> 507 </div> 508 </dl> 509 510 <!-- RETURNS --> 511 <h4>Returns</h4> 512 <dl> 513 <div> 514 <div> 515 </div> 516 </div> 517 </dl> 518 519 <!-- CALLBACK --> 520 <div> 521 <div> 522 <h4>Callback function</h4> 523 <p> 524 The callback <em>parameter</em> should specify a function 525 that looks like this: 526 </p> 527 <p> 528 If you specify the <em>callback</em> parameter, it should 529 specify a function that looks like this: 530 </p> 531 532 <!-- Note: intentionally longer 80 columns --> 533 <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>;</pre> 534 <dl> 535 <div> 536 <div> 537 </div> 538 </div> 539 </dl> 540 </div> 541 </div> 542 543 <!-- MIN_VERSION --> 544 <p> 545 This function was added in version <b><span></span></b>. 546 If you require this function, the manifest key 547 <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> 548 can ensure that your extension won't be run in an earlier browser version. 549 </p> 550 </div> <!-- /description --> 551 552 </div> <!-- /apiItem --> 553 554 </div> <!-- /apiGroup --> 555 556 <!-- EVENTS --> 557 <div id="eventsTemplate" class="apiGroup"> 558 <a></a> 559 <h3>Events</h3> 560 <!-- iterates over all events --> 561 <div class="apiItem"> 562 <a></a> 563 <h4>event name</h4> 564 565 <div class="summary"> 566 <!-- Note: intentionally longer 80 columns --> 567 <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>); 568 </div> 569 570 <div class="description"> 571 <p class="todo">Undocumented.</p> 572 <p> 573 A description from the json schema def of the event goes here. 574 </p> 575 576 <!-- PARAMETERS --> 577 <div> 578 <h4>Parameters</h4> 579 <dl> 580 <div> 581 <div> 582 </div> 583 </div> 584 </dl> 585 </div> 586 </div> <!-- /decription --> 587 588 </div> <!-- /apiItem --> 589 590 </div> <!-- /apiGroup --> 591 592 <!-- TYPES --> 593 <div class="apiGroup"> 594 <a name="types"></a> 595 <h3 id="types">Types</h3> 596 597 <!-- iterates over all types --> 598 <div class="apiItem"> 599 <a></a> 600 <h4>type name</h4> 601 602 <div> 603 </div> 604 605 </div> <!-- /apiItem --> 606 607 </div> <!-- /apiGroup --> 608 609 </div> <!-- /apiPage --> 610 </div> <!-- /gc-pagecontent --> 611 </div> <!-- /g-section --> 612 </div> <!-- /codesiteContent --> 613 <div id="gc-footer" --=""> 614 <div class="text"> 615 <p> 616 Except as otherwise <a href="http://code.google.com/policies.html#restrictions">noted</a>, 617 the content of this page is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons 618 Attribution 3.0 License</a>, and code samples are licensed under the 619 <a rel="license" href="http://code.google.com/google_bsd_license.html">BSD License</a>. 620 </p> 621 <p> 622 2011 Google 623 </p> 624 625 <!-- begin analytics --> 626 <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script> 627 <script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script> 628 629 <script type="text/javascript"> 630 // chrome doc tracking 631 try { 632 var engdocs = _gat._getTracker("YT-10763712-2"); 633 engdocs._trackPageview(); 634 } catch(err) {} 635 636 // code.google.com site-wide tracking 637 try { 638 _uacct="UA-18071-1"; 639 _uanchor=1; 640 _uff=0; 641 urchinTracker(); 642 } 643 catch(e) {/* urchinTracker not available. */} 644 </script> 645 <!-- end analytics --> 646 </div> 647 </div> <!-- /gc-footer --> 648 </div> <!-- /gc-container --> 649 </body></html> 650