Skip to content

Support sending Blob #2206

@kettanaito

Description

@kettanaito

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

Currently, ws doesn't accept Blob as an argument to the .send() function:

wss.on('connection', (ws) => ws.send(new Blob(['hello']))

I believe this is mainly for historic reasons because there used to be no Blob in Node.js. There is now, and it would be great to align the sending (and receiving also) with the WHATWG WebSocket standard.

ws version

8.16.0

Node.js Version

v20.11.0

System

Irrelevant.

Expected result

ws supports sending Blob from the server.

Actual result

  • Type error on the unknown input type to .send();
  • A runtime TypeError:
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Blob

Attachments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions