Skip to content

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

Open
@vito

Description

@vito

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,

Activity

mafredri

mafredri commented on Sep 6, 2024

@mafredri
Member

@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

vito commented on Sep 8, 2024

@vito
Author

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Firefox: `CloseNow` returns "A parameter or an operation is not supported by the underlying object" · Issue #478 · coder/websocket