{"record":{"id":"9dfb7c27ca2afc34","repo":"grafana/k6","slug":"evaluating-scroll-offset-w","errorCode":null,"errorMessage":"evaluating scroll offset: %w","messagePattern":"evaluating scroll offset: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/screenshotter.go","lineNumber":346,"sourceCode":"\t\terr = h.waitAndScrollIntoViewIfNeeded(h.ctx, false, true, opts.Timeout)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scrolling element into view: %w\", err)\n\t\t}\n\t\tbbox, err = h.boundingBox()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"node is either not visible or not an HTMLElement: %w\", err)\n\t\t}\n\t\tif bbox.Width <= 0 {\n\t\t\treturn nil, fmt.Errorf(\"node has 0 width\")\n\t\t}\n\t\tif bbox.Height <= 0 {\n\t\t\treturn nil, fmt.Errorf(\"node has 0 height\")\n\t\t}\n\t}\n\n\tscrollOffset, err := h.Evaluate(`() => { return {x: window.scrollX, y: window.scrollY};}`)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"evaluating scroll offset: %w\", err)\n\t}\n\n\tvar returnVal Position\n\tif err := convert(scrollOffset, &returnVal); err != nil {\n\t\treturn nil, fmt.Errorf(\"unpacking scroll offset: %w\", err)\n\t}\n\n\tdocumentRect := bbox\n\tdocumentRect.X += returnVal.X\n\tdocumentRect.Y += returnVal.Y\n\n\treturn s.screenshot(\n\t\th.frame.page.session,\n\t\tdocumentRect.enclosingIntRect(),\n\t\tnil, // viewportRect\n\t\tformat,\n\t\topts.OmitBackground,\n\t\topts.Quality,","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/screenshotter.go#L328-L364","documentation":"Raised in screenshotElement when evaluating the inline JavaScript expression `() => { return {x: window.scrollX, y: window.scrollY};}` via Runtime.evaluate fails. The scroll offset is needed to convert the element's viewport-relative bounding box into document coordinates for clipping. This fires when the JS evaluation is rejected — most commonly because the frame's execution context was destroyed by a navigation, the page is closing, or the CDP session is broken.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/screenshotter.go:324 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Avoid navigating or reloading the page concurrently with the screenshot call","Retry the screenshot after the page has finished loading (waitForNavigation/waitForLoadState first)","Verify the element is still attached to the DOM before screenshotting","Inspect the wrapped CDP error for the exact evaluation failure reason"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}