From 6d75520cdff8b879116c2cab8c400812e0b5ad91 Mon Sep 17 00:00:00 2001 From: Rohit Date: Mon, 11 Aug 2025 13:01:31 +0530 Subject: [PATCH] feat: add browser status method --- .../browser-management/classes/BrowserPool.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/server/src/browser-management/classes/BrowserPool.ts b/server/src/browser-management/classes/BrowserPool.ts index e6dcf6b8..eb99f2df 100644 --- a/server/src/browser-management/classes/BrowserPool.ts +++ b/server/src/browser-management/classes/BrowserPool.ts @@ -221,6 +221,12 @@ export class BrowserPool { 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; }; @@ -607,8 +613,13 @@ export class BrowserPool { * @returns true if successful, false if slot wasn't reserved */ public upgradeBrowserSlot = (id: string, browser: RemoteBrowser): boolean => { - if (!this.pool[id] || this.pool[id].status !== "reserved") { - logger.log('warn', `Cannot upgrade browser ${id}: slot not reserved`); + if (!this.pool[id]) { + 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; } @@ -629,4 +640,17 @@ export class BrowserPool { 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; + }; } \ No newline at end of file