Support disabling auto-injection of browser refresh JavaScript via launch profile property
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
As a result of the problems experienced by some customers in their ASP.NET Core apps when the browser refresh script is auto-injected, as detailed in #32767, I’m proposing that we add a new launch settings/profile property that can be used to disable the automatic injection of the browser refresh script.
The property would be named `disableBrowserRefreshScriptInjection` and would default to `false`. Setting this property to `true` in a launch profile in `launchSettings.json` would prevent `dotnet watch` and Visual Studio from injecting the middleware that writes out the browser refresh JavaScript to HTML responses from the app, e.g.:
```json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50226/",
"sslPort": 44355
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"disableBrowserRefreshScriptInjection": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"launchBrowser": true,
"disableBrowserRefreshScriptInjection": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:7089;http://localhost:5089"
}
}
}
```
Note that this setting should not disable any other part of the mechanism that enables browser refreshing on Hot Reload, project build, CSS file change, etc., so that the app can manually add the required JavaScript reference manually, e.g.
``` html
@* Render the browser reload script *@
@if (Environment.GetEnvironmentVariable("__ASPNETCORE_BROWSER_TOOLS") != null)
{
}
```
Contributor guide
Assessment
This issue has not been assessed yet.