Skip to content

Issue with "WebSocket.send()": Exceptions thrown listed is incorrect #2589

Description

@mofojed

MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send

What information was incorrect, unhelpful, or incomplete?

In the Exceptions Thrown section, it says the INVALID_STATE_ERR exception is thrown when send is called while the connection is not OPEN. That is incorrect, as an exception is only called in the CONNECTING state; if CLOSING or CLOSED, send just discards the data. Refer to RFC: https://html.spec.whatwg.org/multipage/web-sockets.html#dom-websocket-send
Or run the following snippet in a browser console:

var ws = new WebSocket("wss://invalid-ws-url.com");
setTimeout(() => ws.send("Hello"), 5000);

Specific section or headline?

Exceptions thrown->INVALID_STATE_ERR

What did you expect to see?

Should say it only throws in the state is CONNECTING. Should probably mention in the description of the method that it doesn't do anything if the connection is already closed, and the onus is on the user to check the readyState before calling send.

Did you test this? If so, how?

Ran a snippet in the browser console:

var ws = new WebSocket("wss://invalid-ws-url.com");
setTimeout(() => ws.send("Hello"), 5000);
MDN Content page report details

Metadata

Metadata

Assignees

No one assigned

    Labels

    Content:WebAPIWeb API docseffort: smallThis task is a small effort.help wantedIf you know something about this topic, we would love your help!p2Minor issue with low priority, can be fixed later.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions