{"record":{"id":"4e945186c6819e94","repo":"microsoft/playwright","slug":"can-only-connect-to-the-server-once","errorCode":null,"errorMessage":"Can only connect to the server once","messagePattern":"Can only connect to the server once","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/injected/src/webSocketMock.ts","lineNumber":267,"sourceCode":"      // Calling \"sendToPage()\" from the route handler. Allow this for easier testing.\n      this._ensureOpened();\n      if (this.readyState !== WebSocketMock.OPEN)\n        throw new DOMException(`WebSocket is already in CLOSING or CLOSED state.`);\n      this.dispatchEvent(new MessageEvent('message', { data: message, origin: this._origin, cancelable: true }));\n    }\n\n    _apiSendToServer(message: WebSocketMessage) {\n      if (!this._ws)\n        throw new Error('Cannot send a message before connecting to the server');\n      if (this._ws.readyState === WebSocketMock.CONNECTING)\n        this._wsBufferedMessages.push(message);\n      else\n        this._ws.send(message);\n    }\n\n    _apiConnect() {\n      if (this._ws)\n        throw new Error('Can only connect to the server once');\n\n      this._ws = new NativeWebSocket(this.url, this._protocols);\n      this._ws.binaryType = this._binaryType;\n\n      this._ws.onopen = () => {\n        for (const message of this._wsBufferedMessages)\n          this._ws!.send(message);\n        this._wsBufferedMessages = [];\n        this._ensureOpened();\n      };\n\n      this._ws.onclose = event => {\n        this._onWSClose(event.code, event.reason, event.wasClean);\n      };\n\n      this._ws.onmessage = event => {\n        if (this._passthrough)\n          this._apiSendToPage(event.data);","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/injected/src/webSocketMock.ts#L249-L285","documentation":"Error \"Can only connect to the server once\" thrown in microsoft/playwright.","triggerScenarios":"Thrown at packages/injected/src/webSocketMock.ts:267 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}