{"record":{"id":"650059b0e14378f1","repo":"grafana/k6","slug":"response-body-is-unavailable-for-redirect-response","errorCode":null,"errorMessage":"response body is unavailable for redirect responses","messagePattern":"response body is unavailable for redirect responses","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/http.go","lineNumber":662,"sourceCode":"\theaders := make(map[string]string)\n\tr.extraHeadersMu.RLock()\n\tif len(r.extraHeaders) != 0 {\n\t\tfor name, values := range r.extraHeaders {\n\t\t\theaders[strings.ToLower(name)] = strings.Join(values, \"\\n\")\n\t\t}\n\t} else {\n\t\tfor name, values := range r.headers {\n\t\t\theaders[strings.ToLower(name)] = strings.Join(values, \"\\n\")\n\t\t}\n\t}\n\tr.extraHeadersMu.RUnlock()\n\treturn headers\n}\n\n// Body returns the response body as a bytes buffer.\nfunc (r *Response) Body() ([]byte, error) {\n\tif r.status >= 300 && r.status <= 399 {\n\t\treturn nil, fmt.Errorf(\"response body is unavailable for redirect responses\")\n\t}\n\tif err := r.fetchBody(); err != nil {\n\t\treturn nil, fmt.Errorf(\"getting response body: %w\", err)\n\t}\n\n\tr.bodyMu.RLock()\n\tdefer r.bodyMu.RUnlock()\n\n\treturn r.body, nil\n}\n\n// bodySize returns the size in bytes of the response body.\nfunc (r *Response) bodySize() int64 {\n\t// Skip redirect responses\n\tif r.status >= 300 && r.status <= 399 {\n\t\treturn 0\n\t}\n","sourceCodeStart":644,"sourceCodeEnd":680,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/common/http.go#L644-L680","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/http.go:663 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}