fix: retry createTab on transient browser context errors

When one test's session cleanup closes a browser context, the next test's
createTab can fail with 'Target page, context or browser has been closed'
if the browser hasn't fully recovered. Add up to 2 retries with backoff
for 500 errors matching closed/disposed/terminated patterns.
This commit is contained in:
Pradeep Elankumaran
2026-04-25 11:44:41 -07:00
parent 205a697cf9
commit 0b72a23d73
+14 -6
View File
@@ -59,15 +59,23 @@ class BrowserClient {
}
// Tab management
async createTab(url = null) {
async createTab(url = null, { retries = 2 } = {}) {
const body = { userId: this.userId, sessionKey: this.sessionKey };
if (url) body.url = url;
const result = await this.request('POST', '/tabs', body);
if (result.tabId) {
this.tabs.push(result.tabId);
for (let attempt = 0; attempt <= retries; attempt++) {
try {
const result = await this.request('POST', '/tabs', body);
if (result.tabId) {
this.tabs.push(result.tabId);
}
return result;
} catch (err) {
const retriable = err.status === 500 && /closed|disposed|terminated/i.test(err.message);
if (!retriable || attempt === retries) throw err;
await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
}
}
return result;
}
async navigate(tabId, urlOrMacro) {