grafana/k6 · error

checking is in viewport

Error message

checking is %q in viewport: %w

What it means

Wrapped failure from Frame.isInViewport while computing the viewport-intersection ratio of the element matched by the locator's selector (strict mode forced). Fires when the selector matches nothing or multiple elements, the element is detached, or the bounding-box/intersection evaluation via CDP fails.

Solutions

  1. Use a unique selector or narrow with nth()/filter to satisfy strict mode
  2. Ensure the element is attached and laid out before checking viewport intersection
  3. Verify the page finished loading so viewport dimensions are final
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/locator.go:270 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/2e0ba625a0d2366f. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/locator.go:270

	opts.Strict = true
	disabled, err := l.frame.isDisabled(l.selector, opts)
	if err != nil {
		return false, fmt.Errorf("checking is %q disabled: %w", l.selector, err)
	}

	return disabled, nil
}

// IsInViewport returns true if the element matches the locator's selector and
// intersects the viewport by at least the requested ratio. Otherwise, returns
// false.
func (l *Locator) IsInViewport(opts *FrameIsInViewportOptions) (bool, error) {
	l.log.Debugf("Locator:IsInViewport", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)

	opts.Strict = true
	inViewport, err := l.frame.isInViewport(l.selector, opts)
	if err != nil {
		return false, fmt.Errorf("checking is %q in viewport: %w", l.selector, err)
	}

	return inViewport, nil
}

// IsVisible returns true if the element matches the locator's
// selector and is visible. Otherwise, returns false.
func (l *Locator) IsVisible() (bool, error) {
	l.log.Debugf("Locator:IsVisible", "fid:%s furl:%q sel:%q", l.frame.ID(), l.frame.URL(), l.selector)

	visible, err := l.frame.isVisible(l.selector, &FrameIsVisibleOptions{Strict: true})
	if err != nil {
		return false, fmt.Errorf("checking is %q visible: %w", l.selector, err)
	}

	return visible, nil
}

View on GitHub (pinned to 01ffac6f24)