perf: freeze background tabs via CDP Page Lifecycle API
Build and Release / build-and-release (push) Failing after 32m2s
Build and Release / build-and-release (push) Failing after 32m2s
This commit is contained in:
+21
-1
@@ -339,19 +339,39 @@ export class TabManager {
|
|||||||
const tab = this.tabs.find(t => t.id === id);
|
const tab = this.tabs.find(t => t.id === id);
|
||||||
if (!tab) return;
|
if (!tab) return;
|
||||||
|
|
||||||
if (this.activeTabId !== null) {
|
if (this.activeTabId !== null && this.activeTabId !== id) {
|
||||||
const prev = this.tabs.find(t => t.id === this.activeTabId);
|
const prev = this.tabs.find(t => t.id === this.activeTabId);
|
||||||
if (prev) {
|
if (prev) {
|
||||||
this.containerView.removeChildView(prev.view);
|
this.containerView.removeChildView(prev.view);
|
||||||
|
this.freezeTab(prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.activeTabId = id;
|
this.activeTabId = id;
|
||||||
|
this.unfreezeTab(tab);
|
||||||
this.containerView.addChildView(tab.view);
|
this.containerView.addChildView(tab.view);
|
||||||
this.updateLayout();
|
this.updateLayout();
|
||||||
this.broadcastTabState();
|
this.broadcastTabState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Freeze/unfreeze background tabs via CDP Page Lifecycle ──
|
||||||
|
private freezeTab(tab: TabInfo): void {
|
||||||
|
const wc = tab.view.webContents;
|
||||||
|
if (wc.isDestroyed()) return;
|
||||||
|
this.stopTitleWatcher(tab.id);
|
||||||
|
try { wc.debugger.attach('1.3'); } catch { /* already attached (DevTools open) */ }
|
||||||
|
wc.debugger.sendCommand('Page.setWebLifecycleState', { state: 'frozen' }).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private unfreezeTab(tab: TabInfo): void {
|
||||||
|
const wc = tab.view.webContents;
|
||||||
|
if (wc.isDestroyed()) return;
|
||||||
|
wc.debugger.sendCommand('Page.setWebLifecycleState', { state: 'active' }).catch(() => {}).finally(() => {
|
||||||
|
try { wc.debugger.detach(); } catch { /* not attached */ }
|
||||||
|
if (!wc.isDestroyed()) this.startTitleWatcher(tab.id, wc);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ── Close a tab ──
|
// ── Close a tab ──
|
||||||
closeTab(id: number): void {
|
closeTab(id: number): void {
|
||||||
const idx = this.tabs.findIndex(t => t.id === id);
|
const idx = this.tabs.findIndex(t => t.id === id);
|
||||||
|
|||||||
Reference in New Issue
Block a user