Firefox: `CloseNow` returns "A parameter or an operation is not supported by the underlying object"
vito opened this issue · 2 comments
Hi there, I noticed in Firefox WASM calling CloseNow returns an error:
A parameter or an operation is not supported by the underlying object
This can be fixed by instead calling Close(websocket.StatusNormalClosure, "some reason").
Since CloseNow is just an alias for Close(websocket.StatusGoingAway, "") my guess is that the empty reason value is being rejected by the browser,
@vito any chance you could try this change? Does it still produce the same error?
websocket/internal/wsjs/wsjs_js.go
Line 138 in a633a10
to:
func (c WebSocket) Close(code int, reason string) (err error) {
defer handleJSError(&err, nil)
if reason != "" {
c.v.Call("close", code, reason)
} else {
c.v.Call("close", code)
}
return err
}@mafredri Tried that out - it actually doesn't seem like the empty reason is the issue, it seems to be the websocket.StatusGoingAway value.
This works fine:
if err := c.conn.Close(
websocket.StatusNormalClosure,
"",
); err != nil {This returns the error:
if err := c.conn.Close(
websocket.StatusGoingAway,
"",
); err != nil {Maybe that status code is reserved for the browser and it's not expected to be used programmatically?
Per the docs:
| 1000 | Normal Closure | The connection successfully completed the purpose for which it was created. |
|---|---|---|
| 1001 | Going Away | The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection. |