msqr1 / Vosklet

A speech recognizer that can run on the browser, inspired by vosk-browser
MIT License
33 stars 1 forks source link

ReferenceError: Can't find variable: SharedArrayBuffer #4

Closed jakespracher closed 5 months ago

jakespracher commented 6 months ago
[Error] Unhandled Promise Rejection: ReferenceError: Can't find variable: SharedArrayBuffer
    (anonymous function) (Vosklet.js:9:9494)
    (anonymous function) (index.html:21)

Safari Version 17.3.1 (19617.2.4.11.12)

Happens after clicking start and speaking via the example

Thanks for the lib, still failing to get browser offline speech recognition working with any example from any offering 🙃

msqr1 commented 6 months ago

Did other browsers have the same issue? I've never tested this on Safari, so I will try to reproduce it and see what can we do from there. Do you have the whole stacktrace?

msqr1 commented 6 months ago

I couldn't reproduce this on Chrome, Edge, or Firefox, maybe this is a Safari issue?

cellis commented 6 months ago

Same on Chrome. I'm running the examples with python -m http.server 8080 then going to localhost:8080/examples/fromMic.html

Screenshot 2024-05-16 at 8 01 14 PM
cellis commented 6 months ago

I think, per this, that we just need to send the correct headers from the server.

msqr1 commented 6 months ago

Yeah, this maybe a coep/coop issue

jakespracher commented 6 months ago

Ah interesting, adding those two headers makes the original error log go away and adds two more that are CSP related

[Error] Refused to load blob:http://localhost:4000/59684ac0-cdde-4534-9394-9499838d5deb because it does not appear in the worker-src directive of the Content Security Policy.
[Error] Unhandled Promise Rejection: SecurityError: The operation is insecure.
    (anonymous function) (app.js:9510)
msqr1 commented 6 months ago

You may have a strict CSP for default-src or child-src (Safari and some other) or worker-src that disallow blobs. Try setting worker-src to blob. Let me know if it works for you!

jakespracher commented 6 months ago

I think we can close this one out due to the header requirements for SharedArrayBuffer and general CSP issues, though not sure if it'd be worth adding documentation about this. That said, it's still not working 😅 may open a separate issue.

jakespracher commented 6 months ago

Relevant docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements

msqr1 commented 6 months ago

Does it work on other browsers? Let's just keep this issue here. Not gonna lie, I didn't really think about Safari while doing this. 😅

msqr1 commented 6 months ago

if it'd be worth adding documentation about this.

Some docs on CSP settings would be nice, but we have to make yours work to confirm it. We already have docs for the response headers

msqr1 commented 6 months ago

That said, it's still not working 😅 may open a separate issue.

worker-src set to blob still doesn't work?

jakespracher commented 6 months ago

@cellis mentioned he encountered this on Chrome, it doesn't seem safari specific. Once I get the state of my local cleaned up I can revert the fix and try. I think worker-src blob does work but for now I've disabled my CSP and am still working around the failed to fetch issue in #1

msqr1 commented 6 months ago

Can you review the proposal for fixing I have in #1?