grafana/k6 · error
getting document
Error message
getting document: %w
What it means
Returned by Frame.count when Frame.document fails to provide the document element handle needed to run the count evaluation in the frame's main world. The wrap marks the dependency; the real cause (no execution context, navigation race, CDP error) is in the wrapped error.
Solutions
- Wait for the frame to load before counting
- Retry after navigation settles
- Verify the frame is attached
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/frame.go:636 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/c7d822755cdac996.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/frame.go:644
click := func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {
return nil, handle.click(p, opts.ToMouseClickOptions())
}
act := f.newPointerAction(
selector, DOMElementStateAttached, opts.Strict, click, &opts.ElementHandleBasePointerOptions,
)
if _, err := call(f.ctx, act, opts.Timeout); err != nil {
return errorFromDOMError(err)
}
return nil
}
func (f *Frame) count(selector string) (int, error) {
f.log.Debugf("Frame:count", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)
document, err := f.document()
if err != nil {
return 0, fmt.Errorf("getting document: %w", err)
}
c, err := document.count(f.ctx, selector)
if err != nil {
return 0, fmt.Errorf("counting elements: %w", err)
}
return c, nil
}
// Check clicks the first element found that matches selector.
func (f *Frame) Check(selector string, popts *FrameCheckOptions) error {
f.log.Debugf("Frame:Check", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)
if err := f.check(selector, popts); err != nil {
return fmt.Errorf("checking %q: %w", selector, err)
}
View on GitHub (pinned to 3fcf5388d7)