From 6761968f2d4f8a330d6c183aa8f717ce1798007e Mon Sep 17 00:00:00 2001 From: amhsirak Date: Fri, 7 Mar 2025 22:46:00 +0530 Subject: [PATCH] feat: get active browser id <-> backward compatibility --- .../browser-management/classes/BrowserPool.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server/src/browser-management/classes/BrowserPool.ts b/server/src/browser-management/classes/BrowserPool.ts index 3c86a220..77c3a637 100644 --- a/server/src/browser-management/classes/BrowserPool.ts +++ b/server/src/browser-management/classes/BrowserPool.ts @@ -293,5 +293,22 @@ export class BrowserPool { return browserIds.length > 0 ? browserIds[0] : null; }; - + /** + * Returns the first active browser's instance id from the pool. + * If there is no active browser, it returns null. + * If there are multiple active browsers, it returns the first one. + * + * @returns the first remote active browser instance's id from the pool + * @deprecated Use getBrowserIdForUser instead to enforce the 1 User - 1 Browser policy + */ + public getActiveBrowserIdDep = (): string | null => { + for (const id of Object.keys(this.pool)) { + if (this.pool[id].active) { + return id; + } + } + // Don't log a warning since this behavior is expected in the user-browser model + // logger.log('warn', `No active browser in the pool`); + return null; + }; } \ No newline at end of file