grafana/k6 · error
closing communication with browser
Error message
closing communication with browser: %w
What it means
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.
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
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/connection.go:484 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@94169daab2 (2026-08-18).
Data as JSON: /api/errors/729009407c95b77d.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/connection.go:521
}
if err := c.send(c.ctx, msg, nil, nil); err != nil {
c.logger.Errorf("Connection:detachSession", "sid:%v wsURL:%q, err:%v", session.id, c.wsURL, err)
}
}()
}
func (c *Connection) send(
ctx context.Context, msg *cdproto.Message, recvCh chan *cdproto.Message, res any,
) error {
select {
case c.sendCh <- msg:
case err := <-c.errorCh:
c.logger.Debugf("Connection:send:<-c.errorCh", "wsURL:%q sid:%v, err:%v", c.wsURL, msg.SessionID, err)
return fmt.Errorf("sending a message to browser: %w", err)
case code := <-c.closeCh:
c.logger.Debugf("Connection:send:<-c.closeCh", "wsURL:%q sid:%v, websocket code:%v", c.wsURL, msg.SessionID, code)
_ = c.close(code)
return fmt.Errorf("closing communication with browser: %w", &websocket.CloseError{Code: code})
case <-ctx.Done():
c.logger.Debugf("Connection:send:<-ctx.Done", "wsURL:%q sid:%v err:%v", c.wsURL, msg.SessionID, ContextErr(ctx))
return nil
case <-c.done:
c.logger.Debugf("Connection:send:<-c.done", "wsURL:%q sid:%v", c.wsURL, msg.SessionID)
return nil
}
// Block waiting for response.
if recvCh == nil {
return nil
}
tid := c.findTargetIDForLog(msg.SessionID)
select {
case msg := <-recvCh:
var sid target.SessionID
tid = ""
if msg != nil {View on GitHub (pinned to 94169daab2)