How to stop browserlink.js and aspnet-core-browser-refresh
Asked Answered
M

3

7

Why do I have all this junk in my console, only when using VS 2022?

enter image description here

I set Options -> Projects and Solutions -> ASP.NET Core -> Auto build and refresh options -> NONE

And also disabled 'browser link' here:

enter image description here

None of that stuff appears when running the same project in VS 2019, and I'm pretty sure its messing with my SignalR connections

Mainland answered 18/11, 2021 at 18:47 Comment(0)
J
10

Per https://developercommunity.visualstudio.com/t/Browser-Link-cannot-be-disabled/1582653#T-N1608441, adding "hotReloadEnabled": false to your launchSettings.json profile(s) should suppress the injection of these scripts by Visual Studio. This does not actually turn off C# hot reloading - just turns off the scripts that MSFT injects.

Jocular answered 1/8, 2022 at 22:32 Comment(1)
Please up-vote this answer, as it is correct.Lemnos
C
4

For anyone using dotnet cli tool and want to disable the hot reload and console output whatever, and have no luck with dotnet watch --no-hot-reload, try put this at the very start of your js script:

function removeDotnetHotReload() {
    const scriptInjectedSentinel = '_dotnet_watch_ws_injected'
    // @ts-ignore
    window[scriptInjectedSentinel] = true
}

removeDotnetHotReload()
Cordovan answered 18/2, 2022 at 3:27 Comment(0)
S
1

For aspnet-core-browser-refresh, can you please file an issue at https://github.com/dotnet/sdk, as that's where that code lives?

For Browser Link, I can tell you that right now there's no way to disable those messages in a .NET 6 app without turning off CSS Hot Reload as well (you can turn verbose messages off in the console so they won't show, but they'll still be emitted). If you are ok turning off CSS Hot Reload, you can do that in Tools->Options->Projects and Solutions->ASP.NET Core. Please file feedback at Developer Community about this as well so we can potentially make this more discoverable.

That said, I'm curious why you think this might be interfering with your SignalR connections. If there is interference there, we definitely want to address that as well, but I'm not sure off the top of my head why that would be.

Suu answered 15/1, 2022 at 23:2 Comment(2)
I was concerned about SignalR too. (First of all I use Angular and any refreshing is through Webpack mechanisms so I just wanted all this .NET refreshing disabled.) The reason was it would just completely lock up for no reason as if it was waiting on a resource. I keep several windows open to the same site so connections quickly add up. I just wanted to turn all this off to reduce every possible resource. I really wish VS.NET wouldn't make some of these global settings becasue if I had a second pure .NET project I would want it enabled.Trichinize
Also see here for other options to disable hot refresh - and see my note about a bug in the Options panel not remembering changed checkboxes, otherwise it may not actually be off! https://mcmap.net/q/368606/-how-to-disable-browser-link-in-asp-net-core-net-6-vs-2022. After doing this there was no injected code when I did view source anymore.Trichinize

© 2022 - 2024 — McMap. All rights reserved.