{"record":{"id":"8b40f9788ba67d86","repo":"grafana/k6","slug":"sending-a-message-to-browser-w","errorCode":null,"errorMessage":"sending a message to browser: %w","messagePattern":"sending a message to browser: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/connection.go","lineNumber":517,"sourceCode":"\t\tmsg := &cdproto.Message{\n\t\t\tID:     c.msgIDGen.newID(),\n\t\t\tMethod: cdproto.MethodType(target.CommandDetachFromTarget),\n\t\t\tParams: buf,\n\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 {","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/js/modules/k6/browser/common/connection.go#L499-L535","documentation":"Connection.send aborted because the connection's error channel reported a failure (recv/send loop crash or connection teardown) before the message could be queued on sendCh. The wrapped error is the underlying connection failure; the CDP message was never delivered.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/connection.go:480 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped error and browser logs for the underlying connection failure","Avoid sending CDP commands after the browser or page is closed","Restart the browser/test if the connection dropped unexpectedly (crash, timeout)"],"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"}