Error Handling
Retry mechanism
The SDK has built-in retry support. When script() throws an error, the SDK will automatically retry the entire profile (open browser β run script β close browser).
Configure via execution params:
const params = {
execution: {
concurrency: 3,
maxRetries: 2, // retry failed profiles up to 2 times
keepOpenOnError: false, // close browser on error (default)
},
}Log output during retry:
β Login failed β retrying in 2s...
π Retrying... (1/2)Example 1 β Auto retry
async script(context) {
const browser = new BrowserUtils(context)
await browser.goto(context.globalInput.targetUrl)
// If this returns false β throw to trigger retry
const loggedIn = await browser.exists('#dashboard', 15000)
if (!loggedIn) throw new Error('Dashboard not found β will retry')
// SDK will retry script() up to maxRetries times
}Example 2 β Custom error handling (no retry)
async script(context) {
const browser = new BrowserUtils(context)
const ok = await browser.goto('https://example.com')
if (!ok) {
// Log error but don't throw β prevents retry
await browser.writeOutput('loginStatus', 'Navigation failed')
await browser.screenshot('error.png')
return // exit gracefully
}
await browser.writeOutput('loginStatus', 'Success')
}keepOpenOnError
When true, the browser window stays open after an error β useful for debugging.
Log output: β οΈ Keeping browser open for debug (keepOpenOnError=true).
Example 1 β Debug mode
const params = {
execution: {
concurrency: 1,
keepOpenOnError: true, // browser stays open for inspection
},
}Example 2 β Production mode
const params = {
execution: {
concurrency: 5,
keepOpenOnError: false, // close immediately to free resources
maxRetries: 3,
},
}Abort / Cancel
Flows can be cancelled externally (from the desktop app or agent). The SDK checks for abort signals before every action in BrowserUtils. When cancelled, it throws Error('cancelled') which is not retried.
Profile event: Stopped. (status: cancelled)
Best Practices
- Check return values β
click(),goto(),type()returnboolean, use them instead of try/catch - Use
exists()beforeclick()β handle optional elements gracefully - Write output before throwing β ensures partial results are saved
- Use screenshots for debugging β
browser.screenshot('step-name.png') - Set reasonable timeouts β donβt wait forever for elements
Last updated on