feat: get active browser id

This commit is contained in:
amhsirak
2025-03-07 22:42:49 +05:30
parent 63e48cead7
commit e9d3fcebad

View File

@@ -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;
};
}