This tutorial shows you how to use Google Chrome's built-in developer tools to view your extension's code, display debugging output, and interactively debug your extension.
[PENDING: Rewrite this when we update the example.]
To follow this tutorial, you use a modified version of the Hello World extension that was featured in Getting Started.
Find your copy of the Hello World extension's files. If you don't have a handy copy, extract them from this ZIP file.
Edit my_toolstrip.html
so that it has the following code:
<script> function helloWorld() { var hwFile = 'hello_world.html'; console.log("in helloWorld()"); window.open(hwFile); } </script> <div class="toolstrip-button" onclick="helloWorld();"> <span>Hello, World!</span> </div>
The revised code has the same effect
but now has some debugging output,
thanks to the call to console.log()
.
Note: If you have multiple browser windows open, you'll see multiple copies of my_toolstrip.html in chrome://extensions. Each copy corresponds to a window — or, more precisely, to an instance of the toolstrip.
window.open()
statement
by clicking 5 in the left column:
console.log()
along with the line number,
and execution should stop just before
the call to window.open()
.
The Call Stack area at the right of the tools window shows that
the helloWorld()
method was called by an anonymous function
that was called by onclick
.
Anywhere in the Call Stack or console that you see a file and line number
(for example, "my_toolstrip.html:4"),
you can click that text to see the relevant line of code.
hwFile
is a local variable
that has the value "hello_world.html".
window.open()
returns,
the main browser window should open a new tab
that displays the contents of hello_world.html
.Now that you've been introduced to debugging, here are suggestions for what to do next:
For more ideas, see the Now what? section of Getting Started.