{"record":{"id":"729009407c95b77d","repo":"grafana/k6","slug":"closing-communication-with-browser-w","errorCode":null,"errorMessage":"closing communication with browser: %w","messagePattern":"closing communication with browser: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/connection.go","lineNumber":521,"sourceCode":"\t\t}\n\t\tif err := c.send(c.ctx, msg, nil, nil); err != nil {\n\t\t\tc.logger.Errorf(\"Connection:detachSession\", \"sid:%v wsURL:%q, err:%v\", session.id, c.wsURL, err)\n\t\t}\n\t}()\n}\n\nfunc (c *Connection) send(\n\tctx context.Context, msg *cdproto.Message, recvCh chan *cdproto.Message, res any,\n) error {\n\tselect {\n\tcase c.sendCh <- msg:\n\tcase err := <-c.errorCh:\n\t\tc.logger.Debugf(\"Connection:send:<-c.errorCh\", \"wsURL:%q sid:%v, err:%v\", c.wsURL, msg.SessionID, err)\n\t\treturn fmt.Errorf(\"sending a message to browser: %w\", err)\n\tcase code := <-c.closeCh:\n\t\tc.logger.Debugf(\"Connection:send:<-c.closeCh\", \"wsURL:%q sid:%v, websocket code:%v\", c.wsURL, msg.SessionID, code)\n\t\t_ = c.close(code)\n\t\treturn fmt.Errorf(\"closing communication with browser: %w\", &websocket.CloseError{Code: code})\n\tcase <-ctx.Done():\n\t\tc.logger.Debugf(\"Connection:send:<-ctx.Done\", \"wsURL:%q sid:%v err:%v\", c.wsURL, msg.SessionID, ContextErr(ctx))\n\t\treturn nil\n\tcase <-c.done:\n\t\tc.logger.Debugf(\"Connection:send:<-c.done\", \"wsURL:%q sid:%v\", c.wsURL, msg.SessionID)\n\t\treturn nil\n\t}\n\n\t// Block waiting for response.\n\tif recvCh == nil {\n\t\treturn nil\n\t}\n\ttid := c.findTargetIDForLog(msg.SessionID)\n\tselect {\n\tcase msg := <-recvCh:\n\t\tvar sid target.SessionID\n\t\ttid = \"\"\n\t\tif msg != nil {","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/js/modules/k6/browser/common/connection.go#L503-L539","documentation":"Connection.send aborted because the connection's close channel signaled that the websocket was closed before the message could be sent. The wrapped error describes the closure; the command is dropped since the transport is gone.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/connection.go:484 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Don't issue browser commands after page/browser close","Check earlier logs for why the connection closed (browser crash, timeout, explicit close)","Guard code paths that race shutdown with pending operations"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}