OpenAICloudflare Developer PlatformApr 21, 2026, 12:00 AM

Workers - WebSocket binary messages now delivered as Blob by default

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

Workers - WebSocket binary messages now delivered as Blob by default

Key Points

  • Binary frames delivered as Blob by default
  • Set ws.binaryType = "arraybuffer" before accept() to opt back
  • Use no_websocket_standard_binary_type in Wrangler to keep old default

Summary

Binary WebSocket frames received by Cloudflare Workers are now delivered to the message event as Blob objects by default, matching the WebSocket specification and browser behavior. Previously binary frames were always delivered as ArrayBuffer. This change is active for Workers with compatibility dates on or after 2026-03-17 (via the websocket_standard_binary_type compatibility flag). Durable Object hibernatable WebSocket handlers are unchanged and still receive ArrayBuffer.

Key Points

  • Default delivery for binary frames is now Blob (not ArrayBuffer).
  • If your code assumes event.data is an ArrayBuffer, instanceof ArrayBuffer checks will fail and may silently drop frames.
  • To opt a single WebSocket back into ArrayBuffer delivery, set ws.binaryType = "arraybuffer" before calling ws.accept().
  • To preserve the old ArrayBuffer default across a Worker, add the no_websocket_standard_binary_type flag to your Wrangler config.
  • The per-WebSocket binaryType assignment works regardless of the compatibility flag.

Quick migration checklist

  • Audit handlers that process event.data and avoid relying on instanceof ArrayBuffer.
  • If you need ArrayBuffer for an individual connection, set ws.binaryType = "arraybuffer" before ws.accept().
  • If you need the old default globally, add no_websocket_standard_binary_type to Wrangler.

Resources

See the WebSockets binary messages documentation for details and examples.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

Workers - WebSocket バイナリメッセージがデフォルトで Blob として配信されるようになりました

概要

WebSocket で受信したバイナリフレームは、デフォルトで message イベントに Blob ↗ オブジェクトとして渡されるようになりました。これは WebSocket の仕様 ↗ および標準ブラウザの動作に合わせた変更です。以前はバイナリフレームは常に ArrayBuffer ↗ として配信されていました。

binaryType プロパティは、個々の WebSocket ごとの配信形式を制御します。

影響を受ける Workers

この変更は、互換性日付が 2026-03-17 以降に設定されている Workers に対して、websocket_standard_binary_type 互換性フラグを通じて有効になっています。

文書化が遅れたことをお詫びします。もしあなたの Worker がバイナリ WebSocket メッセージを扱い event.data を ArrayBuffer と仮定している場合、フレームは Blob として届き、単純に instanceof ArrayBuffer で判定していると全てのフレームが無視されてしまいます。

ArrayBuffer 配信に戻す方法

WebSocket を受け入れる前に binaryType を設定することで、その WebSocket に限り ArrayBuffer 配信に戻せます(互換性フラグに関係なく動作します)。例:

const resp = await fetch("https://example.com", {
  headers: { Upgrade: "websocket" },
});
const ws = resp.webSocket;
// この WebSocket を ArrayBuffer 配信に戻す
ws.binaryType = "arraybuffer";
ws.accept();
ws.addEventListener("message", (event) => {
  if (typeof event.data === "string") {
    // テキストフレーム
  } else {
    // 上で binaryType を設定したので、event.data は ArrayBuffer です
  }
});

Worker 全体で ArrayBuffer をデフォルトに保つ方法

まだ移行の準備ができておらず、Worker 内の全ての WebSocket で ArrayBuffer をデフォルトにしたい場合は、wrangler の設定ファイルに no_websocket_standard_binary_type フラグを追加してください。例:

# wrangler.toml
compatibility_flags = ["no_websocket_standard_binary_type"]

Durable Object の扱い

この変更は、Durable Object の hibernatable WebSocket webSocketMessage ハンドラには影響しません。そちらは引き続きバイナリデータを ArrayBuffer として受け取ります。

参照

  • 詳細は WebSockets binary messages を参照してください。