grafana/k6 · error

checking element is hidden: %w

Error message

checking element is hidden: %w

What it means

Returned by ElementHandle.isHidden() when the state probe fails with a non-timeout error. Timeout errors are deliberately ignored (hiding is evaluated with a 0 timeout), so this error signals an operational failure: stale/detached handle, destroyed execution context, CDP transport error, or closed page/browser - not merely that the element is visible.

Source

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

}

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

	return ok, nil
}

// 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) {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-query the handle immediately before isHidden()
  2. Wait for the element to be attached if it may not exist yet
  3. Ensure the page is still open before probing
  4. Distinguish the thrown error (operational) from a false return (element visible)

Example fix

// before
const hidden = await h.isHidden(); // stale handle
// after
const el = await page.$('#modal');
const hidden = await el.isHidden();
Defensive patterns

Strategy: try-catch

Validate before calling

const el = await page.$('#modal');
if (el) {
  const hidden = await el.isHidden();
}

Try / catch

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

Prevention

When it happens

Trigger: Calling isHidden() on a handle whose node was removed; after a navigation destroyed the context; after the page was closed; when the browser crashed or the session dropped.

Common situations: Checking visibility of list items in re-rendering SPAs with cached handles; probing after a redirect; teardown races when the browser closes before the last assertion.

Related errors


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