grafana/k6 · error

getting response body as text

Error message

getting response body as text: %w

What it means

Wrap of Response.fetchBody in the public Text() accessor: identical mechanism to the Body() wrap — the CDP Network.getResponseBody fetch (with internal retries for transient cache misses) failed, and this error adds the "as text" context. Typical causes are the browser session being closed, the response body evicted from Chrome's cache after further navigation, or the resource having no cached body at all.

Solutions

  1. Read the body right after receiving the response instead of after subsequent navigations
  2. Keep the page open until all response reads finish
  3. Retry the request if the error is transient
  4. Check the wrapped CDP error to distinguish cache eviction from a closed session
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/http.go:821 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/dd6bdce4982b3d21. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/http.go:820

		Body:    r.bodySize(),
		Headers: r.headersSize(),
	}
}

// Status returns the response status code.
func (r *Response) Status() int64 {
	return r.status
}

// StatusText returns the response status text.
func (r *Response) StatusText() string {
	return r.statusText
}

// Text returns the response body as a string.
func (r *Response) Text() (string, error) {
	if err := r.fetchBody(); err != nil {
		return "", fmt.Errorf("getting response body as text: %w", err)
	}

	r.bodyMu.RLock()
	defer r.bodyMu.RUnlock()

	return string(r.body), nil
}

// URL returns the request URL.
func (r *Response) URL() string {
	return r.url
}

// Route allows to handle a request.
type Route struct {
	logger         *log.Logger
	networkManager *NetworkManager

View on GitHub (pinned to 8d06114777)