0

I am developing a mobile app using jQuery, jQuery mobile (and PhoneGap, but that is not relevant). Let's say I have two html pages: page1.html and page2.html. I am loading page2.html using $.mobile.changePage() from page1.html. The page div in page2.html (i.e., the div having data-role="page") contains javascript code that is specific to page2, which also gets loaded with page2.html. The code in page2.html looks something like this:

<!DOCTYPE HTML>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div id="conf-page" data-role="page">

    <script type="text/javascript" charset="utf-8">

    <!-- MY SCRIPT HERE ----->

    </script>
    <div data-role="header" style="height: 45px">

Now I want to break somewhere in the javascript code in page2.html. For the time being, I am using Firefox (16.0.2) and Firebug to develop and debug. When page2.html is loaded, I see the JS code of page2.html at two places in firebug Scripts list:

  1. At jQuery.min.js/eval/MD5/
  2. At jQuery.min.js/eval/seq/<#>

If I put a breakpoint somewhere in one of the codes, it get applied to the code in (1) above, but it is never hit when page2.html is loaded.

How to go about setting a breakpoint and breaking somewhere in the JS code in page2.html? I couldn't find anything relevant on the web, which makes me think that I must be missing something, as this must be a pretty common requirement.

Samik R
  • 1,636
  • 3
  • 15
  • 33
  • Not quite sure what you mean by ***break** somewhere in the javascript*. If you add a `console.log('Hello');` as the first line in the `script`, is it being triggered i.e. does it show in the Firebug console? – Coby Nov 10 '12 at 23:58
  • Yes, console log messages like the one you mention are being shown, but I cannot put a breakpoint on that line and make the execution break there. That is what I want to do. – Samik R Nov 11 '12 at 04:47
  • What is the purpose of adding a breakpoint? It may be a Firebug limitation. Try adding the breakpoint via Google Chrome. – Coby Nov 11 '12 at 04:51
  • It's hard to help you when you haven't posted any code. We don't know what you're trying to set a breakpoint on. For what it's worth, I've had trouble setting breakpoints on anonymous functions before. – Brad Nov 11 '12 at 05:04

1 Answers1

0

Looks like I was searching for different terms. There has been some discussions on this problem in this site. Here are a few references:

There are two solutions suggested in the above threads:

  • Most of these threads suggest the same solution: use the "debugger;" statement (w/o the quotes) twice in the code for the FireBug debugger to stop. I did that, and it was a partial solution: the firebug did break, but the variable stack was empty. So this wasn't very useful.
  • Put the script in a file, use an AJAX Get call to load the script with crossdomain set to true, and that gets the script file, loads it and the script file shows in debugger. That can be used now to set breakpoints etc. More useful than above.

Keeping open to see if there are other solutions.

Community
  • 1
  • 1
Samik R
  • 1,636
  • 3
  • 15
  • 33
  • I ended up using the second option above, with some caching so that I don't get a different JS file every time I reload the page. – Samik R Nov 28 '12 at 22:36