Skip to content

Send a Blob passed to WebSocket send() as a binary message - #8850

Merged
littledivy merged 2 commits into
mainfrom
littledivy/2026-11-24-ws-send-blob
Nov 25, 2026
Merged

littledivy merged 2 commits into
mainfrom
littledivy/2026-11-24-ws-send-blob

Conversation

@littledivy

@littledivy littledivy commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

The WHATWG WebSockets spec says send(Blob) sends the Blob's bytes as a binary message, in order with the other messages sent. workerd's send() takes an ArrayBuffer, an ArrayBufferView or a string, so a Blob is converted to a string and sent as a text message such as "[object Blob]". The WPT case Send-binary-blob was disabled because of this, since the echo server never sent a binary message back and the test hung.

In this patch send() also takes a Blob. A Blob's bytes are always in memory, so send() copies them and queues them like any other binary message, which keeps the order with the send() calls around it. They count toward bufferedAmount and the isolate's external memory the same way.

There is no compat flag. The one thing that changes is that send(blob), which used to send the text "[object Blob]" (or "[object Object]" on older compatibility dates), now sends the Blob's bytes as a binary message. Nothing should depend on that text.

websocket-send-blob-test covers a Blob, an empty Blob, a File, a sliced Blob, ordering against string and ArrayBuffer sends, and bufferedAmount. It fails without the fix. The second commit runs Send-binary-blob, which passes.

@littledivy
littledivy requested review from a team as code owners November 24, 2026 04:04

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 276bdc66.

This review, of 3915480b

✅ Approved — I found no issues. With the compat flag on, a Blob is sent as a binary message in order with other sends; without the flag, nothing changes, and the tests and the WPT case cover both.

Not opened by the correctness review: 1 changed file it was meant to read
  • types/generated-snapshot/experimental/index.ts

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No issues found.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

No issues found.


⚡ Performance: ✅ LGTM

The Blob's bytes are copied once, the same way the existing ArrayBuffer send path copies its data.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 3915480b

@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 67.53%. Comparing base (28068ef) to head (276bdc6).
⚠️ Report is 161 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/api/web-socket.c++ 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8850      +/-   ##
==========================================
- Coverage   67.73%   67.53%   -0.20%     
==========================================
  Files         848      871      +23     
  Lines      215725   220345    +4620     
  Branches    32511    32955     +444     
==========================================
+ Hits       146121   148814    +2693     
- Misses      50404    52076    +1672     
- Partials    19200    19455     +255     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@npaun npaun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need a compat flag? Who's going to be complaining that we're no longer sending [object Blob] anymore?

Comment thread src/workerd/api/web-socket.h Resolved
The WHATWG WebSockets spec says send(Blob) sends the Blob's bytes as a
binary message, in order with the other messages sent. workerd's send()
takes an ArrayBuffer, an ArrayBufferView or a string, so a Blob is
converted to a string and sent as a text message such as
"[object Blob]".

In this patch send() also takes a Blob. A Blob's bytes are always in
memory, so send() copies them and queues them like any other binary
message, which keeps the order with the send() calls around it. They
count toward bufferedAmount and the isolate's external memory the same
way.

There is no compat flag. The one thing that changes is that
send(blob), which used to send the text "[object Blob]" (or
"[object Object]" on older compatibility dates), now sends the Blob's
bytes as a binary message. Nothing should depend on that text.

websocket-send-blob-test covers a Blob, an empty Blob, a File, a
sliced Blob, ordering against string and ArrayBuffer sends, and
bufferedAmount. It fails without the fix.
Send-binary-blob was disabled because send() didn't take a Blob, so
the echo server never sent a binary message back and the test hung.
In this patch it runs, and passes.
@littledivy
littledivy force-pushed the littledivy/2026-11-24-ws-send-blob branch from 3915480 to 276bdc6 Compare November 25, 2026 06:42
@littledivy
littledivy requested a review from a team as a code owner November 25, 2026 06:42

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No issues found. A Blob passed to send() is copied and queued on the existing binary path, so send order and buffer accounting work as before, and dropping the compat flag is reasonable for a change that only replaces the "[object Blob]" text.

Not opened by the correctness review: 2 changed files it was meant to read
  • types/generated-snapshot/experimental/index.ts
  • types/generated-snapshot/index.ts

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No issues found. The Blob's bytes go through the same size accounting and bufferedAmount handling as an ArrayBuffer send.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

No issues found. The Blob case copies getData(js) into the existing binary send path. The internal Impl::send signature stays as it was, and the tests cover a Blob, an empty Blob, a File, a sliced Blob, ordering and bufferedAmount.


⚡ Performance: ✅ LGTM

The Blob's bytes are copied once, the same way the ArrayBuffer send path copies its data.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 276bdc66

@littledivy
littledivy merged commit f7f12c3 into main Nov 25, 2026
25 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-24-ws-send-blob branch November 25, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants