mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Implements support for the `upgrade` and `unexpected-response` events in the `ws` package polyfill. This enables Playwright's `chromium.connectOverCDP()` and other tools that rely on these events to work correctly with Bun. Changes: - Add `upgradeStatusCode` property to native WebSocket that stores the HTTP status code from the upgrade handshake - Pass the status code from the HTTP upgrade response through Zig to C++ - Update ws.js polyfill to emit `upgrade` event before `open` event with the actual status code from the native WebSocket - Emit `unexpected-response` event on connection errors for compatibility - Add TypeScript types for the new `upgradeStatusCode` property - Add regression tests for the new events The `upgrade` event provides a response object with `statusCode`, `statusMessage`, and `headers` properties. Headers are currently empty but can be populated in a future enhancement if needed. Fixes #9911 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>