Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically loaded javascript doesn't show in sources panel?

For example, I have an ajax request and it returns <script src='buggy.js'></script>.

Problem is, it doesn't show up in sources or resources panel. That means I can't do all the cool stuffs like adding breakpoint and inspecting the elements as they run.

I could only see the source of the js file under the Network panel.

Is there anyway to make chrome add them to the sources panel?
Or how do you guys go about debugging dynamically added scripts?

Using Canary.

like image 881
resting Avatar asked Dec 21 '12 06:12

resting


1 Answers

I was having the same problem, and I found a workaround that is better than the deliberate exception. It does still require changing the code as opposed to just setting a breakpoint inside the chrome dev tools.

I tried using the "//# sourceURL=dynamicScript.js" that was suggested as a workaround by the OP, but it still wasn't showing up for me unless it already existed in my tabs from a previous time when it produced an exception.

Coding a "debugger;" line forced it to break at that location. Then once it was in my tabs in the Sources panel, I could set breakpoints like normal and remove the "debugger;" line.

like image 156
kevinpo Avatar answered Oct 16 '22 15:10

kevinpo