Skip to content

Refresh Browser After Build - iFrame and Content Security Policy Error #31320

Closed
@CannyGent

Description

@CannyGent

I have a .NET 5 Blazor application developed from the standard template using

  • WASM App
  • Hosted in ASP.NET Core
  • PWA
  • Individual User Accounts

I am running with Ctrl-F5 and Visual Studio configured to Refresh Browser After Build. When I look at the console in Chrome, I get the following error message:
Refused to load the script 'https://localhost:36001/_framework/aspnetcore-browser-refresh.js' because it violates the following Content Security Policy directive: "script-src 'sha256-fa5rxHhZ799izGRP38+h4ud5QXNT0SFaFlh4eqDumBI='". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

When I look at the source using the inspector I observe that an iFrame has been inserted:
<iframe src="https://localhost:36001/connect/checksession" style="visibility: hidden; position: absolute; display: none; width: 0px; height: 0px;"></iframe>

This iFrame includes <script src="/_framework/aspnetcore-browser-refresh.js"></script>

What is causing this behaviour? In other projects I just see that script being inserted, not the iFrame and the reload works fine. The reload in this case is not working due to the CSP but even that is confusing because the script does not have an integrity attribute.

This seems to be a defect in the logic for how the Refresh functionality is injected. Any help would be much appreciated.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-boot-upfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyfeature-hot-reloadThis issue is related to the Hot Reload feaaturefeature-pwaIssues related to building PWAs with Blazor

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions