Spotted something off?Report on Discord
guides

While Loop

Repeat browser actions in a loop until a JavaScript condition evaluates to false.

Updated May 28, 2025

Repeat a set of browser actions until a specific condition is no longer true.

Command

"while"

Use this command to perform looping logic within the browser context. It's useful for tasks like handling CAPTCHAs, paginated scraping, or waiting for content to disappear/appear. It's the looping counterpart to the if conditional, and one of the browser actions.

Parameters

Parameter Type Required Description
condition string Yes A JavaScript expression that returns true or false. The loop continues as long as it evaluates to true.
then array Yes Array of browser actions to execute on each iteration while the condition is true.
maxAttempts number No Max number of loop iterations to prevent infinite loops.

Example

bash22 lines
Want to run this request directly in your browser?to try it live with your own API key.

Notes

  • You can combine this with other browser actions like click, type, goto, wait, or even another if or while block.
  • Always consider setting a maxAttempts to avoid infinite loops and excessive resource usage.
  • Use Case Ideas: looping through paginated content until no "Next" button appears, retrying CAPTCHA verification handling until successful, or waiting for an element to disappear before proceeding.