Skip to content

fix(websocket): handle Blob binaryType for compatibility_date >=2026-03-17 - #1049

Open
ZEROLINGG wants to merge 2 commits into
cloudflare:mainfrom
ZEROLINGG:fix/websocket-blob-binarytype
Open

fix(websocket): handle Blob binaryType for compatibility_date >=2026-03-17#1049
ZEROLINGG wants to merge 2 commits into
cloudflare:mainfrom
ZEROLINGG:fix/websocket-blob-binarytype

Conversation

@ZEROLINGG

Copy link
Copy Markdown

workerd#6178 changes WebSocket.binaryType default from arraybuffer to blob for compatibility_date >=2026-03-17 (websocket_standard_binary_type). Original MessageEvent::bytes()->Option<Vec> assumed ArrayBuffer and silently returned [] for Blob (new Uint8Array(Blob).length==0).

  • WebSocket: expose binary_type()/set_binary_type() proxying web_sys::BinaryType, must be set before accept() to opt back to ArrayBuffer
  • MessageEvent: split into bytes_from_arraybuffer()->Result<Vec> (sync), bytes_from_blob().await->Result<Vec> and unified bytes().await->Result<Vec> that handles both types; docs cover 2026-04-21 changelog and workerd#6178
  • Fix Blob handling via await blob.array_buffer() instead of Uint8Array::new(blob)

Refs: https://developers.cloudflare.com/changelog/post/2026-04-21-websocket-standard-binary-type
Refs: cloudflare/workerd#6178

…03-17

workerd#6178 changes WebSocket.binaryType default from arraybuffer to blob
for compatibility_date >=2026-03-17 (websocket_standard_binary_type).
Original MessageEvent::bytes()->Option<Vec<u8>> assumed ArrayBuffer and
silently returned [] for Blob (new Uint8Array(Blob).length==0).

- WebSocket: expose binary_type()/set_binary_type() proxying web_sys::BinaryType,
  must be set before accept() to opt back to ArrayBuffer
- MessageEvent: split into bytes_from_arraybuffer()->Result<Vec<u8>> (sync),
  bytes_from_blob().await->Result<Vec<u8>> and unified bytes().await->Result<Vec<u8>>
  that handles both types; docs cover 2026-04-21 changelog and workerd#6178
- Fix Blob handling via await blob.array_buffer() instead of Uint8Array::new(blob)

Refs: https://developers.cloudflare.com/changelog/post/2026-04-21-websocket-standard-binary-type
Refs: cloudflare/workerd#6178
@ZEROLINGG
ZEROLINGG requested a review from guybedford as a code owner August 22, 2026 13:37
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.

1 participant