grafana/k6 · error
getting response body: %w
Error message
getting response body: %w
What it means
Response.Body() first fetches the body over CDP (fetchBody, with its 5x retry loop for late-arriving data), then returns the cached bytes. This error wraps that fetch failure; the separate redirect-status guard is a distinct error, so hitting this one means the status was fine but Network.getResponseBody failed.
Source
Thrown at internal/js/modules/k6/browser/common/http.go:666
for name, values := range r.extraHeaders {
headers[strings.ToLower(name)] = strings.Join(values, "\n")
}
} else {
for name, values := range r.headers {
headers[strings.ToLower(name)] = strings.Join(values, "\n")
}
}
r.extraHeadersMu.RUnlock()
return headers
}
// Body returns the response body as a bytes buffer.
func (r *Response) Body() ([]byte, error) {
if r.status >= 300 && r.status <= 399 {
return nil, fmt.Errorf("response body is unavailable for redirect responses")
}
if err := r.fetchBody(); err != nil {
return nil, fmt.Errorf("getting response body: %w", err)
}
r.bodyMu.RLock()
defer r.bodyMu.RUnlock()
return r.body, nil
}
// bodySize returns the size in bytes of the response body.
func (r *Response) bodySize() int64 {
// Skip redirect responses
if r.status >= 300 && r.status <= 399 {
return 0
}
if err := r.fetchBody(); err != nil {
r.logger.Debugf("Response:bodySize:fetchBody",
"url:%s method:%s err:%s", r.url, r.request.method, err)View on GitHub (pinned to 93accf6570)
Solutions
- Call res.body() immediately after receiving the response object
- Avoid reading bodies for intercepted (fulfilled) responses through this API
- Ensure the page and context stay open until body assertions finish
- If it happens only under load, investigate browser stability (memory, sandbox, zombie processes)
Example fix
// before const res = await promiseOfNavigation; // stored for later await doOtherWork(); const body = await res.body(); // after const res = await promiseOfNavigation; const body = await res.body(); // read as soon as it arrives await doOtherWork();
Defensive patterns
Strategy: try-catch
Try / catch
try {
const body = await res.body();
} catch (e) {
if (!/getting response body/.test(String(e.message))) throw e;
// body unavailable: page navigated/closed or fulfilled response
} Prevention
- Call res.body() as soon as the response arrives
- Do not hold Response objects across navigations for later body reads
- Avoid body reads for intercepted requests
When it happens
Trigger: Calling res.body() when the body cannot be retrieved: page navigated away or closed before the read, response fulfilled via route.fulfill() with no network data, cached/service-worker responses without retrievable bodies, or the DevTools session/browser gone.
Common situations: Deferring body reads until after navigation or teardown; intercepted requests; CI flakiness where the browser drops under load; asserting on large streaming responses.
Related errors
- fetching response body: %w
- getting response body as text: %w
- errorText
- updating extra HTTP headers: %w
- updating offline mode for frame %v: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/641f7631059d6bd3.
Report an issue: GitHub.