{"record":{"id":"0b4ccfe23d10f4c1","repo":"microsoft/playwright","slug":"websocket-is-already-in-closing-or-closed-state","errorCode":null,"errorMessage":"WebSocket is already in CLOSING or CLOSED state.","messagePattern":"WebSocket is already in CLOSING or CLOSED state\\.","errorType":"exception","errorClass":"DOMException","httpStatus":null,"severity":"error","filePath":"packages/injected/src/webSocketMock.ts","lineNumber":218,"sourceCode":"    }\n\n    get onmessage() {\n      return this._onmessageListener;\n    }\n\n    set onmessage(listener) {\n      if (this._onmessageListener)\n        this.removeEventListener('message', this._onmessageListener as any);\n      this._onmessageListener = listener;\n      if (this._onmessageListener)\n        this.addEventListener('message', this._onmessageListener as any);\n    }\n\n    send(message: WebSocketMessage): void {\n      if (this.readyState === WebSocketMock.CONNECTING)\n        throw new DOMException(`Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.`);\n      if (this.readyState !== WebSocketMock.OPEN)\n        throw new DOMException(`WebSocket is already in CLOSING or CLOSED state.`);\n      if (this._passthrough) {\n        if (this._ws)\n          this._apiSendToServer(message);\n      } else {\n        messageToData(message, data => binding({ type: 'onMessageFromPage', id: this._id, data }));\n      }\n    }\n\n    close(code?: number, reason?: string): void {\n      if (code !== undefined && code !== 1000 && (code < 3000 || code > 4999))\n        throw new DOMException(`Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999. ${code} is neither.`);\n      if (this.readyState === WebSocketMock.OPEN || this.readyState === WebSocketMock.CONNECTING)\n        this.readyState = WebSocketMock.CLOSING;\n      if (this._passthrough)\n        this._apiCloseServer(code, reason, true);\n      else\n        binding({ type: 'onClosePage', id: this._id, code, reason, wasClean: true });\n    }","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/injected/src/webSocketMock.ts#L200-L236","documentation":"Error \"WebSocket is already in CLOSING or CLOSED state.\" thrown in microsoft/playwright.","triggerScenarios":"Thrown at packages/injected/src/webSocketMock.ts:218 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"}