Skip to main content

Function: getWebSocketShim()

getWebSocketShim(fetchFn, factoryInit?): (url, protocols?) => WebSocket

Defined in: packages/utils/src/websocket-shim.ts:30

Creates a WebSocket shim class for use in Cloudflare Workers test environments.

Returns a browser-compatible WebSocket constructor that uses a provided fetch function to initiate WebSocket connections, enabling testing without a separate server.

Parameters

fetchFn

{(input, init?): Promise<Response>; (input, init?): Promise<Response>; }

The fetch function to use for WebSocket upgrade requests (e.g., SELF.fetch.bind(SELF)).

factoryInit?

WebSocketShimOptions

Optional configuration for headers and queue limits.

Returns

A WebSocket-compatible constructor class.

new getWebSocketShim(url, protocols?): WebSocket

Parameters

url

string | URL

protocols?

string | string[]

Returns

WebSocket