Chrome JavaScript Debugging - how to save break points between page refresh or break via code?

前端 未结 8 750
情深已故
情深已故 2021-01-31 06:46

When using Chrome and it\'s JavaScript debugger, every time I reload my page / scripts, my breakpoints are lost and I have to go find the script file in the pop-up, find the lin

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 07:21

    This is probably happening for scripts that you're dynamically loading or evaluating from other scripts? I can say for myself that this scenario really irritated me until I discovered the sourceURL property. Placing the following specially formatted comment on the last line of the script you want to debug will 'anchor' it within Chrome so it has a frame of reference for it:

    //# sourceURL=filename.js

    Your manually-placed breakpoints will now persist between page loads! The convention actually originated from the sourcemap specification, but Chrome at least honors it as a standalone technique. Here's a reference.

提交回复
热议问题