WebSocket
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2825
Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
Extends
Section titled “Extends”EventTarget
<WebSocketEventMap
>
Properties
Section titled “Properties”extensions
Section titled “extensions”
readonly
extensions:null
|string
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2881
Returns the extensions selected by the server, if any.
protocol
Section titled “protocol”
readonly
protocol:null
|string
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2875
Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor’s second argument to perform subprotocol negotiation.
readyState
Section titled “readyState”
readonly
readyState:number
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2863
Returns the state of the WebSocket object’s connection. It can have the values described below.
readonly
url:null
|string
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2869
Returns the URL that was used to establish the WebSocket connection.
Methods
Section titled “Methods”accept()
Section titled “accept()”accept():
void
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2843
Returns
Section titled “Returns”void
addEventListener()
Section titled “addEventListener()”addEventListener<
Type
>(type
,handler
,options?
):void
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:812
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options’s capture.
When set to true, options’s capture prevents callback from being invoked when the event’s eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event’s eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event’s eventPhase attribute value is AT_TARGET.
When set to true, options’s passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options’s once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options’s signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target’s event listener list and is not appended if it has the same type, callback, and capture.
Type Parameters
Section titled “Type Parameters”Type
extends keyof WebSocketEventMap
Parameters
Section titled “Parameters”Type
handler
Section titled “handler”EventListenerOrEventListenerObject
<WebSocketEventMap
[Type
]>
options?
Section titled “options?”boolean
| EventTargetAddEventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”EventTarget.addEventListener
close()
Section titled “close()”close(
code?
,reason?
):void
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2855
Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
Parameters
Section titled “Parameters”number
reason?
Section titled “reason?”string
Returns
Section titled “Returns”void
deserializeAttachment()
Section titled “deserializeAttachment()”deserializeAttachment():
any
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2857
Returns
Section titled “Returns”any
dispatchEvent()
Section titled “dispatchEvent()”dispatchEvent(
event
):boolean
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:832
Dispatches a synthetic event event to target and returns true if either event’s cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
Parameters
Section titled “Parameters”Event
| MessageEvent
| CloseEvent
| ErrorEvent
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”EventTarget.dispatchEvent
removeEventListener()
Section titled “removeEventListener()”removeEventListener<
Type
>(type
,handler
,options?
):void
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:822
Removes the event listener in target’s event listener list with the same type, callback, and options.
Type Parameters
Section titled “Type Parameters”Type
extends keyof WebSocketEventMap
Parameters
Section titled “Parameters”Type
handler
Section titled “handler”EventListenerOrEventListenerObject
<WebSocketEventMap
[Type
]>
options?
Section titled “options?”boolean
| EventTargetEventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”EventTarget.removeEventListener
send()
Section titled “send()”send(
message
):void
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2849
Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
Parameters
Section titled “Parameters”message
Section titled “message”string
| ArrayBuffer
| ArrayBufferView
<ArrayBufferLike
>
Returns
Section titled “Returns”void
serializeAttachment()
Section titled “serializeAttachment()”serializeAttachment(
attachment
):void
Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20250725.0/node_modules/@cloudflare/workers-types/index.ts:2856
Parameters
Section titled “Parameters”attachment
Section titled “attachment”any
Returns
Section titled “Returns”void