fix: reuse external browsers for element pickup
This commit is contained in:
1 parent
927b18551f
commit
d39c77324a
4 files changed
+63
-11
No files matched your search
@@ -166,6 +166,16 @@ export class BrowserSession implements BrowserLike {
|
||||
}
|
||||
|
||||
/** 当前会话是否为外部浏览器 */
|
||||
/** 会话底层 CDP 是否已断开(缓存清理用) */
|
||||
get closed(): boolean {
|
||||
return this.transport.closed;
|
||||
}
|
||||
|
||||
/** 缓存键,外部会话排序用 */
|
||||
get sessionKey(): string {
|
||||
return this.externalKey;
|
||||
}
|
||||
|
||||
get isExternal(): boolean {
|
||||
return this.external !== null;
|
||||
}
|
||||
@@ -1370,6 +1380,16 @@ export async function externalBrowserSession(options: ExternalBrowserOptions): P
|
||||
return BrowserSession.createExternal(options);
|
||||
}
|
||||
|
||||
export function listExternalSessions(): BrowserSession[] {
|
||||
return [...externalSessionCache().values()]
|
||||
.filter((session) => session.isExternal && !session.closed)
|
||||
.sort((left, right) => right.sessionKey.localeCompare(left.sessionKey));
|
||||
}
|
||||
|
||||
export function latestExternalSession(): BrowserSession | null {
|
||||
return listExternalSessions()[0] || null;
|
||||
}
|
||||
|
||||
export function hasBrowserSession(): boolean {
|
||||
return Boolean(globalThis.__rpaBrowserWindow && !globalThis.__rpaBrowserWindow.isDestroyed());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user