feat: add browser status method

This commit is contained in:
Rohit
2025-08-11 13:01:31 +05:30
parent 2a302c859e
commit 6d75520cdf

View File

@@ -221,6 +221,12 @@ export class BrowserPool {
return undefined; return undefined;
} }
// Return undefined for failed slots
if (poolInfo.status === "failed") {
logger.log('debug', `Browser ${id} has failed status`);
return undefined;
}
return poolInfo.browser || undefined; return poolInfo.browser || undefined;
}; };
@@ -607,8 +613,13 @@ export class BrowserPool {
* @returns true if successful, false if slot wasn't reserved * @returns true if successful, false if slot wasn't reserved
*/ */
public upgradeBrowserSlot = (id: string, browser: RemoteBrowser): boolean => { public upgradeBrowserSlot = (id: string, browser: RemoteBrowser): boolean => {
if (!this.pool[id] || this.pool[id].status !== "reserved") { if (!this.pool[id]) {
logger.log('warn', `Cannot upgrade browser ${id}: slot not reserved`); logger.log('warn', `Cannot upgrade browser ${id}: slot does not exist in pool`);
return false;
}
if (this.pool[id].status !== "reserved") {
logger.log('warn', `Cannot upgrade browser ${id}: slot not in reserved state (current: ${this.pool[id].status})`);
return false; return false;
} }
@@ -629,4 +640,17 @@ export class BrowserPool {
this.deleteRemoteBrowser(id); this.deleteRemoteBrowser(id);
} }
}; };
/**
* Gets the current status of a browser slot.
*
* @param id browser ID to check
* @returns the status or null if browser doesn't exist
*/
public getBrowserStatus = (id: string): "reserved" | "initializing" | "ready" | "failed" | null => {
if (!this.pool[id]) {
return null;
}
return this.pool[id].status || null;
};
} }