{"record":{"id":"641f7631059d6bd3","repo":"grafana/k6","slug":"getting-response-body-w","errorCode":null,"errorMessage":"getting response body: %w","messagePattern":"getting response body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/http.go","lineNumber":665,"sourceCode":"\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\n\tif err := r.fetchBody(); err != nil {\n\t\tr.logger.Debugf(\"Response:bodySize:fetchBody\",\n\t\t\t\"url:%s method:%s err:%s\", r.url, r.request.method, err)","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/common/http.go#L647-L683","documentation":"Wrap of Response.fetchBody in the public Body() accessor: after the redirect-status guard passes, the CDP body fetch (with its internal retries) still failed, and this wrap adds the \"getting response body\" context to the underlying error. Root causes are the same as the wrapped fetchBody failure — session closed, response evicted from the browser cache, or no body for the resource.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/http.go:666 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the body immediately after the response arrives rather than after later page activity","Verify the browser session and page are still open at read time","Retry the navigation/request if the failure is transient","Inspect the wrapped error for the specific CDP reason (cache miss vs. closed session)"],"exampleFix":null,"handlingStrategy":"retry","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"}