grafana/k6 · error

checking element is visible: %w

Error message

checking element is visible: %w

What it means

Returned by ElementHandle.isVisible() when the state probe fails with a non-timeout error. Timeouts are intentionally ignored (the probe uses a 0 timeout; a timeout just means 'not visible right now' and returns false), so this error means the probe itself failed: stale handle, destroyed execution context, CDP failure, or closed page/browser.

Source

Thrown at internal/js/modules/k6/browser/common/element_handle.go:1113

}

// IsHidden checks if the element is hidden.
func (h *ElementHandle) IsHidden() (bool, error) {
	ok, err := h.isHidden(h.ctx)
	// We don't care anout timeout errors here!
	if err != nil && !errors.Is(err, ErrTimedOut) {
		return false, fmt.Errorf("checking element is hidden: %w", err)
	}

	return ok, nil
}

// IsVisible checks if the element is visible.
func (h *ElementHandle) IsVisible() (bool, error) {
	ok, err := h.isVisible(h.ctx)
	// We don't care anout timeout errors here!
	if err != nil && !errors.Is(err, ErrTimedOut) {
		return false, fmt.Errorf("checking element is visible: %w", err)
	}

	return ok, nil
}

// OwnerFrame returns the frame containing this element.
func (h *ElementHandle) OwnerFrame() (_ *Frame, rerr error) {
	fn := `
		(node, injected) => {
			return injected.getDocumentElement(node);
		}
	`
	opts := evalOptions{
		forceCallable: true,
		returnByValue: false,
	}
	res, err := h.evalWithScript(h.ctx, opts, fn)
	if err != nil {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-query the handle right before isVisible()
  2. Wait for the element if its existence is uncertain: page.waitForSelector(sel, { state: 'attached' })
  3. Confirm the page is still open before probing
  4. Handle the thrown error separately from a false result

Example fix

// before
const visible = await h.isVisible(); // stale handle
// after
const el = await page.$('#banner');
const visible = await el.isVisible();
Defensive patterns

Strategy: try-catch

Validate before calling

const el = await page.$('#banner');
if (el) {
  const visible = await el.isVisible();
}

Try / catch

try {
  return await handle.isVisible();
} catch (e) {
  if (String(e).includes('checking element is visible')) {
    const fresh = await page.$(sel);
    return fresh ? fresh.isVisible() : false;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling isVisible() on a detached handle or one captured before navigation; while the page navigates; after page.close(); when the CDP session dropped or the browser crashed.

Common situations: Cached handles invalidated by SPA re-renders; visibility checks racing redirects; browser shutdown before the final check completes.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/eecbfa6713d65c09. Report an issue: GitHub.