coder/websocket

wasm not working for unknown reason

nhooyr opened this issue · 6 comments

nhooyr commented
          While the Go team decides how (or whether?) to handle this, is there a workaround ? 

My execution environment:

  • server: go1.21.4 darwin/arm64
  • client: Safari 17.1 running a wasm client compiled with go1.21.4 (GOOS=js GOARCH=wasm)

When the wasm client tries to connect, the server gets this error from websocket.Accept(w,req,nil):

failed to accept WebSocket connection: WebSocket protocol violation: Connection header "keep-alive" does not contain Upgrade

When package websocket is compiled for wasm, the field websocket.DialOptions.HTTPHeader is not available, so I cannot add the required header. This appears to be a limitation of the Javascript WebSocket API, or of how the API is used.

I presume this is all related to issue 373.

But it is possible that I am on the wrong track and have no idea what I am doing wrong.

I would be grateful for any guidance.

Originally posted by @fbaube in #4 (comment)

nhooyr commented

@fbaube Not related to HTTP/2.

The browser automatically adds such headers as necessary. Do you have a proxy between the client and server? Any middleware before you call websocket.Accept that might be interfering?

fbaube commented

Do you have a proxy between the client and server? Any middleware before you call websocket.Accept that might be interfering?

No proxy, no middleware. I am running the server and Safari on the same machine, and the URL is to localhost.

Not related to HTTP/2.

I can add that for completeness, I tried methods (documented in stdlib http) to disable HTTP/2, and in both cases I still got the identical error about the missing keep-alive header:

  • Invoke the server with GODEBUG=http2server=0 (and of course also GODEBUG=http2client=0, because why not)
  • Set the server's TLSNextProto to a non-nil map (by following this example)
nhooyr commented

Is it possible for you to upload your code?

fbaube commented

I'll try to make a minimal demo of the bug. I might find that something else is gumming up the works.

fbaube commented

I withdraw this issue.

I had not used my code for months, and it was not updated as needed. In particular, wasm_exec.js was out of sync.

I have updated it to be the proper version, and it is now renamed to wasm_exec_21_4.js

My apologies.

nhooyr commented

Awesome!