Are you talking about code within
<script> tags, or in the HTML tag attributes, like this?
<a href="#" onclick="alert('this is inline JS');return false;">Click</a>
Either way, the
debugger keyword like this will work:
<a href="#" onclick="debugger; alert('this is inline JS');return false;">Click</a>
N.B. Chrome won’t pause at
debuggers if the dev tools are not open.
You can also set property breakpoints in JS files and
- Click the Sources tab
- Click the Show Navigator icon and select the a file
- Double-click the a line number in the left-hand margin. A corresponding row is added to the Breakpoints panel (4).
You also can give a name to your script:
... (your code here)
ofcourse replace “somename” by some name 😉 and then you will see it in the chrome debugger at “Sources > top > (no domain) > somename.js” as a normal script and you will be able to debug it like other scripts
Refresh the page containing the script whilst the developer tools are open on the scripts tab. This will add a (program) entry in the file list which shows the html of the page including the script. From here you can add breakpoints.
Another intuitive simple trick to debug especially script inside html returned by ajax, is to temporary put console.log(“test”) inside the script.
Once you have fired the event, open up the console tab inside the developer tools.
you will see the source file link shown up at the right side of the “test” debug print statement. just click on the source (something like VM4xxx) and you can now set the break point.
P.S.: besides, you can consider to put “debugger” statement if you are using chrome, like what is being suggested by @Matt Ball
My situation and what I did to fix it:
Page Name: test.html
<script> document.write("something"); </script>
..and refreshed / reloaded the page, voila, it appeared in the drop down list, and all was well again.