fix: add PageRegistry.clear() and getAll(), fix BrowserManager.cleanup() to clear registry

This commit is contained in:
2026-08-12 20:56:16 +08:00
parent ac503a5ca3
commit dd79194179
2 changed files with 13 additions and 2 deletions
+2 -2
View File
@@ -90,10 +90,10 @@ export class BrowserManager {
async cleanup(): Promise<void> {
// Close all contexts / 关闭所有上下文
const entries = this.registry['pages']?.values() ?? [];
for (const entry of entries) {
for (const entry of this.registry.getAll()) {
try { await entry.context.close(); } catch { /* ignore / 忽略 */ }
}
this.registry.clear();
if (this.browser) {
await this.browser.close();
this.browser = null;
+11
View File
@@ -45,4 +45,15 @@ export class PageRegistry {
hasAlias(alias: string): boolean {
return this.aliasMap.has(alias);
}
/** Return all registered entries for iteration / 返回所有已注册条目用于遍历 */
getAll(): RegisteredPage[] {
return Array.from(this.pages.values());
}
/** Clear all entries / 清除所有条目 */
clear(): void {
this.pages.clear();
this.aliasMap.clear();
}
}