{"record":{"id":"dd6bdce4982b3d21","repo":"grafana/k6","slug":"getting-response-body-as-text-w","errorCode":null,"errorMessage":"getting response body as text: %w","messagePattern":"getting response body as text: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/http.go","lineNumber":820,"sourceCode":"\t\tBody:    r.bodySize(),\n\t\tHeaders: r.headersSize(),\n\t}\n}\n\n// Status returns the response status code.\nfunc (r *Response) Status() int64 {\n\treturn r.status\n}\n\n// StatusText returns the response status text.\nfunc (r *Response) StatusText() string {\n\treturn r.statusText\n}\n\n// Text returns the response body as a string.\nfunc (r *Response) Text() (string, error) {\n\tif err := r.fetchBody(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting response body as text: %w\", err)\n\t}\n\n\tr.bodyMu.RLock()\n\tdefer r.bodyMu.RUnlock()\n\n\treturn string(r.body), nil\n}\n\n// URL returns the request URL.\nfunc (r *Response) URL() string {\n\treturn r.url\n}\n\n// Route allows to handle a request.\ntype Route struct {\n\tlogger         *log.Logger\n\tnetworkManager *NetworkManager\n","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/common/http.go#L802-L838","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/http.go:821 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the body right after receiving the response instead of after subsequent navigations","Keep the page open until all response reads finish","Retry the request if the error is transient","Check the wrapped CDP error to distinguish cache eviction from a 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"}