mirror of
https://github.com/jo-inc/camofox-browser.git
synced 2026-10-02 04:14:41 +08:00
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:
+14
-6
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user