#2707·msw

[experimental] `WebSocketNetworkFrame` cannot be initialized with `WebSocket(Client|Server)ConnectionProtocol` implementations

Author: christoph-frickeCreated Apr 12, 2026Updated Sep 25, 2026

This issue has come up while migrating @msw/playwright to the new network source architecture.

Description

When constructing an implementation of the WebSocketNetworkFrame, it requires a WebSocketClientConnection and WebSocketServerConnection connection. This results in errors when providing WebSocket(Client|Server)ConnectionProtocol implementations.

typescript
const frame = new PlaywrightWebSocketNetworkFrame({
  connection: {
    client: new PlaywrightWebSocketClientConnection(route),
    server: new PlaywrightWebSocketServerConnection(route),
    info: { protocols: [] },
  },
})
  • client: Type 'PlaywrightWebSocketClientConnection' is missing the following properties from type 'WebSocketClientConnection': socket, transport, [kEmitter$1]
  • server: Type 'PlaywrightWebSocketServerConnection' is missing the following properties from type 'WebSocketServerConnection': client, transport, createConnection, mockCloseController, and 7 more.

Furthermore, it results in errors when passing protocol implementations to webSockerHandler.run(...).

Proposed Solution

As pointed out here, this seems to be a bug since WebSocket(Client|Server)ConnectionProtocol is the intended way for working with WebSocketNetworkFrame.

I'm getting the WebSocketConnectionData from the Interceptors as-is, but that's a mistake. That type is a narrower type than what the frame should care about.

We should probably annotate that connection option as WebSocketHandlerConnection from WebSocketHandler.ts, which contains the broader WebSocketClientConnectionProtocol.