fix: add PageRegistry.clear() and getAll(), fix BrowserManager.cleanup() to clear registry
This commit is contained in:
@@ -90,10 +90,10 @@ export class BrowserManager {
|
|||||||
|
|
||||||
async cleanup(): Promise<void> {
|
async cleanup(): Promise<void> {
|
||||||
// Close all contexts / 关闭所有上下文
|
// Close all contexts / 关闭所有上下文
|
||||||
const entries = this.registry['pages']?.values() ?? [];
|
for (const entry of this.registry.getAll()) {
|
||||||
for (const entry of entries) {
|
|
||||||
try { await entry.context.close(); } catch { /* ignore / 忽略 */ }
|
try { await entry.context.close(); } catch { /* ignore / 忽略 */ }
|
||||||
}
|
}
|
||||||
|
this.registry.clear();
|
||||||
if (this.browser) {
|
if (this.browser) {
|
||||||
await this.browser.close();
|
await this.browser.close();
|
||||||
this.browser = null;
|
this.browser = null;
|
||||||
|
|||||||
@@ -45,4 +45,15 @@ export class PageRegistry {
|
|||||||
hasAlias(alias: string): boolean {
|
hasAlias(alias: string): boolean {
|
||||||
return this.aliasMap.has(alias);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user