Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug javascript as a popup window loads?

Tags:

What is the most effective way to debug JavaScript code that runs in a popup window? Specifically I need to trace what is happening as the page loads.

This is for SCORM 1.2 courses running in an LMS, which depends on other JavaScript objects in a parent window, so debugging the popup by itself won't work.

I could use a technique for other contexts though most of my time is debugging these courses.

I could use something like an option in the in-browser debugger that pauses on the first line of JavaScript that executes for a popup page, as if I put a breakpoint there. (I can't, or at least don't know how, to set breakpoints until well after the page has started)

Edit:

The debugger; statement works, but only for code I control. I sometimes need to trace JavaScript that runs as some popup window opens, and can't add breakpoints because the code has already run.

like image 982
Dan Novak Avatar asked Oct 02 '12 18:10

Dan Novak


People also ask

Why is JavaScript so hard to debug?

What makes JavaScript great is also what makes it frustrating to debug. Its asynchronous nature makes it easy to manipulate the DOM in response to user events, but it also makes it difficult to locate problems.


1 Answers

You can put the magic

debugger;

statement anywhere into your javascript code (every debugger I know about will halt there by automatically setting a breakpoint at that line).

If that doesn't help either, I'd just "open that page in a new window / tab" and setting up breakpoints myself or also using debugger;

like image 57
jAndy Avatar answered Dec 04 '22 10:12

jAndy