| OLD | NEW |
| (Empty) |
| 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/jstempla
te_compiled.js"> | |
| 15 </script> | |
| 16 <script type="text/javascript" src="../../../../third_party/json_minify/mini
fy-sans-regexp.js"> | |
| 17 </script> | |
| 18 <script type="text/javascript" src="js/api_page_generator.js"></script> | |
| 19 <script type="text/javascript" src="js/bootstrap.js"></script> | |
| 20 <script type="text/javascript" src="js/sidebar.js"></script> | |
| 21 <title>Tutorial: Debugging - Google Chrome Extensions - Google Code</title></h
ead> | |
| 22 <body> <div id="devModeWarning" class="displayModeWarning"> | |
| 23 You are viewing extension docs in chrome via the 'file:' scheme: are you exp
ecting to see local changes when you refresh? You'll need run chrome with --allo
w-file-access-from-files. | |
| 24 </div> | |
| 25 <div id="branchWarning" class="displayModeWarning"> | |
| 26 <span>WARNING: This is the <span id="branchName">BETA</span> documentation. | |
| 27 It may not work with the stable release of Chrome.</span> | |
| 28 <select id="branchChooser"> | |
| 29 <option>Choose a different version... | |
| 30 </option><option value="">Stable | |
| 31 </option><option value="beta">Beta | |
| 32 </option><option value="dev">Dev | |
| 33 </option><option value="trunk">Trunk | |
| 34 </option></select> | |
| 35 </div> | |
| 36 <div id="unofficialWarning" class="displayModeWarning"> | |
| 37 <span>WARNING: This is unofficial documentation. It may not work with the | |
| 38 current release of Chrome.</span> | |
| 39 <button id="goToOfficialDocs">Go to the official docs</button> | |
| 40 </div> | |
| 41 <div id="gc-container" class="labs"> | |
| 42 <!-- SUBTEMPLATES: DO NOT MOVE FROM THIS LOCATION --> | |
| 43 <!-- In particular, sub-templates that recurse, must be used by allowing | |
| 44 jstemplate to make a copy of the template in this section which | |
| 45 are not operated on by way of the jsskip="true" --> | |
| 46 <!-- /SUBTEMPLATES --> | |
| 47 <a id="top"></a> | |
| 48 <div id="skipto"> | |
| 49 <a href="#gc-pagecontent">Skip to page content</a> | |
| 50 <a href="#gc-toc">Skip to main navigation</a> | |
| 51 </div> | |
| 52 <!-- API HEADER --> | |
| 53 <table id="header" width="100%" cellspacing="0" border="0"> | |
| 54 <tbody><tr> | |
| 55 <td valign="middle"><a href="http://code.google.com/"><img src="images/c
ode_labs_logo.gif" height="43" width="161" alt="Google Code Labs" style="border:
0; margin:0;"></a></td> | |
| 56 <td valign="middle" width="100%" style="padding-left:0.6em;"> | |
| 57 <form action="http://www.google.com/cse" id="cse" style="margin-top:0.
5em"> | |
| 58 <div id="gsc-search-box"> | |
| 59 <input type="hidden" name="cx" value="002967670403910741006:61_cvz
fqtno"> | |
| 60 <input type="hidden" name="ie" value="UTF-8"> | |
| 61 <input type="text" name="q" value="" size="55"> | |
| 62 <input class="gsc-search-button" type="submit" name="sa" value="Se
arch"> | |
| 63 <br> | |
| 64 <span class="greytext">e.g. "page action" or "tabs"</span> | |
| 65 </div> | |
| 66 </form> | |
| 67 <script type="text/javascript" src="https://www.google.com/jsapi"></sc
ript> | |
| 68 <script type="text/javascript">google.load("elements", "1", {packages:
"transliteration"});</script> | |
| 69 <script type="text/javascript" src="https://www.google.com/coop/cse/t1
3n?form=cse&t13n_langs=en"></script> | |
| 70 <script type="text/javascript" src="https://www.google.com/coop/cse/br
and?form=cse&lang=en"></script> | |
| 71 </td> | |
| 72 </tr> | |
| 73 </tbody></table> | |
| 74 <div id="codesiteContent" class=""> | |
| 75 <a id="gc-topnav-anchor"></a> | |
| 76 <div id="gc-topnav"> | |
| 77 <h1>Google Chrome Extensions (<a href="http://code.google.com/labs/">Lab
s</a>)</h1> | |
| 78 <ul id="home" class="gc-topnav-tabs"> | |
| 79 <li id="home_link"> | |
| 80 <a href="index.html" title="Google Chrome Extensions home page">Home
</a> | |
| 81 </li> | |
| 82 <li id="docs_link"> | |
| 83 <a href="docs.html" title="Official Google Chrome Extensions documen
tation">Docs</a> | |
| 84 </li> | |
| 85 <li id="faq_link"> | |
| 86 <a href="faq.html" title="Answers to frequently asked questions abou
t Google Chrome Extensions">FAQ</a> | |
| 87 </li> | |
| 88 <li id="samples_link"> | |
| 89 <a href="samples.html" title="Sample extensions (with source code)">
Samples</a> | |
| 90 </li> | |
| 91 <li id="group_link"> | |
| 92 <a href="http://groups.google.com/a/chromium.org/group/chromium-exte
nsions" title="Google Chrome Extensions developer forum">Group</a> | |
| 93 </li> | |
| 94 <li id="so_link"> | |
| 95 <a href="http://stackoverflow.com/questions/tagged/google-chrome-ext
ension" title="[google-chrome-extension] tag on Stack Overflow">Questions?</a> | |
| 96 </li> | |
| 97 </ul> | |
| 98 </div> <!-- end gc-topnav --> | |
| 99 <div class="g-section g-tpl-170"> | |
| 100 <!-- SIDENAV --> | |
| 101 <div class="g-unit g-first" id="gc-toc"> | |
| 102 <ul> | |
| 103 <li><a href="getstarted.html">Getting Started</a></li> | |
| 104 <li><a href="overview.html">Overview</a></li> | |
| 105 <li><a href="whats_new.html">What's New?</a></li> | |
| 106 <li><h2><a href="devguide.html">Developer's Guide</a></h2> | |
| 107 <ul> | |
| 108 <li>Browser UI | |
| 109 <ul> | |
| 110 <li><a href="browserAction.html">Browser Actions</a></li> | |
| 111 <li><a href="contextMenus.html">Context Menus</a></li> | |
| 112 <li><a href="notifications.html">Desktop Notifications</a></li
> | |
| 113 <li><a href="omnibox.html">Omnibox</a></li> | |
| 114 <li><a href="options.html">Options Pages</a></li> | |
| 115 <li><a href="override.html">Override Pages</a></li> | |
| 116 <li><a href="pageAction.html">Page Actions</a></li> | |
| 117 </ul> | |
| 118 </li> | |
| 119 <li>Browser Interaction | |
| 120 <ul> | |
| 121 <li><a href="bookmarks.html">Bookmarks</a></li> | |
| 122 <li><a href="cookies.html">Cookies</a></li> | |
| 123 <li><a href="devtools.html">Developer Tools</a></li> | |
| 124 <li><a href="events.html">Events</a></li> | |
| 125 <li><a href="history.html">History</a></li> | |
| 126 <li><a href="management.html">Management</a></li> | |
| 127 <li><a href="tabs.html">Tabs</a></li> | |
| 128 <li><a href="windows.html">Windows</a></li> | |
| 129 </ul> | |
| 130 </li> | |
| 131 <li>Implementation | |
| 132 <ul> | |
| 133 <li><a href="a11y.html">Accessibility</a></li> | |
| 134 <li><a href="background_pages.html">Background Pages</a></li> | |
| 135 <li><a href="content_scripts.html">Content Scripts</a></li> | |
| 136 <li><a href="xhr.html">Cross-Origin XHR</a></li> | |
| 137 <li><a href="i18n.html">Internationalization</a></li> | |
| 138 <li><a href="messaging.html">Message Passing</a></li> | |
| 139 <li><a href="permissions.html">Optional Permissions</a></li> | |
| 140 <li><a href="npapi.html">NPAPI Plugins</a></li> | |
| 141 </ul> | |
| 142 </li> | |
| 143 <li>Finishing | |
| 144 <ul> | |
| 145 <li><a href="hosting.html">Hosting</a></li> | |
| 146 <li><a href="external_extensions.html">Other Deployment Option
s</a></li> | |
| 147 </ul> | |
| 148 </li> | |
| 149 </ul> | |
| 150 </li> | |
| 151 <li><h2><a href="apps.html">Packaged Apps</a></h2></li> | |
| 152 <li><h2><a href="tutorials.html">Tutorials</a></h2> | |
| 153 <ul> | |
| 154 <li class="leftNavSelected">Debugging</li> | |
| 155 <li><a href="tut_analytics.html">Google Analytics</a></li> | |
| 156 <li><a href="tut_oauth.html">OAuth</a></li> | |
| 157 </ul> | |
| 158 </li> | |
| 159 <li><h2>Reference</h2> | |
| 160 <ul> | |
| 161 <li>Formats | |
| 162 <ul> | |
| 163 <li><a href="manifest.html">Manifest Files</a></li> | |
| 164 <li><a href="match_patterns.html">Match Patterns</a></li> | |
| 165 </ul> | |
| 166 </li> | |
| 167 <li><a href="permission_warnings.html">Permission Warnings</a></li
> | |
| 168 <li><a href="api_index.html">chrome.* APIs</a></li> | |
| 169 <li><a href="api_other.html">Other APIs</a></li> | |
| 170 </ul> | |
| 171 </li> | |
| 172 <li><h2><a href="samples.html">Samples</a></h2></li> | |
| 173 <div class="line"> </div> | |
| 174 <li><h2>More</h2> | |
| 175 <ul> | |
| 176 <li><a href="http://code.google.com/chrome/webstore/docs/index.htm
l">Chrome Web Store</a></li> | |
| 177 <li><a href="http://code.google.com/chrome/apps/docs/developers_gu
ide.html">Hosted Apps</a></li> | |
| 178 <li><a href="themes.html">Themes</a></li> | |
| 179 </ul> | |
| 180 </li> | |
| 181 </ul> | |
| 182 </div> | |
| 183 <script> | |
| 184 initToggles(); | |
| 185 </script> | |
| 186 <div class="g-unit" id="gc-pagecontent"> | |
| 187 <div id="pageTitle"> | |
| 188 <h1 class="page_title">Tutorial: Debugging</h1> | |
| 189 </div> | |
| 190 <!-- TABLE OF CONTENTS --> | |
| 191 <div id="toc"> | |
| 192 <h2>Contents</h2> | |
| 193 <ol> | |
| 194 <li> | |
| 195 <a href="#extension-info"> View extension information </a> | |
| 196 <ol> | |
| 197 </ol> | |
| 198 </li><li> | |
| 199 <a href="#inspect-popup"> Inspect the popup </a> | |
| 200 <ol> | |
| 201 </ol> | |
| 202 </li><li> | |
| 203 <a href="#debug"> Use the debugger </a> | |
| 204 <ol> | |
| 205 </ol> | |
| 206 </li><li> | |
| 207 <a href="#summary">Summary</a> | |
| 208 <ol> | |
| 209 </ol> | |
| 210 </li><li> | |
| 211 <a href="#next">Now what?</a> | |
| 212 <ol> | |
| 213 </ol> | |
| 214 </li> | |
| 215 </ol> | |
| 216 </div> | |
| 217 <!-- /TABLE OF CONTENTS --> | |
| 218 <!-- Standard content lead-in for experimental API pages --> | |
| 219 <!-- STATIC CONTENT PLACEHOLDER --> | |
| 220 <div id="static"><div id="pageData-name" class="pageData">Tutorial: Debu
gging</div> | |
| 221 <div id="pageData-showTOC" class="pageData">true</div> | |
| 222 <p> | |
| 223 This tutorial introduces you to using | |
| 224 Google Chrome's built-in Developer Tools | |
| 225 to interactively debug an extension. | |
| 226 </p> | |
| 227 <h2 id="extension-info"> View extension information </h2> | |
| 228 <p> | |
| 229 To follow this tutorial, you need | |
| 230 the Hello World extension that was featured in | |
| 231 <a href="getstarted.html">Getting Started</a>. | |
| 232 In this section, | |
| 233 you'll load the extension | |
| 234 and take a look at its information | |
| 235 in the Extensions page. | |
| 236 </p> | |
| 237 <ol> | |
| 238 <li> | |
| 239 <p> | |
| 240 Load the Hello World extension if it isn't already running. | |
| 241 If the extension is running, | |
| 242 you'll see the Hello World icon | |
| 243 <img src="examples/tutorials/getstarted/icon.png" width="19" height="19" a
lt="" style="margin:0"> | |
| 244 to the right of | |
| 245 your browser's address bar. | |
| 246 </p> | |
| 247 <p> | |
| 248 If the Hello World extension isn't already running, | |
| 249 find the extension files and load them. | |
| 250 If you don't have a handy copy of the files, | |
| 251 extract them from this | |
| 252 <a href="examples/tutorials/getstarted.zip">ZIP file</a>. | |
| 253 See Getting Started if you need | |
| 254 <a href="getstarted.html#load-ext">instructions | |
| 255 for loading the extension</a>. | |
| 256 </p> | |
| 257 </li> | |
| 258 <li> | |
| 259 Go to the Extensions page | |
| 260 (<b>chrome://extensions</b>), | |
| 261 and make sure the page is in Developer mode. | |
| 262 </li> | |
| 263 <li> | |
| 264 Look at the Hello World extension's information on that page. | |
| 265 You can see details such as the extension's | |
| 266 name, description, and ID. | |
| 267 </li> | |
| 268 </ol> | |
| 269 <h2 id="inspect-popup"> Inspect the popup </h2> | |
| 270 <p> | |
| 271 As long as your browser is in Developer mode, it's easy to inspect popups. | |
| 272 </p> | |
| 273 <ol> | |
| 274 <li> | |
| 275 Go to the Extensions page (<b>chrome://extensions</b>), and make sure Develope
r | |
| 276 mode is still enabled. The Extensions page doesn't need to be open | |
| 277 for the following to work. The browser remembers the setting, | |
| 278 even when the page isn't shown. | |
| 279 </li> | |
| 280 <li> | |
| 281 Right-click the Hello World icon | |
| 282 <img src="examples/tutorials/getstarted/icon.png" width="19" height="19" alt="
" style="margin:0"> | |
| 283 and choose the <b>Inspect popup</b> menu item. The popup appears, | |
| 284 and a Developer Tools window like the following should display the code | |
| 285 for <b>popup.html</b>. | |
| 286 <p> | |
| 287 <img src="images/devtools-1.gif" alt="" width="500" height="294"> | |
| 288 </p> | |
| 289 The popup remains open as long as the Developer Tools window does. | |
| 290 </li> | |
| 291 <li> | |
| 292 If the <strong>Scripts</strong> button isn't already selected, | |
| 293 click it. | |
| 294 <!-- [PENDING: can we omit this step?] --> | |
| 295 </li> | |
| 296 <li> | |
| 297 Click the console button | |
| 298 <img src="images/console-button.gif" style="margin:0; padding:0" align="absmid
dle" width="26" height="22" alt="">(second | |
| 299 from left, | |
| 300 at the bottom of the Developer Tools window) | |
| 301 so that you can see both the code and the console. | |
| 302 </li> | |
| 303 </ol> | |
| 304 <h2 id="debug"> Use the debugger </h2> | |
| 305 <p> | |
| 306 In this section, | |
| 307 you'll follow the execution of the popup page | |
| 308 as it adds images to itself. | |
| 309 </p> | |
| 310 <ol> | |
| 311 <li> | |
| 312 Set a breakpoint inside the image-adding loop | |
| 313 by searching for the string <b>img.src</b> | |
| 314 and clicking the number of the line where it occurs | |
| 315 (for example, <strong>37</strong>): | |
| 316 <p> | |
| 317 <img src="images/devtools-2.gif" alt="" width="500" height="294"> | |
| 318 </p> | |
| 319 </li> | |
| 320 <li> | |
| 321 Make sure you can see the <b>popup.html</b> tab. | |
| 322 It should show 20 "hello world" images. | |
| 323 </li> | |
| 324 <li> | |
| 325 At the console prompt, reload the popup page | |
| 326 by entering <b>location.reload(true)</b>: | |
| 327 <pre>> <b>location.reload(true)</b> | |
| 328 </pre> | |
| 329 <p> | |
| 330 The popup page goes blank as it begins to reload, | |
| 331 and its execution stops at line 37. | |
| 332 </p> | |
| 333 </li> | |
| 334 <li> | |
| 335 In the upper right part of the tools window, | |
| 336 you should see the local scope variables. | |
| 337 This section shows the current values of all variables in the current scope. | |
| 338 For example, in the following screenshot | |
| 339 the value of <code>i</code> is 0, and | |
| 340 <code>photos</code> is a node list | |
| 341 that contains at least a few elements. | |
| 342 (In fact, it contains 20 elements at indexes 0 through 19, | |
| 343 each one representing a photo.) | |
| 344 <p> | |
| 345 <img src="images/devtools-localvars.gif" alt="" width="225" height="215"> | |
| 346 </p> | |
| 347 </li> | |
| 348 <li> | |
| 349 Click the play/pause button | |
| 350 <img src="images/play-button.gif" style="margin:0; padding:0" align="absmiddle
" width="22" height="20" alt="">(near | |
| 351 the top right of the Developer Tools window) | |
| 352 to go through the image-processing loop a single time. | |
| 353 Each time you click that button, | |
| 354 the value of <code>i</code> increments and | |
| 355 another icon appears in the popup page. | |
| 356 For example, when <code>i</code> is 10, | |
| 357 the popup page looks something like this: | |
| 358 </li> | |
| 359 <p> | |
| 360 <img src="images/devtools-3.gif" width="500" height="245" alt="the popup page
with 10 images"> | |
| 361 </p> | |
| 362 <li> | |
| 363 Use the buttons next to the play/pause button | |
| 364 to step over, into, and out of function calls. | |
| 365 To let the page finish loading, | |
| 366 click line <b>37</b> to disable the breakpoint, | |
| 367 and then press play/pause | |
| 368 <img src="images/play-button.gif" style="margin:0; padding:0" align="absmiddle
" width="22" height="20" alt="">to | |
| 369 continue execution. | |
| 370 </li> | |
| 371 </ol> | |
| 372 <h2 id="summary">Summary</h2> | |
| 373 <p> | |
| 374 This tutorial demonstrated some techniques you can use | |
| 375 to debug your extensions: | |
| 376 </p> | |
| 377 <ul> | |
| 378 <li> | |
| 379 Find your extension's ID and links to its pages in | |
| 380 the <b>Extensions</b> page | |
| 381 (<b>chrome://extensions</b>). | |
| 382 </li> | |
| 383 <li> | |
| 384 View hard-to-reach pages | |
| 385 (and any other file in your extension) using | |
| 386 <b>chrome-extension://</b><em>extensionId</em><b>/</b><em>filename</em>. | |
| 387 </li> | |
| 388 <li> | |
| 389 Use Developer Tools to inspect | |
| 390 and step through a page's JavaScript code. | |
| 391 </li> | |
| 392 <li> | |
| 393 Reload the currently inspected page from the console | |
| 394 using <b>location.reload(true)</b>. | |
| 395 </li> | |
| 396 </ul> | |
| 397 <h2 id="next">Now what?</h2> | |
| 398 <p> | |
| 399 Now that you've been introduced to debugging, | |
| 400 here are suggestions for what to do next: | |
| 401 </p> | |
| 402 <ul> | |
| 403 <li> | |
| 404 Watch the extensions video | |
| 405 <a href="http://www.youtube.com/watch?v=IP0nMv_NI1s&feature=PlayList&
;p=CA101D6A85FE9D4B&index=5">Developing and Debugging</a>. | |
| 406 </li> | |
| 407 <li> | |
| 408 Try installing and inspecting other extensions, | |
| 409 such as the | |
| 410 <a href="samples.html">samples</a>. | |
| 411 </li> | |
| 412 <li> | |
| 413 Try using widely available debugging APIs such as | |
| 414 <code>console.log()</code> and <code>console.error()</code> | |
| 415 in your extension's JavaScript code. | |
| 416 Example: <code>console.log("Hello, world!")</code> | |
| 417 </li> | |
| 418 <li> | |
| 419 Follow the <a href="http://www.chromium.org/devtools/google-chrome-developer
-tools-tutorial">Developer Tools tutorial</a>, | |
| 420 explore the | |
| 421 <a href="http://www.chromium.org/devtools">Developer Tools site</a>, | |
| 422 and watch some video tutorials. | |
| 423 </li> | |
| 424 </ul> | |
| 425 <!-- [PENDING: do something to help people debug content scripts, which show up
in blue] --> | |
| 426 <p> | |
| 427 For more ideas, | |
| 428 see the <a href="getstarted.html#summary">Now what?</a> section | |
| 429 of Getting Started. | |
| 430 </p> | |
| 431 </div> | |
| 432 <!-- API PAGE --> | |
| 433 <!-- /apiPage --> | |
| 434 </div> <!-- /gc-pagecontent --> | |
| 435 </div> <!-- /g-section --> | |
| 436 </div> <!-- /codesiteContent --> | |
| 437 <div id="gc-footer" --=""> | |
| 438 <div class="text"> | |
| 439 <p> | |
| 440 Except as otherwise <a href="http://code.google.com/policies.html#restrictions
">noted</a>, | |
| 441 the content of this page is licensed under the <a rel="license" href="http://c
reativecommons.org/licenses/by/3.0/">Creative Commons | |
| 442 Attribution 3.0 License</a>, and code samples are licensed under the | |
| 443 <a rel="license" href="http://code.google.com/google_bsd_license.html">BSD Lic
ense</a>. | |
| 444 </p> | |
| 445 <p> | |
| 446 ©2011 Google | |
| 447 </p> | |
| 448 <!-- begin analytics --> | |
| 449 <script src="https://www.google-analytics.com/urchin.js" type="text/javascript">
</script> | |
| 450 <script src="https://www.google-analytics.com/ga.js" type="text/javascript"></sc
ript> | |
| 451 <script type="text/javascript"> | |
| 452 // chrome doc tracking | |
| 453 try { | |
| 454 var engdocs = _gat._getTracker("YT-10763712-2"); | |
| 455 engdocs._trackPageview(); | |
| 456 } catch(err) {} | |
| 457 // code.google.com site-wide tracking | |
| 458 try { | |
| 459 _uacct="UA-18071-1"; | |
| 460 _uanchor=1; | |
| 461 _uff=0; | |
| 462 urchinTracker(); | |
| 463 } | |
| 464 catch(e) {/* urchinTracker not available. */} | |
| 465 </script> | |
| 466 <!-- end analytics --> | |
| 467 </div> | |
| 468 </div> <!-- /gc-footer --> | |
| 469 </div> <!-- /gc-container --> | |
| 470 </body></html> | |
| OLD | NEW |