glidercli 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/glider.js +130 -0
- package/lib/paths.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,7 +147,7 @@ glider resolve https://news.ycombinator.com --json
|
|
|
147
147
|
| Env | Default | Role |
|
|
148
148
|
|-----|---------|------|
|
|
149
149
|
| `GLIDER_HOME` | `~/.glider` | config, cache, warch tree |
|
|
150
|
-
| `AGREGISTRY` | unset | optional registry root → warch at
|
|
150
|
+
| `AGREGISTRY` | unset | optional registry root → warch at `AGREGISTRY/warch/HOST/` |
|
|
151
151
|
|
|
152
152
|
Copy `config/domains.template.json` into `~/.glider/config/domains.json` to seed the host index.
|
|
153
153
|
|
package/bin/glider.js
CHANGED
|
@@ -1623,6 +1623,132 @@ async function cmdThaw(opts = []) {
|
|
|
1623
1623
|
}
|
|
1624
1624
|
}
|
|
1625
1625
|
|
|
1626
|
+
// Freeze a hidden/background tab IN PLACE: Chrome's Page lifecycle 'frozen' state
|
|
1627
|
+
// halts the tab's task queues (timers, rAF, fetch, workers, further JS allocation)
|
|
1628
|
+
// without killing the renderer. Reverse of `glider thaw`. Idempotent. The tab
|
|
1629
|
+
// auto-resumes ('active') on focus or via `glider thaw`; DOM/scroll/form state is
|
|
1630
|
+
// preserved.
|
|
1631
|
+
//
|
|
1632
|
+
// WHAT IT IS FOR: CONTAINMENT, not reclaim. Freezing a background tab that is
|
|
1633
|
+
// actively burning CPU or leaking (heap growing in a rAF/timer loop) stops the
|
|
1634
|
+
// bleed. It does NOT by itself free existing memory. Empirically (native-port A/B,
|
|
1635
|
+
// Runtime.getHeapUsage + process-tree RSS): unreachable JS heap is reclaimed by
|
|
1636
|
+
// V8's own GC / memory-reducer (idle GC ~10s on a live tab) whether or not you
|
|
1637
|
+
// freeze; and a loaded tab's real footprint (live DOM, decoded images, compositor)
|
|
1638
|
+
// is not released by ANY V8 lever while the document is alive - only discard /
|
|
1639
|
+
// navigate (which loses page state) frees that. `--verify` prints a before/after
|
|
1640
|
+
// heap delta, but that delta is V8 GC of the now-quiesced tab, not a freeze-
|
|
1641
|
+
// specific reclaim.
|
|
1642
|
+
//
|
|
1643
|
+
// WALLS (recorded in capabilities.json): via the extension chrome.debugger bridge
|
|
1644
|
+
// the Memory + HeapProfiler domains are BLOCKED by Chromium (JSON-RPC -32601 "wasn't
|
|
1645
|
+
// found"); Memory.forciblyPurgeJavaScriptMemory / HeapProfiler.collectGarbage exist
|
|
1646
|
+
// only on the native --remote-debugging-port. Even there, forciblyPurge reclaims
|
|
1647
|
+
// nothing beyond an explicit GC for JS heap and does not touch DOM/image/renderer
|
|
1648
|
+
// memory of a loaded page (proven: Wikipedia tab, GC 52->1MB JS but RSS -5MB only,
|
|
1649
|
+
// purge +0). Freeze (Page domain) is what the CRX bridge CAN reach.
|
|
1650
|
+
//
|
|
1651
|
+
// Safety: NEVER freezes the visible/active tab (--force overrides). --fat-mb gates
|
|
1652
|
+
// to tabs whose heap backingStorage >= N MB.
|
|
1653
|
+
async function cmdFreeze(opts = []) {
|
|
1654
|
+
let sessionId = null;
|
|
1655
|
+
let all = false;
|
|
1656
|
+
let verify = false;
|
|
1657
|
+
let force = false;
|
|
1658
|
+
let fatMb = 0;
|
|
1659
|
+
for (let i = 0; i < opts.length; i++) {
|
|
1660
|
+
const a = opts[i];
|
|
1661
|
+
if (a === '--session' || a === '--sessionId') sessionId = opts[++i];
|
|
1662
|
+
else if (a === '--all') all = true;
|
|
1663
|
+
else if (a === '--verify') verify = true;
|
|
1664
|
+
else if (a === '--force') force = true;
|
|
1665
|
+
else if (a === '--fat-mb') fatMb = parseInt(opts[++i], 10) || 0;
|
|
1666
|
+
else if (a === '--help') {
|
|
1667
|
+
console.log('Usage: glider freeze [--session <id>] [--all] [--fat-mb N] [--verify] [--force]');
|
|
1668
|
+
console.log(' Halt a hidden/background tab in place (stop timers/rAF/fetch/JS alloc) to');
|
|
1669
|
+
console.log(' CONTAIN a runaway or leaking bg tab. Reverse of thaw; auto-resumes on focus.');
|
|
1670
|
+
console.log(' Not a heap reclaimer: V8 GC handles dead heap; only discard frees live DOM/images.');
|
|
1671
|
+
console.log(' --all freeze every hidden attached tab (skips the visible one)');
|
|
1672
|
+
console.log(' --fat-mb N only freeze tabs whose heap backingStorage >= N MB (default 0)');
|
|
1673
|
+
console.log(' --verify print before/after heap delta (V8 GC of quiesced tab, not freeze-reclaim)');
|
|
1674
|
+
console.log(' --force also freeze the visible tab (DANGER: hangs current page)');
|
|
1675
|
+
console.log(' Reverse of `glider thaw`. Idempotent.');
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
if (!await ensureConnected()) process.exit(1);
|
|
1680
|
+
|
|
1681
|
+
const heapMb = async (sid) => {
|
|
1682
|
+
const p = { method: 'Runtime.getHeapUsage', params: {} };
|
|
1683
|
+
if (sid) p.sessionId = sid;
|
|
1684
|
+
try {
|
|
1685
|
+
const r = await httpPost('/cdp', p);
|
|
1686
|
+
const bs = r?.backingStorageSize ?? r?.result?.backingStorageSize;
|
|
1687
|
+
return typeof bs === 'number' ? Math.round(bs / 1048576) : null;
|
|
1688
|
+
} catch { return null; }
|
|
1689
|
+
};
|
|
1690
|
+
const visState = async (sid) => {
|
|
1691
|
+
const p = { method: 'Runtime.evaluate', params: { expression: `document.visibilityState`, returnByValue: true } };
|
|
1692
|
+
if (sid) p.sessionId = sid;
|
|
1693
|
+
try { const r = await httpPost('/cdp', p); return r?.result?.value || null; } catch { return null; }
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
let targets;
|
|
1697
|
+
if (all) {
|
|
1698
|
+
const raw = await httpGet('/targets');
|
|
1699
|
+
targets = (Array.isArray(raw) ? raw : [])
|
|
1700
|
+
.map((t) => ({ sid: t.sessionId, pid: t.targetInfo && t.targetInfo.pid, url: (t.targetInfo && t.targetInfo.url) || '' }))
|
|
1701
|
+
.filter((t) => t.sid);
|
|
1702
|
+
if (!targets.length) { log.warn('No targets to freeze'); return; }
|
|
1703
|
+
} else {
|
|
1704
|
+
targets = [{ sid: sessionId || activeSessionId || null, pid: null, url: '' }];
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
const results = [];
|
|
1708
|
+
let totalReclaimed = 0;
|
|
1709
|
+
for (const t of targets) {
|
|
1710
|
+
const sid = t.sid;
|
|
1711
|
+
const vis = await visState(sid);
|
|
1712
|
+
if (vis === 'visible' && !force) {
|
|
1713
|
+
results.push({ sessionId: sid || '(pinned)', frozen: false, skipped: 'visible' });
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
const before = await heapMb(sid);
|
|
1717
|
+
if (fatMb > 0 && before !== null && before < fatMb) {
|
|
1718
|
+
results.push({ sessionId: sid || '(pinned)', frozen: false, skipped: `under_fat_mb(${before}<${fatMb})` });
|
|
1719
|
+
continue;
|
|
1720
|
+
}
|
|
1721
|
+
const p = { method: 'Page.setWebLifecycleState', params: { state: 'frozen' } };
|
|
1722
|
+
if (sid) p.sessionId = sid;
|
|
1723
|
+
try {
|
|
1724
|
+
const r = await httpPost('/cdp', p);
|
|
1725
|
+
if (r && r.error && !(r.result)) throw new Error(typeof r.error === 'string' ? r.error : JSON.stringify(r.error));
|
|
1726
|
+
const entry = { sessionId: sid || activeSessionId || '(pinned)', pid: t.pid || undefined, frozen: true, beforeMb: before };
|
|
1727
|
+
if (verify) {
|
|
1728
|
+
const after = await heapMb(sid);
|
|
1729
|
+
entry.afterMb = after;
|
|
1730
|
+
if (before !== null && after !== null) { entry.reclaimedMb = before - after; totalReclaimed += Math.max(0, before - after); }
|
|
1731
|
+
}
|
|
1732
|
+
results.push(entry);
|
|
1733
|
+
} catch (e) {
|
|
1734
|
+
results.push({ sessionId: sid || '(pinned)', frozen: false, error: e.message });
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
if (jsonOutput) {
|
|
1739
|
+
emitJson(true, all ? { frozen: results, totalReclaimedMb: totalReclaimed } : results[0]);
|
|
1740
|
+
} else {
|
|
1741
|
+
for (const r of results) {
|
|
1742
|
+
if (r.skipped) { log.info(`skipped ${r.sessionId} (${r.skipped})`); continue; }
|
|
1743
|
+
if (!r.frozen) { log.fail(`freeze failed (${r.sessionId}): ${r.error}`); continue; }
|
|
1744
|
+
let extra = r.beforeMb !== null && r.beforeMb !== undefined ? ` heap=${r.beforeMb}MB` : '';
|
|
1745
|
+
if (verify && r.afterMb !== undefined) extra += ` -> ${r.afterMb}MB (V8-GC heapΔ ${r.reclaimedMb}MB)`;
|
|
1746
|
+
log.ok(`froze ${r.sessionId}${r.pid ? ` pid=${r.pid}` : ''}${extra}`);
|
|
1747
|
+
}
|
|
1748
|
+
if (all && verify) log.ok(`total heapΔ (V8 GC of quiesced tabs): ${totalReclaimed}MB across ${results.filter(r => r.frozen).length} tab(s)`);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1626
1752
|
// List cookies for a URL (including HttpOnly) via extension chrome.cookies.getAll bridge.
|
|
1627
1753
|
// Primitive: extension_ws_bridge (background.js exposes method:'getCookies').
|
|
1628
1754
|
// Note: this reads via the CRX cookies API - HttpOnly cookies (ESTSAUTH, s.SessID etc.)
|
|
@@ -2562,6 +2688,7 @@ ${YELLOW}DOMAIN EXTENSIONS:${NC}
|
|
|
2562
2688
|
console.log(` ${GREEN}${'a11y'.padEnd(16)}${NC} ${DIM}Accessibility.getFullAXTree (snapshot --a11y flag equivalent)${NC}`);
|
|
2563
2689
|
console.log(` ${GREEN}${'frozen'.padEnd(16)}${NC} ${DIM}detect if tab is macrotask-frozen (hidden); exit 1 = frozen${NC}`);
|
|
2564
2690
|
console.log(` ${GREEN}${'thaw'.padEnd(16)}${NC} ${DIM}un-throttle a frozen/hidden tab in place (--all --verify); aka unfreeze/wake${NC}`);
|
|
2691
|
+
console.log(` ${GREEN}${'freeze'.padEnd(16)}${NC} ${DIM}halt/contain a hidden bg tab (stop JS/timers/alloc); reverse of thaw${NC}`);
|
|
2565
2692
|
console.log('');
|
|
2566
2693
|
}
|
|
2567
2694
|
|
|
@@ -4048,6 +4175,9 @@ async function main() {
|
|
|
4048
4175
|
case 'wake':
|
|
4049
4176
|
await cmdThaw(args.slice(1));
|
|
4050
4177
|
break;
|
|
4178
|
+
case 'freeze':
|
|
4179
|
+
await cmdFreeze(args.slice(1));
|
|
4180
|
+
break;
|
|
4051
4181
|
case 'cookies':
|
|
4052
4182
|
if (args.slice(1).some(a => a === '--set' || a === '--delete')) {
|
|
4053
4183
|
await cmdCookieWrite(args.slice(1));
|
package/lib/paths.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const os = require('os');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
/** Browser runtime data
|
|
6
|
+
/** Browser runtime data - always ~/.glider unless GLIDER_HOME set. */
|
|
7
7
|
function gliderHome() {
|
|
8
8
|
return process.env.GLIDER_HOME || path.join(os.homedir(), '.glider');
|
|
9
9
|
}
|
|
@@ -32,7 +32,7 @@ function configPath(name) {
|
|
|
32
32
|
];
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/** Domain intel:
|
|
35
|
+
/** Domain intel: AGREGISTRY/warch or ~/.glider/warch when AGREGISTRY unset. */
|
|
36
36
|
function warchRoot() {
|
|
37
37
|
return path.join(registryBase(), 'warch');
|
|
38
38
|
}
|
package/package.json
CHANGED