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

Firefox: CloseNow returns "A parameter or an operation is not supported by the underlying object" #478

Open
vito opened this issue Sep 6, 2024 · 2 comments
Labels

Comments

@vito
Copy link

vito commented Sep 6, 2024

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,

@coder-labeler coder-labeler bot added the bug label Sep 6, 2024
@mafredri
Copy link
Member

mafredri commented Sep 6, 2024

@vito any chance you could try this change? Does it still produce the same error?

c.v.Call("close", code, reason)

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
}

@vito
Copy link
Author

vito commented Sep 8, 2024

@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.

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

No branches or pull requests

2 participants