Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug only one js file

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.

like image 877
Imad Avatar asked Apr 29 '16 12:04

Imad


People also ask

How do I debug a single file in Visual Studio?

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 .

How do I debug JavaScript script?

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).

Should all my JavaScript be in one file?

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.


1 Answers

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.

enter image description here

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.

like image 149
Gerfried Avatar answered Sep 22 '22 08:09

Gerfried