{"record":{"id":"4e2bab7db48326f2","repo":"microsoft/playwright","slug":"failed-to-execute-close-on-websocket-the-clos","errorCode":null,"errorMessage":"Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999. ${code} is neither.","messagePattern":"Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999\\. (.+?) is neither\\.","errorType":"exception","errorClass":"DOMException","httpStatus":null,"severity":"error","filePath":"packages/injected/src/webSocketMock.ts","lineNumber":229,"sourceCode":"        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    }\n\n    // --- methods called from the routing API ---\n\n    _apiEnsureOpened() {\n      // This is called at the end of the route handler. If we did not connect to the server,\n      // assume that websocket will be fully mocked. In this case, pretend that server\n      // connection is established right away.\n      if (!this._ws)\n        this._ensureOpened();\n    }\n","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/injected/src/webSocketMock.ts#L211-L247","documentation":"Error \"Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999. ${code} is neither.\" thrown in microsoft/playwright.","triggerScenarios":"Thrown at packages/injected/src/webSocketMock.ts:229 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"}