getstarted.html revision 731df977c0511bca2206b5f333555b1205ff1f43
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>Tutorial: Getting Started (Hello, World!) - 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 class="leftNavSelected">Getting Started</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><a href="events.html">Events</a></li>
179                  <li><a href="history.html">History</a></li>
180                  <li><a href="management.html">Management</a></li>
181                  <li><a href="tabs.html">Tabs</a></li>
182                  <li><a href="windows.html">Windows</a></li>
183                </ul>
184              </li>
185              <li>Implementation
186                <ul>
187                  <li><a href="a11y.html">Accessibility</a></li>
188                  <li><a href="background_pages.html">Background Pages</a></li>
189                  <li><a href="content_scripts.html">Content Scripts</a></li>
190                  <li><a href="xhr.html">Cross-Origin XHR</a></li>
191                  <li><a href="idle.html">Idle</a></li>
192                  <li><a href="i18n.html">Internationalization</a></li>
193                  <li><a href="messaging.html">Message Passing</a></li>
194                  <li><a href="npapi.html">NPAPI Plugins</a></li>
195                </ul>
196              </li>
197              <li>Finishing
198                <ul>
199                  <li><a href="hosting.html">Hosting</a></li>
200                  <li><a href="external_extensions.html">Other Deployment Options</a></li>
201                </ul>
202              </li>
203            </ul>
204          </li>
205          <li><h2><a href="tutorials.html">Tutorials</a></h2>
206            <ul>
207              <li><a href="tut_debugging.html">Debugging</a></li>
208              <li><a href="tut_analytics.html">Google Analytics</a></li>
209              <li><a href="tut_oauth.html">OAuth</a></li>
210            </ul>
211          </li>
212          <li><h2>Reference</h2>
213            <ul>
214              <li>Formats
215                <ul>
216                  <li><a href="manifest.html">Manifest Files</a></li>
217                  <li><a href="match_patterns.html">Match Patterns</a></li>
218                  <!-- <li>Packages (.crx)</li> -->
219                </ul>
220              </li>
221              <li><a href="api_index.html">chrome.* APIs</a></li>
222              <li><a href="api_other.html">Other APIs</a></li>
223            </ul>
224          </li>
225         <li><h2><a href="samples.html">Samples</a></h2></li>
226        </ul>
227      </div>
228
229    <div class="g-unit" id="gc-pagecontent">
230      <div id="pageTitle">
231        <h1 class="page_title">Tutorial: Getting Started (Hello, World!)</h1>
232      </div>
233        <!-- TABLE OF CONTENTS -->
234        <div id="toc">
235          <h2>Contents</h2>
236          <ol>
237            <li>
238              <a href="#load">Create and load an extension</a>
239              <ol>
240                <li style="display: none; ">
241                  <a>h3Name</a>
242                </li>
243              </ol>
244            </li><li>
245              <a href="#code">Add code to the extension</a>
246              <ol>
247                <li style="display: none; ">
248                  <a>h3Name</a>
249                </li>
250              </ol>
251            </li><li>
252              <a href="#summary">Now what?</a>
253              <ol>
254                <li style="display: none; ">
255                  <a>h3Name</a>
256                </li>
257              </ol>
258            </li>
259              <li style="display: none; ">
260                <a href="#apiReference">API reference</a>
261                <ol>
262                  <li>
263                    <a href="#properties">Properties</a>
264                    <ol>
265                      <li>
266                        <a href="#property-anchor">propertyName</a>
267                      </li>
268                    </ol>
269                  </li>
270                  <li>
271                    <a href="#methods">Methods</a>
272                    <ol>
273                      <li>
274                        <a href="#method-anchor">methodName</a>
275                      </li>
276                    </ol>
277                  </li>
278                  <li>
279                    <a href="#events">Events</a>
280                    <ol>
281                      <li>
282                        <a href="#event-anchor">eventName</a>
283                      </li>
284                    </ol>
285                  </li>
286                  <li>
287                    <a href="#types">Types</a>
288                    <ol>
289                      <li>
290                        <a href="#id-anchor">id</a>
291                      </li>
292                    </ol>
293                  </li>
294                </ol>
295              </li>
296          </ol>
297        </div>
298        <!-- /TABLE OF CONTENTS -->
299
300        <!-- Standard content lead-in for experimental API pages -->
301        <p id="classSummary" style="display: none; ">
302          For information on how to use experimental APIs, see the <a href="experimental.html">chrome.experimental.* APIs</a> page.
303        </p>
304
305        <!-- STATIC CONTENT PLACEHOLDER -->
306        <div id="static"><div id="pageData-name" class="pageData">Tutorial: Getting Started (Hello, World!)</div>
307<div id="pageData-showTOC" class="pageData">true</div>
308
309<p>
310This tutorial walks you through creating a simple extension.
311You'll add an icon to Google Chrome
312that, when clicked, displays an automatically generated page.
313The icon and page will look something like this:
314</p>
315
316<img src="images/hello-world-small.png" width="300" height="221" alt="a window with a grid of images related to HELLO WORLD">
317
318<p>
319You can develop extensions using any release of Google Chrome,
320on Windows, Mac, or Linux.
321</p>
322
323<h2 id="load">Create and load an extension</h2>
324<p>
325In this section, you'll write an extension
326that adds a <em>browser action</em>
327to the toolbar of Google Chrome.
328</p>
329
330<ol>
331  <li>
332    Create a folder somewhere on your computer to contain your extension's code.
333  </li>
334  <li>
335    Inside your extension's folder,
336    create a text file called <strong><code>manifest.json</code></strong>,
337    and put this in it:
338<pre>{
339  "name": "My First Extension",
340  "version": "1.0",
341  "description": "The first extension that I made.",
342  "browser_action": {
343    "default_icon": "icon.png"
344  },
345  "permissions": [
346    "http://api.flickr.com/"
347  ]
348}</pre>
349  </li>
350  <li>
351    Copy this icon to the same folder:<br>
352    <table cellpadding="0" cellspacing="0" style="border:0">
353      <tbody><tr>
354        <td style="text-align:center; border:0;"><a href="examples/tutorials/getstarted/icon.png"><img src="examples/tutorials/getstarted/icon.png" width="19" height="19" border="0"></a><br>
355          <a href="examples/tutorials/getstarted/icon.png">Download icon.png</a></td>
356      </tr>
357    </tbody></table>
358  </li>
359  <li id="load-ext"> Load the extension.
360    <ol type="a">
361      <li>
362      Bring up the extensions management page
363      by clicking the Tools menu
364      <img src="images/toolsmenu.gif" width="43" height="34" alt="" align="absmiddle" style="margin:0; padding:0">
365      (or the Window menu on Mac)
366      and choosing <b>Extensions</b>.
367      (If you're using version 6 or later,
368      choose <b>Tools &gt; Extensions</b>.)
369      </li>
370
371      <li>
372      If <b>Developer mode</b> has a + by it,
373      click the + to add developer information to the page.
374      The + changes to a -,
375      and more buttons and information appear.
376      </li>
377
378      <li>
379      Click the <b>Load unpacked extension</b> button.
380      A file dialog appears.
381      </li>
382
383      <li>
384      In the file dialog,
385      navigate to your extension's folder
386      and click <b>OK</b>.
387      </li>
388    </ol> </li>
389  </ol>
390
391<p>
392If your extension is valid,
393its icon appears next to the address bar,
394and information about the extension
395appears in the extensions page,
396as the following screenshot shows.
397</p>
398
399<p>
400<a href="images/load_after.png"><img src="images/load_after_small.png" width="300" height="132"></a>
401</p>
402
403<h2 id="code">Add code to the extension</h2>
404<p> In this step, you'll make your extension <em>do</em> something besides just look good. </p>
405<ol>
406  <li>
407    <p> Edit <code>manifest.json</code> to add the following line:</p>
408<pre>  ...
409  "browser_action": {
410    "default_icon": "icon.png"<b>,
411    "popup": "popup.html"</b>
412  },
413  ...
414</pre>
415    <p> Inside your extension's folder,
416    create a text file called <strong><code>popup.html</code></strong>,
417    and add the following code to it:</p>
418    <blockquote> <a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/tutorials/getstarted/popup.html?content-type=text/plain" target="_blank">CSS
419    and JavaScript code for hello_world</a></blockquote>
420  </li>
421  <li>
422    Return to the extensions management page,
423    and click the <b>Reload</b> button
424    to load the new version of the extension.</li>
425  <li>Click the extension's icon.
426  A popup should appear that displays the contents of
427  <code>popup.html</code>. </li>
428</ol>
429<p> It should look something like this:</p>
430
431<img src="images/hello-world.png" width="500" height="369" alt="a popup with a grid of images related to HELLO WORLD">
432
433<p> If you don't see the popup,
434try the instructions again,
435following them exactly.
436Don't try loading an HTML file that isn't in the extension's folder —
437it won't work! </p>
438
439<h2 id="summary">Now what?</h2>
440
441<!-- [PENDING: Summarize what we did, what it means, what else we would've done if this were a real extension (e.g. package/zip it), and where to find more information.] -->
442
443<p>
444Here are some suggestions for what to read next:
445</p>
446
447<ul>
448  <li>
449    The <a href="overview.html">Overview</a>,
450    which has important conceptual and practical information
451  </li>
452  <li>
453    The
454    <a href="tut_debugging.html">debugging tutorial</a>,
455    which starts where this tutorial leaves off
456  </li>
457  <li>
458    The <a href="hosting.html">hosting</a> page,
459    which tells you about the gallery
460    and other options for distributing your extension
461  </li>
462</ul>
463
464<p>
465If you don't feel like reading, try these:
466</p>
467<ul>
468  <li>
469    Keep up to date with the latest news:
470    <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions/subscribe">subscribe to chromium-extensions</a>
471  </li>
472  <li>
473    Look at some
474    <a href="samples.html">sample extensions</a>
475  </li>
476  <li>
477    Watch some
478    <a href="http://www.youtube.com/view_play_list?p=CA101D6A85FE9D4B">videos</a>, such as
479    <a href="http://www.youtube.com/watch?v=e3McMaHvlBY&feature=PlayList&p=CA101D6A85FE9D4B&index=3">How to build an extension</a>
480  </li>
481</ul>
482</div>
483
484        <!-- API PAGE -->
485        <div class="apiPage" style="display: none; ">
486        <a name="apiReference"></a>
487        <h2>API reference: chrome.apiname </h2>
488
489          <!-- PROPERTIES -->
490          <div class="apiGroup">
491            <a name="properties"></a>
492            <h3 id="properties">Properties</h3>
493
494            <div>
495              <a></a>
496              <h4>getLastError</h4>
497              <div class="summary">
498                <!-- Note: intentionally longer 80 columns -->
499                <span>chrome.extension</span><span>lastError</span>
500              </div>
501              <div>
502              </div>
503            </div>
504
505          </div> <!-- /apiGroup -->
506
507          <!-- METHODS -->
508          <div class="apiGroup" id="methods">
509            <a name="methods"></a>
510            <h3>Methods</h3>
511
512            <!-- iterates over all functions -->
513            <div class="apiItem">
514              <a></a> <!-- method-anchor -->
515              <h4>method name</h4>
516
517              <div class="summary"><span>void</span>
518                  <!-- Note: intentionally longer 80 columns -->
519                  <span>chrome.module.methodName</span>(<span><span>, </span><span></span>
520                      <var><span></span></var></span>)</div>
521
522              <div class="description">
523                <p class="todo">Undocumented.</p>
524                <p>
525                  A description from the json schema def of the function goes here.
526                </p>
527
528                <!-- PARAMETERS -->
529                <h4>Parameters</h4>
530                <dl>
531                  <div>
532                    <div>
533                    </div>
534                  </div>
535                </dl>
536
537                <!-- RETURNS -->
538                <h4>Returns</h4>
539                <dl>
540                  <div>
541                    <div>
542                    </div>
543                  </div>
544                </dl>
545
546                <!-- CALLBACK -->
547                <div>
548                  <div>
549                  <h4>Callback function</h4>
550                  <p>
551                    The callback <em>parameter</em> should specify a function
552                    that looks like this:
553                  </p>
554                  <p>
555                    If you specify the <em>callback</em> parameter, it should
556                    specify a function that looks like this:
557                  </p>
558
559                  <!-- Note: intentionally longer 80 columns -->
560                  <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>;</pre>
561                  <dl>
562                    <div>
563                      <div>
564                      </div>
565                    </div>
566                  </dl>
567                  </div>
568                </div>
569
570                <!-- MIN_VERSION -->
571                <p>
572                  This function was added in version <b><span></span></b>.
573                  If you require this function, the manifest key
574                  <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
575                  can ensure that your extension won't be run in an earlier browser version.
576                </p>
577              </div> <!-- /description -->
578
579            </div>  <!-- /apiItem -->
580
581          </div>  <!-- /apiGroup -->
582
583          <!-- EVENTS -->
584          <div class="apiGroup">
585            <a name="events"></a>
586            <h3 id="events">Events</h3>
587
588            <!-- iterates over all events -->
589            <div class="apiItem">
590              <a></a>
591              <h4>event name</h4>
592
593              <div class="summary">
594                <!-- Note: intentionally longer 80 columns -->
595                <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>);
596              </div>
597
598              <div class="description">
599                <p class="todo">Undocumented.</p>
600                <p>
601                  A description from the json schema def of the event goes here.
602                </p>
603
604                <!-- PARAMETERS -->
605                <h4>Parameters</h4>
606                <dl>
607                  <div>
608                    <div>
609                    </div>
610                  </div>
611                </dl>
612
613              </div> <!-- /decription -->
614
615            </div> <!-- /apiItem -->
616
617          </div> <!-- /apiGroup -->
618
619          <!-- TYPES -->
620          <div class="apiGroup">
621            <a name="types"></a>
622            <h3 id="types">Types</h3>
623
624            <!-- iterates over all types -->
625            <div class="apiItem">
626              <a></a>
627              <h4>type name</h4>
628
629              <div>
630              </div>
631
632            </div> <!-- /apiItem -->
633
634          </div> <!-- /apiGroup -->
635
636        </div> <!-- /apiPage -->
637      </div> <!-- /gc-pagecontent -->
638    </div> <!-- /g-section -->
639  </div> <!-- /codesiteContent -->
640    <div id="gc-footer" --="">
641      <div class="text">
642  <p>
643  Except as otherwise <a href="http://code.google.com/policies.html#restrictions">noted</a>,
644  the content of this page is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons
645  Attribution 3.0 License</a>, and code samples are licensed under the
646  <a rel="license" href="http://code.google.com/google_bsd_license.html">BSD License</a>.
647  </p>
648  <p>
649  ©2010 Google
650  </p>
651
652<!-- begin analytics -->
653<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
654<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>
655
656<script type="text/javascript">
657  // chrome doc tracking
658  try {
659    var engdocs = _gat._getTracker("YT-10763712-2");
660    engdocs._trackPageview();
661  } catch(err) {}
662
663  // code.google.com site-wide tracking
664  try {
665    _uacct="UA-18071-1";
666    _uanchor=1;
667    _uff=0;
668    urchinTracker();
669  }
670  catch(e) {/* urchinTracker not available. */}
671</script>
672<!-- end analytics -->
673      </div>
674    </div> <!-- /gc-footer -->
675  </div> <!-- /gc-container -->
676</body></html>
677