Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wasm/dotnet Integrity attribute invalid for my Blazor app on Github pages

See the error on my website here

I have embedded a blazor app in my jekyll site. It runs perfectly locally, but when I publish it on github pages, I am getting this error:

Failed to find a valid digest in the 'integrity' attribute for resource 'https://chrisevans9629.github.io/blazor/xt/_framework/wasm/dotnet.3.2.0-rc1.20222.2.js' with computed SHA-256 integrity 'yVt8FYsTQDifOGsifIkmEXwe+7ML0jZ1dMi2xluiDXQ='. The resource has been blocked.

This is something that I think blazor generates when the page is ran. this is what my page looks like that starts blazor:

<script src="js/index.js"></script>
<app>Loading...</app>
Built with <3 using Blazor
<script src="_framework/blazor.webassembly.js"></script>

This is what the page looks like on github pages:


<script src="js/index.js"></script>

<app>Loading...</app>
<p>Built with &lt;3 using Blazor
<script src="_framework/blazor.webassembly.js"></script></p>        

<script type="text/javascript">var Module; window.__wasmmodulecallback__(); delete window.__wasmmodulecallback__;</script><script src="_framework/wasm/dotnet.3.2.0-rc1.20222.2.js" defer="" integrity="sha256-iZCHkFXJWYNxCUFwhj+4oqR4fkEJc5YGjfTTvdIuX84=" crossorigin="anonymous"></script></body>

Why is this error happening and how can I fix this? I've thought about create a script that would remove the integrity attribute, but I don't think that would be a good solution.

like image 677
Chris Evans Avatar asked May 02 '20 16:05

Chris Evans


People also ask

How do you run Blazor Wasm app?

Open Visual Studio and select Create a new project. Select the Blazor WebAssembly App project type, enter a name for your project, and then click Next. Select the ASP.NET Core hosted checkbox and the desired framework, and then click Create.

What is Wasm in Blazor?

Blazor WASM (or Blazor WebAssembly) is a single-page web application framework built by Microsoft that allows you to build single-page web applications. Built as part of the . NET Core ecosystem, Blazor uses C# to generate dynamic content for a rich client experience.

Does Blazor compile to WebAssembly?

Blazor WebAssembly supports ahead-of-time (AOT) compilation, where you can compile your . NET code directly into WebAssembly. AOT compilation results in runtime performance improvements at the expense of a larger app size.

Is Blazor Wasm a spa?

Blazor WebAssembly is a single-page app (SPA) framework for building interactive client-side web apps with . NET.


1 Answers

I found an answer here

Cause

Because I am using github pages to host my blazor app, it's using git to push up the code. Git by default will try to normalize line endings when committing code, which was causing the integrity of the blazor app to fail due to the files changing.

Solution

To fix this, I added a .gitattributes file to my blazor folder with * binary as the contents.

This tells git to treat all files as binary and therefore not to normalize the line endings. After I did that, I had to delete my _framework folder in my blazor app and rebuild it. After doing this, the blazor app worked.

like image 105
Chris Evans Avatar answered Sep 20 '22 03:09

Chris Evans