15

I recently upgraded from VS 2017 to VS 2019.

In VS 2017, when running an asp.net application locally, using Chrome, I could put a breakpoint in javascript code and the debugger would stop on the breakpoint. This no longer works in Visual Studio 2019.

What do I need to do to enable javascript debugging in Visual Studio 2019 using Chrome? I would like to be able to put breakpoints in javascript files and have them hit.

Here is my setup.

  1. I've enabled Javascript debugging. enter image description here

  2. I put a breakpoint in my Javscript code. This breakpoint is in a *.js file (not inside a Razor view).

enter image description here

  1. The breakpoint is ignored. Visual Studio very courteously shows me a tooltip telling me the breakpoint will be ignored.

enter image description here

Mosè Raguzzini
  • 15,399
  • 1
  • 31
  • 43
Tom Regan
  • 3,580
  • 4
  • 42
  • 71
  • 1
    I guess it will work if you use chrome or internet explorer – TAHA SULTAN TEMURI Nov 01 '19 at 13:56
  • 3
    @TAHASULTANTEMURI it is not working, that is the problem. I'm using Chrome (I have to use Chrome). – Tom Regan Nov 01 '19 at 14:10
  • 1
    The solution for me was: https://stackoverflow.com/questions/71697532/visual-studio-2022-javascript-debugging-not-working-with-edge-browser/74474717#74474717 – Cilesizzz Nov 17 '22 at 12:02
  • Double check your code - my solution was the js code was not compiling correctly / being included correctly. To be clear .js files CAN be debugged but they have to be found and compiled. – Rob Mar 28 '23 at 21:12

6 Answers6

2

It should work in VS2019+Chrome.(I just checked this in several machines)

This is not one issue can be resolved directly since many factors can cause this behavior, you can follow suggestions below to check if it helps:

1.Update your VS2019 to latest 16.3.7, update your chrome browser to latest 78.0.3904.87

2.Delete the bin and obj folders in your project directory => then close and restart VS => open that project and do a clean rebuild

3.Make sure you're in debug project mode, right-click your web project=>Set as StartUp project

Also, sometimes we need to wait for several seconds before the debug session starts successfully.(I once met same popup, then after several seconds it disappeared and everything worked)

Hope it helps :)

Sylvain Rodrigue
  • 4,751
  • 5
  • 53
  • 67
LoLance
  • 25,666
  • 1
  • 39
  • 73
  • 1
    None of the suggestions above seem to work for me. VS is v16.6.4. Chrome is v84. "Enable JavaScript debugging for ASP.NET" is checked. My JS is in CSHTML files. I get a similar message in VS: "The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line." Have tried deleting _bin_ and _obj_ folders. Also is the correct Startup Project. Anyone have success with this? – Cardi DeMonaco Jr Aug 12 '20 at 15:37
  • And when the JS code is in a JS file, the debug point stays the normal red (with no warning message), but is never hit. Even with a simple alert("Hello, world!"), I see the alert, but the breakpoint is not hit. – Cardi DeMonaco Jr Aug 12 '20 at 15:41
  • So, Edge seems to work just fine, but not Chrome. So I guess Edge it is when JS debugging is necessary. – Cardi DeMonaco Jr Aug 12 '20 at 16:14
  • 2
    Cardi DeMonaco, I found that when the breakpoint is being ignored in a .js file I must close VS, delete the bin and obj folders for the solution, reopen the solution and rebuild all, then start the debugger, revisit the page in question and do a Ctrl-F5 to reload the javascript. When I go through those steps it usually starts finding the breakpoint again. I don't know about putting break points in cshtml files though. – Tom Regan Aug 12 '20 at 17:37
  • 1
    @CardiDeMonacoJr - Edge has the same problem for me with a slightly different message. Instead of "Breakpoint set but not yet bound" it just says "Unbound breakpoint" – Kyle Delaney Nov 07 '20 at 00:11
  • Nothing has worked for me so far. Using Internet Explorer as well as Chrome with ASP.NET Website and VS 2019. https://stackoverflow.com/questions/66609043/debug-javascript-files-associated-with-the-respected-ascx-in-vs-2017-2019 Pls help. – tRuEsAtM Mar 14 '21 at 16:39
  • A half-baked VS version is on the pipe line at the moment, there seems to be no fix to this thing yet. Very disappointed again with Microsoft Visual Studio. I tried everything suggested but nothing works, no hope on this one yet. – allan Sep 16 '21 at 00:41
1

Besides enabling JavaScript debugging in Visual Studio, please ensure that minification is off. (Turn off bundling/minification while debugging in WebForms)

  • If using .Net Core with Ligershark WebOptimizer you need to turn off minification in dev mode in startup.cs. e.g. `services.AddWebOptimizer(minifyJavaScript: false, minifyCss: false);` – Norbert Norbertson Jan 18 '22 at 13:43
1

If your page contains Razor syntax, the breakpoints won't work.

Instead add the debugger; statement into the script as a breakpoint.

Then again, the debugger statement had failed to work earlier this year. It only works at top level, means before the page is completely rendered. It will not work if I put the debugger statement into $(document).ready()

So my work around now is to put my javascript in a separate .js file without any Razor syntax.

s k
  • 4,342
  • 3
  • 42
  • 61
1

The good old console.log works for me as nothing suggested as above answers are working at all. Anyway it is what it is amidst the frustration for VS, nothing new about that.

allan
  • 131
  • 10
1

If your Javascript is in a Razor file it will not work.

I have been struggling with this for ages and getting by with console.log. But just now I moved the js into an external file and bingo it works.

I am using latest VS 16.11.5 and Chrome in a .Net 5 project with Razor pages.

Norbert Norbertson
  • 2,102
  • 1
  • 16
  • 28
  • I noticed in my original post that my javascript is in a *.js file, not in a Razor view, and yet the problem still occurred. – Tom Regan Nov 01 '21 at 18:02
0

I have noticed that if I open a URL from within Javascript in the following manner:

window.open("url");

It opens in a new tab and no breakpoints will be hit in the javascript that loads for the new browser window. Nor will "debugger" work. However, if you do NOT open in a new tab, but use:

window.open("url", "_self");

It opens in the same window, and breakpoints will work. Something about the execution context of the browser in a new tab I think. I hope this helps.

Evan
  • 457
  • 4
  • 14