grafana/k6 · error
evaluating scroll offset
Error message
evaluating scroll offset: %w
What it means
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.
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
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/screenshotter.go:324 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/9dfb7c27ca2afc34.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/screenshotter.go:346
err = h.waitAndScrollIntoViewIfNeeded(h.ctx, false, true, opts.Timeout)
if err != nil {
return nil, fmt.Errorf("scrolling element into view: %w", err)
}
bbox, err = h.boundingBox()
if err != nil {
return nil, fmt.Errorf("node is either not visible or not an HTMLElement: %w", err)
}
if bbox.Width <= 0 {
return nil, fmt.Errorf("node has 0 width")
}
if bbox.Height <= 0 {
return nil, fmt.Errorf("node has 0 height")
}
}
scrollOffset, err := h.Evaluate(`() => { return {x: window.scrollX, y: window.scrollY};}`)
if err != nil {
return nil, fmt.Errorf("evaluating scroll offset: %w", err)
}
var returnVal Position
if err := convert(scrollOffset, &returnVal); err != nil {
return nil, fmt.Errorf("unpacking scroll offset: %w", err)
}
documentRect := bbox
documentRect.X += returnVal.X
documentRect.Y += returnVal.Y
return s.screenshot(
h.frame.page.session,
documentRect.enclosingIntRect(),
nil, // viewportRect
format,
opts.OmitBackground,
opts.Quality,View on GitHub (pinned to 3fcf5388d7)