Chrome javascript debugger breakpoints don't do anything?

前端 未结 21 996
时光说笑
时光说笑 2020-12-02 18:14

I can\'t seem to figure out the Chrome debugging tool.

I have chrome version 21.0.1180.60 m.

Steps I took:

  1. I pressed ctrl-shift-i to bring up t
相关标签:
21条回答
  • 2020-12-02 18:39

    Make sure that you're using the same host in the URL that you were when you set up the mapping. E.g. if you were at http://127.0.0.1/my-app when you set up and mapped the workspace then breakpoints won't work if you view the page via http://localhost/my-app. Also, thanks for reading this far. See my answer to the Chromium issue here.

    0 讨论(0)
  • 2020-12-02 18:42

    This may be a Chrome bug. Unfortunately Chrome routinely breaks debugging. It often has some kind of memory leak and it often breaks or changes every few releases.

    Debugging with formatted sources is currently extremely unreliable.

    It's possible you're also trying to break on dead code.

    To be certain it's not the browser you should also try to debug it in firefox.

    0 讨论(0)
  • 2020-12-02 18:44

    I met this several times, at first it works well by localhost, suddenly, the breakpoints don't work, i switch to 127.0.0.1, then it works again. Hope helps.

    0 讨论(0)
  • 2020-12-02 18:45

    I'm not sure why your breakpoints aren't hitting, but one sure-fire way to step into your code is to type

    debugger;
    

    where you want the code to halt, and then run again with the chrome developer tools window open.


    Just one small thing to be aware of, be sure to clean up after you done and remove the debugger lines. If you ever run JavaScript files through YUI compressor, the existence of a debugger; line will cause it to error out.

    0 讨论(0)
  • 2020-12-02 18:45

    This is a late answer, but I had the same problem, but the answer was different.

    In my case, there was a sourceURL reference in my code:

    //@ sourceURL=/Scripts/test.js
    

    When this Javascript file is minified and loaded by the browser, it normally tells Chrome Dev Tools where the unminified version is.

    However, if you are debugging the unminified version and this line exists, Chrome Dev Tools maps to that sourceURL path instead of the "normal" path.

    For example, if you work locally on a web server, then in the Sources tab in Chrome Dev Tools, the path to a given JS file will be http://localhost/Scripts/test.js

    If test.js has this at the bottom

    //@ sourceURL=/Scripts/test.js
    

    then breakpoints will only work if the file path is /Scripts/test.js, not the fully-qualified URL of http://localhost/Scripts/test.js

    In Chrome 38, staying with my example above, if you look at the Sources tab, every file runs off http://localhost/, so when you click on test.js, Chrome loads up http://localhost/Scripts/test.js

    You can put all the breakpoints you want in this file, and Chrome never hits any of them. If you put a breakpoint in your JS before it calls any function in test.js and then step into that function, you will see that Chrome opens a new tab whose path is /Scripts/test.js. Putting breakpoints in this file will stop the program flow.

    When I got rid of the @ sourceURL line from the JS file, everything works normally again (i.e. the way you would expect).

    0 讨论(0)
  • 2020-12-02 18:45

    I had a minifier that was stripping out debugger statements ¯_(ツ)_/¯

    0 讨论(0)
提交回复
热议问题