views:

5318

answers:

4

This question has been asked similarly before (http://stackoverflow.com/questions/66420/how-do-you-launch-the-javascript-debugger-in-google-chrome), but I can't seem to debug Javascript in Google Chrome.

If I go to Page > Developer the "Debug Javascript" (Ctrl+Shift+L) is disabled. Alt + ` doesn't work.

I'm developing a 'content script' extension so I'm launching chrome with --enable-extensions.

What I'd ideally like to do is set breakpoints and step/run through my script as it executes. I'm a little over my head when it comes to JavaScript, so any guidance is appreciated.

I can get to the 'JavaScript Console,' but can't find the content scripts inside of that. I'm also not sure how that differs from the 'JavaScript Debugger.'

I'm using the latest Dev build of Chrome (2.0.181.1) on Windows XP.

+1  A: 

Right-click and select Inspect Element, there you'll find the JS debugger, among other debugging tools. The JS debugger should allow you to set breakpoints, etc.

Scott
Well, this is the JavaScript Console, not the debugger. There seems to be a difference. I'm likely being dense here, but I can't find a way to insert breakpoints into the script at this point.How do I see a content script function that I've added as an Event Listener to a particular object?e.g. I want to be able to debug 'myFuncHere()' in this.addEventListener('click', myFuncHere, true);
Clayton Hughes
If you click the "Scripts" button at the top of the Inspector window, that should be the debugger. You can select a particular script source from a drop down menu and then click on the line number to set a breakpoint.
Scott
Thanks for the tip, Scott, but I don't see any of my user scripts there, just the ones from the website proper. Am I missing something?
Clayton Hughes
I installed the sample GMail checker extension http://dev.chromium.org/developers/design-documents/extensions/samples and by right clicking on the installed button at the bottom was able to select 'Inspect Element" which brought up the inspector / debugger scoped to just the extension.
Scott
A: 

I'm a bit confused about this as well. On my home computer the "Scripts" button is there. On my work computer it is not. I'm not really sure what the difference is between the two installs. They're generally installed/updated at the same time (same day at least).

Is one of the machines on the Dev/Beta branch and one on the release branch? Check the "about google chrome" info on the little wrench icon menu.
EricLaw -MSFT-
A: 

What you have to do is enable your extension, then in Chrome click "Developer" -> "Javascript Console". Then click the "Scripts" tab. After that you should see a listing just below of all the loaded scripts. You will see scripts for the current page as well as all the scripts for any extensions you have installed. (If you don't see any scripts listed after opening the console, you may have to refresh)

It seems that all Chrome extensions get assigned a unique ID. You can find out your ID by viewing the Chrome Extensions page in Developer Mode.

Then it's just a matter of searching through the scripts in the dropdown for your script. Select your script and you can set breakpoints etc.

There's a lot more info on the Chrome Dev Tools here: http://www.chromium.org/devtools

sym3tri
A: 

Put the following command in your script:

debugger;

That will launch the Javascript debugger when it gets to that point

Rory