From e9d3fcebad909aa3aa94ff479537f992f467e853 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Fri, 7 Mar 2025 22:42:49 +0530 Subject: [PATCH] feat: get active browser id --- .../browser-management/classes/BrowserPool.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/src/browser-management/classes/BrowserPool.ts b/server/src/browser-management/classes/BrowserPool.ts index d260f16d..e09f96ef 100644 --- a/server/src/browser-management/classes/BrowserPool.ts +++ b/server/src/browser-management/classes/BrowserPool.ts @@ -160,5 +160,28 @@ export class BrowserPool { return this.pool[id]?.browser; }; + /** + * Returns the active browser's instance id for a specific user. + * + * @param userId the user ID to find the browser for + * @returns the browser ID for the user, or null if no browser exists + */ + public getActiveBrowserId = (userId: string): string | null => { + const browserId = this.userToBrowserMap.get(userId); + if (!browserId) { + logger.log('debug', `No browser found for user: ${userId}`); + return null; + } + + // Verify the browser still exists in the pool + if (!this.pool[browserId]) { + this.userToBrowserMap.delete(userId); + logger.log('warn', `Browser mapping found for user: ${userId}, but browser doesn't exist in pool`); + return null; + } + console.log(`Browser Id ${browserId} found for user: ${userId}`); + return browserId; + }; + } \ No newline at end of file