I have lot of my JS
files in my projects. Some of them are external libraries. I want to know what JS
code is executing for current user interaction. I have set up break point in chrome as describe here. But there are already lots of JS
files and lots are added by Visual Studio
of his own. So it becomes difficult for me to get to exact code. So in this case, I need something that will enable me to debug only xyz.js
file.
Try this: go to File->New->Project... and pick a win32 console application. In the next wizard, go to Application Settings , and check "Empty Project", and hit OK. Now you have empty project and solution files which you can copy/paste wherever you want them; to debug, just open the . sln file, drag in your single .
In the debugger window, you can set breakpoints in the JavaScript code. At each breakpoint, JavaScript will stop executing, and let you examine JavaScript values. After examining values, you can resume the execution of code (typically with a play button).
To avoid multiple server requests, group your JavaScript files into one. Whatever you use for performance, try to minify JavaScript to improve the load time of the web page. If you are using single page application, then group all the scripts in a single file.
Based on adamtickner's explanation here is a detailed description. Let's assume the file you want to debug is "src/app.js"
In Chrome open the debugger using F12 and then click settings (gear icon ⚙ , top right window corner). Select the "Ignore List" menu item.
So far so easy. The tricky part is to add the right regular expression. We need an expression saying "everything, except...". This can be done by a technique called "negative look-arounds"
Our positive expression would be:
src\/app\.js
We just escaped the slash and the dot as these are reserved regex characters.
Now, using negative look-arounds, our expression should look like this:
^((?!src\/app\.js).)*$
This expression will find anything which does NOT contain our file path. You can test it with regex101. Add this pattern to your Ignore List and you are done! Chrome will maybe show a misleading message when you debug in this file like "This script is on the debugger's ignore list" - just ignore this message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With