sincecutoff.com
← all changes

k6 browser locator.isInViewport method

Introduced 2026-06-30 · score 0.94

HOW TO USE IT

When a browser test should interact with an element only if it intersects the viewport, call `locator.isInViewport()` and act on its boolean result. Set `ratio` for a visibility threshold; the check measures once after attachment.

const button = page.locator('button#submit'); if (await button.isInViewport()) { await button.click(); }

WHY THIS HELPS

Check whether a browser element is visible in the viewport before interacting with it.

REQUIREMENTS AND LIMITATIONS

  • Version: v2.1.0
  • options: Optional options object for the check.
  • options.ratio: Minimum element ratio in the viewport, from 0 to 1; default 0 means any visible pixel counts.
  • options.timeout: Maximum wait in milliseconds; default 30000. Set 0 to disable; BrowserContext or Page `setDefaultTimeout` overrides the default.
  • The call measures the intersection once after the element attaches.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card