{"record":{"id":"87cfeea60d66bc41","repo":"grafana/k6","slug":"fetching-response-body-w","errorCode":null,"errorMessage":"fetching response body: %w","messagePattern":"fetching response body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/http.go","lineNumber":610,"sourceCode":"\tvar body []byte\n\tvar err error\n\tmaxRetries := 5\n\tfor i := 0; i <= maxRetries; i++ {\n\t\tbody, err = action.Do(cdp.WithExecutor(r.ctx, r.request.frame.manager.session))\n\t\tif err == nil {\n\t\t\tbreak\n\t\t}\n\t\tif strings.Contains(err.Error(), \"No data found for resource with given identifier\") {\n\t\t\tif i == maxRetries {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\ttime.Sleep(100 * time.Millisecond)\n\t\t\tcontinue\n\t\t}\n\t\tbreak\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"fetching response body: %w\", err)\n\t}\n\tr.bodyMu.Lock()\n\tr.body = body\n\tr.bodyMu.Unlock()\n\n\treturn nil\n}\n\nfunc (r *Response) headersSize() int64 {\n\tsize := 4 // 4 = 2 spaces + 2 line breaks (HTTP/1.1 200 OK\\r\\n)\n\tsize += 8 // httpVersion\n\tsize += 3 // statusCode\n\tsize += len(r.statusText)\n\tr.extraHeadersMu.RLock()\n\tif len(r.extraHeaders) != 0 {\n\t\tfor name, values := range r.extraHeaders {\n\t\t\tfor _, value := range values {\n\t\t\t\tsize += len(name) + len(value) + 4 // 4 = ': ' + '\\r\\n'","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/http.go#L592-L628","documentation":"Response bodies are fetched lazily over CDP with Network.getResponseBody on the frame manager's session. fetchBody first returns any cached body, then retries up to 5 times with 100ms sleeps specifically for 'No data found for resource with given identifier' (body not yet flushed). This error means the final attempt still failed: the body is genuinely unavailable or the session is gone.","triggerScenarios":"The frame's manager session cannot serve GetResponseBody: the page navigated away or closed before the body was read, the request was fulfilled by route.fulfill() so no network data exists, the response came from cache/service worker without retrievable body, or the target/browser died.","commonSituations":"Reading res.body()/text()/json() late in the iteration after further navigation; intercepted requests handled with page.route; service-worker-backed responses; calling body accessors after context/page teardown; heavy parallelism causing the browser to drop.","solutions":["Read the response body immediately after obtaining the Response, before further navigation or closing the page","For intercepted/fulfilled requests, use the content you supplied to fulfill() instead of reading it back through the browser API","Check the response status and whether the request was cached before attempting a body read","Keep the browser/context alive until all assertions on bodies complete"],"exampleFix":"// before\nconst res = await page.goto('https://app.example.com');\nawait page.goto('https://app.example.com/next');\nconst body = await res.body(); // frame may be gone\n\n// after\nconst res = await page.goto('https://app.example.com');\nconst body = await res.body(); // read immediately\nawait page.goto('https://app.example.com/next');","handlingStrategy":"retry","validationCode":"// read bodies before navigating further\nconst res = await page.goto(url);\nconst body = await res.body(); // immediate read","typeGuard":null,"tryCatchPattern":"let body;\nfor (let i = 0; i < 2; i++) {\n  try { body = await res.body(); break; }\n  catch (e) {\n    if (i === 1 || !/fetching response body/.test(String(e.message))) throw e;\n    await page.waitForTimeout(200);\n  }\n}","preventionTips":["Read response bodies immediately after receiving them","Do not read bodies for route.fulfill()-ed requests","Keep page and context open until body assertions finish"],"tags":["browser","network","response-body","cdp","lazy-fetch"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}