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