Skip to content

Conversation

@pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Oct 11, 2021

The aspnet-browser-refresh.js script is injected in to documents that appear to destined to be displayed in the browser. As part of dotnet/aspnetcore#37326, we realized the script was being added to an iframe that appears in the background. (We only found this because the particular page being served uses CSP that is designed to prevent modifications). Even if amending the script had succeeded in this case, VS which uses this code currently does not support having multiple instances of the script calling back.

The fix is to avoid injecting the scripts in responses that are clearly not destined for a visible browser document.

Partly fixes dotnet/aspnetcore#37326

Customer impact

Warnings in the browser console when running F5 / Ctrl-F5 on a React or Angular project template

Testing

  • Added unit tests
  • Verified the E2E manually

Risk

Low

@ghost ghost added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Oct 11, 2021
@pranavkm pranavkm requested a review from a team October 11, 2021 20:20

if (request.Headers.TryGetValue("Sec-Fetch-Dest", out var values) &&
!StringValues.IsNullOrEmpty(values) &&
!string.Equals(values[0], "document", StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec doesn't talk about any other casing than document so strictly speaking I think this could be StringComparison.Ordinal. However I can't think of any real drawback to doing a case-insensitive check.

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Do you know if there's a specific plan to fix this for browser link too? That's equally problematic.

@pranavkm
Copy link
Contributor Author

I'll file a VS issue and follow up with @jodavis about getting it resolved there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch Servicing-approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants