grafana/k6 · error
response body is unavailable for redirect responses
Error message
response body is unavailable for redirect responses
What it means
Domain guard in Response.Body: k6's browser module refuses to return a body when the response status is in the 3xx range, because Chrome does not reliably expose bodies for redirect responses (the network layer follows redirects internally). Rather than returning empty or stale bytes, the API returns this explicit error telling the caller the body is structurally unavailable for redirects.
Solutions
- Check response.status before calling response.body(); skip body reads for 3xx
- Access the body on the final response after redirects complete, following location manually if needed
- Disable redirect following if the intermediate redirect bodies are required
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/http.go:663 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/650059b0e14378f1.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/http.go:662
headers := make(map[string]string)
r.extraHeadersMu.RLock()
if len(r.extraHeaders) != 0 {
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
}
View on GitHub (pinned to 8d06114777)