Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSException: SharedArrayBuffer is not defined #9

Closed
nor0x opened this issue Mar 2, 2022 · 15 comments
Closed

JSException: SharedArrayBuffer is not defined #9

nor0x opened this issue Mar 2, 2022 · 15 comments
Assignees

Comments

@nor0x
Copy link

nor0x commented Mar 2, 2022

i'm not sure if it's somehow related with #6 but there i get the following error if i want to use FFmpegBlazor in my WebAssembly project. I noticed that there is a JSException on the hosted version on netlify as well.
i'm testing https://ffmpegblazor.netlify.app/tomp3

Microsoft.JSInterop.JSException: SharedArrayBuffer is not defined
ReferenceError: SharedArrayBuffer is not defined
    at blob:https://localhost:5011/8b279815-9592-46f1-806c-a92e17d96ca7:22:175
    at https://unpkg.com/@ffmpeg/ffmpeg@0.10.0/dist/ffmpeg.min.js:1:7334
    at f (https://unpkg.com/@ffmpeg/ffmpeg@0.10.0/dist/ffmpeg.min.js:1:12320)
    at Generator._invoke (https://unpkg.com/@ffmpeg/ffmpeg@0.10.0/dist/ffmpeg.min.js:1:12108)
    at Generator.next (https://unpkg.com/@ffmpeg/ffmpeg@0.10.0/dist/ffmpeg.min.js:1:12745)
    at i (https://unpkg.com/@ffmpeg/ffmpeg@0.10.0/dist/ffmpeg.min.js:1:5052)
    at c (https://unpkg.com/@ffmpeg/ffmpeg@0.10.0/dist/ffmpeg.min.js:1:5255)
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
   at FFmpegBlazor.FFMPEG.Load(Boolean triggerEvents)

i'm happy to provide more info if needed.
Thank you

@sps014
Copy link
Owner

sps014 commented Mar 2, 2022

Thanks for info.
Recently chromium browsers stopped supporting SharedArrayBuffer on cross origin sites (since i was fetching .wasm from different domain). That means I have to ship ffmpeg.wasm with our application. eg. https://github.com/sps014/FFmpegBlazor/tree/Self-Host .
Also we need to set

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

headers.
Will update site this weekend.
These extra steps will be removed in .NET 7 when Multithreading arrives. Waiting for that preview to hit, we will have option to further speedup video processing and trim application.
have a great day.

@sps014 sps014 self-assigned this Mar 2, 2022
@nor0x
Copy link
Author

nor0x commented Mar 2, 2022

thank you very much for your quick reply 👏
i will check the self-host branch and see how i can implement it for my usecase

@aokocax
Copy link

aokocax commented Mar 6, 2022

Those who want to test it quickly on their local computer can add a web.config file to their project and run the project with IISExpress.
image

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>

<add name="Cross-Origin-Embedder-Policy" value="require-corp"/>
<add name="Cross-Origin-Opener-Policy" value="same-origin"/>

</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>

@sps014
Copy link
Owner

sps014 commented Mar 6, 2022

@aokocax thank you so much, this will help me so much, i asked the same question on aspnetcore dotnet/aspnetcore#38327 unfortunately was not able to find any pointers in the same direction..

@aokocax
Copy link

aokocax commented Mar 6, 2022

You're welcome, I thank you too for the beautiful project.

@aokocax thank you so much, this will help me so much, i asked the same question on aspnetcore dotnet/aspnetcore#38327 unfortunately was not able to find any pointers in the same direction..

@sps014
Copy link
Owner

sps014 commented Mar 6, 2022

@nor0x Website is now fixed and if you want you can check this netlify deployment example
Thanks for notifying.

@nor0x
Copy link
Author

nor0x commented Mar 6, 2022

thank you both 🙌
closing the issue now!

@nor0x nor0x closed this as completed Mar 6, 2022
@nor0x
Copy link
Author

nor0x commented Mar 7, 2022

Those who want to test it quickly on their local computer can add a web.config file to their project and run the project with IISExpress. image

<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <httpProtocol> <customHeaders>

<add name="Cross-Origin-Embedder-Policy" value="require-corp"/> <add name="Cross-Origin-Opener-Policy" value="same-origin"/>

</customHeaders> </httpProtocol> </system.webServer> </configuration>

thanks for the suggestion @aokocax ! do you know how to configure this with Kestrel? I'm on macOS and cannot use IIS for local development

@sps014
Copy link
Owner

sps014 commented Mar 8, 2022

That should be resolved in .NET 7 when they deliver Multi threading support in blazor wasm .
Currently not sure about Kestrel , didn't find anything useful.

@Heartnett
Copy link

Is there a workaround for vscode?

@sps014
Copy link
Owner

sps014 commented Aug 8, 2022

It is blocked by: dotnet/aspnetcore#38327
Currently only IIS allows us to add these two headers , running from VSCode require a lot of steps. These steps should be reduced in upcoming few .NET 7 preview (it is really close). In the mean time I suggest to use VS for better developer experience.

@Heartnett
Copy link

I'm running vscode on linux, VS is a non-starter for me.

@sps014
Copy link
Owner

sps014 commented Aug 8, 2022

@Heartnett
Another alternative is to build project then use 3rd party local web server which can serve wasm files and allows you to add headers with web request ie. add these :

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

@timothyparez
Copy link

This does not appear to be fixed in .net 7

@keke1210
Copy link

.NET 8 is here and this issue is only resolved in preview.

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

No branches or pull requests

6 participants