openchrome-mcp 1.10.1 → 1.10.3
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 +49 -15
- package/assets/badges/mseep.png +0 -0
- package/dist/browser-state/snapshot.d.ts +12 -0
- package/dist/browser-state/snapshot.d.ts.map +1 -1
- package/dist/browser-state/snapshot.js +39 -7
- package/dist/browser-state/snapshot.js.map +1 -1
- package/dist/cdp/client.d.ts +16 -0
- package/dist/cdp/client.d.ts.map +1 -1
- package/dist/cdp/client.js +62 -2
- package/dist/cdp/client.js.map +1 -1
- package/dist/cdp/tab-health-monitor.d.ts +16 -1
- package/dist/cdp/tab-health-monitor.d.ts.map +1 -1
- package/dist/cdp/tab-health-monitor.js +47 -12
- package/dist/cdp/tab-health-monitor.js.map +1 -1
- package/dist/chrome/exit-classifier.d.ts +66 -0
- package/dist/chrome/exit-classifier.d.ts.map +1 -0
- package/dist/chrome/exit-classifier.js +97 -0
- package/dist/chrome/exit-classifier.js.map +1 -0
- package/dist/chrome/launch-mode-resolver.d.ts +78 -0
- package/dist/chrome/launch-mode-resolver.d.ts.map +1 -0
- package/dist/chrome/launch-mode-resolver.js +108 -0
- package/dist/chrome/launch-mode-resolver.js.map +1 -0
- package/dist/chrome/launcher.d.ts +40 -0
- package/dist/chrome/launcher.d.ts.map +1 -1
- package/dist/chrome/launcher.js +174 -15
- package/dist/chrome/launcher.js.map +1 -1
- package/dist/chrome/ownership-marker.d.ts +86 -0
- package/dist/chrome/ownership-marker.d.ts.map +1 -0
- package/dist/chrome/ownership-marker.js +329 -0
- package/dist/chrome/ownership-marker.js.map +1 -0
- package/dist/chrome/process-detector.d.ts +49 -0
- package/dist/chrome/process-detector.d.ts.map +1 -0
- package/dist/chrome/process-detector.js +241 -0
- package/dist/chrome/process-detector.js.map +1 -0
- package/dist/chrome/process-watchdog.d.ts +18 -0
- package/dist/chrome/process-watchdog.d.ts.map +1 -1
- package/dist/chrome/process-watchdog.js +59 -9
- package/dist/chrome/process-watchdog.js.map +1 -1
- package/dist/cli/claude-cli.d.ts +23 -0
- package/dist/cli/claude-cli.js +31 -0
- package/dist/cli/claude-cli.js.map +1 -0
- package/dist/cli/claude-session.js +3 -2
- package/dist/cli/claude-session.js.map +1 -1
- package/dist/cli/index.js +46 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp-client-config.d.ts +13 -1
- package/dist/cli/mcp-client-config.js +33 -2
- package/dist/cli/mcp-client-config.js.map +1 -1
- package/dist/config/global.d.ts +6 -1
- package/dist/config/global.d.ts.map +1 -1
- package/dist/config/global.js.map +1 -1
- package/dist/config/headless-resolver.d.ts +39 -0
- package/dist/config/headless-resolver.d.ts.map +1 -0
- package/dist/config/headless-resolver.js +55 -0
- package/dist/config/headless-resolver.js.map +1 -0
- package/dist/config/tool-tiers.d.ts.map +1 -1
- package/dist/config/tool-tiers.js +2 -1
- package/dist/config/tool-tiers.js.map +1 -1
- package/dist/index.js +194 -14
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +27 -4
- package/dist/mcp-server.js.map +1 -1
- package/dist/session-state-persistence.d.ts +17 -0
- package/dist/session-state-persistence.d.ts.map +1 -1
- package/dist/session-state-persistence.js +36 -1
- package/dist/session-state-persistence.js.map +1 -1
- package/dist/tools/computer.d.ts.map +1 -1
- package/dist/tools/computer.js +31 -6
- package/dist/tools/computer.js.map +1 -1
- package/dist/tools/fill-form.d.ts.map +1 -1
- package/dist/tools/fill-form.js +122 -4
- package/dist/tools/fill-form.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/login-detector.d.ts +87 -0
- package/dist/tools/login-detector.d.ts.map +1 -0
- package/dist/tools/login-detector.js +169 -0
- package/dist/tools/login-detector.js.map +1 -0
- package/dist/tools/navigate.d.ts.map +1 -1
- package/dist/tools/navigate.js +73 -22
- package/dist/tools/navigate.js.map +1 -1
- package/dist/tools/validate-page.d.ts +16 -0
- package/dist/tools/validate-page.d.ts.map +1 -0
- package/dist/tools/validate-page.js +309 -0
- package/dist/tools/validate-page.js.map +1 -0
- package/dist/tools/wait-for.js +2 -2
- package/dist/tools/wait-for.js.map +1 -1
- package/dist/transports/stdio.d.ts.map +1 -1
- package/dist/transports/stdio.js +15 -0
- package/dist/transports/stdio.js.map +1 -1
- package/dist/utils/health-endpoint-gating.d.ts +19 -0
- package/dist/utils/health-endpoint-gating.d.ts.map +1 -0
- package/dist/utils/health-endpoint-gating.js +28 -0
- package/dist/utils/health-endpoint-gating.js.map +1 -0
- package/dist/utils/idle-state.d.ts +62 -0
- package/dist/utils/idle-state.d.ts.map +1 -0
- package/dist/utils/idle-state.js +88 -0
- package/dist/utils/idle-state.js.map +1 -0
- package/dist/utils/idle-timeout.d.ts +69 -0
- package/dist/utils/idle-timeout.d.ts.map +1 -0
- package/dist/utils/idle-timeout.js +139 -0
- package/dist/utils/idle-timeout.js.map +1 -0
- package/dist/utils/parent-watcher.d.ts +33 -0
- package/dist/utils/parent-watcher.d.ts.map +1 -0
- package/dist/utils/parent-watcher.js +78 -0
- package/dist/utils/parent-watcher.js.map +1 -0
- package/dist/utils/pid-manager.d.ts +16 -0
- package/dist/utils/pid-manager.d.ts.map +1 -1
- package/dist/utils/pid-manager.js +88 -0
- package/dist/utils/pid-manager.js.map +1 -1
- package/dist/utils/session-resume-token.d.ts +53 -0
- package/dist/utils/session-resume-token.d.ts.map +1 -0
- package/dist/utils/session-resume-token.js +191 -0
- package/dist/utils/session-resume-token.js.map +1 -0
- package/dist/utils/sync-shutdown.d.ts +51 -0
- package/dist/utils/sync-shutdown.d.ts.map +1 -0
- package/dist/utils/sync-shutdown.js +112 -0
- package/dist/utils/sync-shutdown.js.map +1 -0
- package/dist/watchdog/chrome-monitor.d.ts +16 -0
- package/dist/watchdog/chrome-monitor.d.ts.map +1 -1
- package/dist/watchdog/chrome-monitor.js +35 -3
- package/dist/watchdog/chrome-monitor.js.map +1 -1
- package/dist/watchdog/disk-monitor.d.ts +17 -0
- package/dist/watchdog/disk-monitor.d.ts.map +1 -1
- package/dist/watchdog/disk-monitor.js +41 -8
- package/dist/watchdog/disk-monitor.js.map +1 -1
- package/dist/watchdog/event-loop-monitor.d.ts +23 -0
- package/dist/watchdog/event-loop-monitor.d.ts.map +1 -1
- package/dist/watchdog/event-loop-monitor.js +61 -25
- package/dist/watchdog/event-loop-monitor.js.map +1 -1
- package/dist/watchdog/health-endpoint.d.ts +5 -0
- package/dist/watchdog/health-endpoint.d.ts.map +1 -1
- package/dist/watchdog/health-endpoint.js +14 -2
- package/dist/watchdog/health-endpoint.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
<a href="https://github.com/shaun0927/openchrome/releases/latest"><img src="https://img.shields.io/github/v/release/shaun0927/openchrome" alt="Latest Release"></a>
|
|
15
15
|
<a href="https://github.com/shaun0927/openchrome/releases/latest"><img src="https://img.shields.io/github/release-date/shaun0927/openchrome" alt="Release Date"></a>
|
|
16
16
|
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="MIT"></a>
|
|
17
|
+
<a href="https://mseep.ai/app/shaun0927-openchrome"><img src="assets/badges/mseep.png" alt="Listed on MseeP.ai" height="20"></a>
|
|
17
18
|
</p>
|
|
18
19
|
|
|
19
20
|
<p align="center">
|
|
@@ -208,6 +209,11 @@ npx openchrome-mcp setup
|
|
|
208
209
|
npx openchrome-mcp setup --client codex
|
|
209
210
|
```
|
|
210
211
|
|
|
212
|
+
**OpenCode**
|
|
213
|
+
```bash
|
|
214
|
+
npx openchrome-mcp setup --client opencode
|
|
215
|
+
```
|
|
216
|
+
|
|
211
217
|
One command. Configures the MCP server for the selected client.
|
|
212
218
|
Restart your MCP client after setup completes.
|
|
213
219
|
|
|
@@ -244,6 +250,20 @@ claude mcp add openchrome -- npx -y openchrome-mcp@latest serve --auto-launch
|
|
|
244
250
|
}
|
|
245
251
|
```
|
|
246
252
|
|
|
253
|
+
|
|
254
|
+
**OpenCode** (`~/.config/opencode/opencode.json`):
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"$schema": "https://opencode.ai/config.json",
|
|
258
|
+
"mcp": {
|
|
259
|
+
"openchrome": {
|
|
260
|
+
"type": "local",
|
|
261
|
+
"command": ["npx", "--prefer-online", "-y", "openchrome-mcp@latest", "serve", "--auto-launch"]
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
247
267
|
**Cursor / Windsurf / Other stdio MCP clients:**
|
|
248
268
|
```json
|
|
249
269
|
{
|
|
@@ -397,9 +417,11 @@ When a navigation is blocked by CDN/WAF systems (Akamai, Cloudflare, etc.), Open
|
|
|
397
417
|
Tier 3 launches a real headed Chrome window with a genuine user-agent (`Chrome/...` instead of `HeadlessChrome/...`) and a different TLS fingerprint, bypassing binary-level detection that no JavaScript injection can fix.
|
|
398
418
|
|
|
399
419
|
**Parameters:**
|
|
400
|
-
- `autoFallback: false` — disable
|
|
401
|
-
- `headed: true` — skip directly to
|
|
402
|
-
- `stealth: true` — use stealth mode (Tier 2) explicitly
|
|
420
|
+
- `autoFallback: false` — disable automatic CDN/WAF retry. This does not log in for you or bypass normal authentication redirects.
|
|
421
|
+
- `headed: true` — skip directly to headed Chrome for user-visible login, 2FA, CAPTCHA, or sites that require a real browser window.
|
|
422
|
+
- `stealth: true` — use stealth mode (Tier 2) explicitly.
|
|
423
|
+
|
|
424
|
+
**Authentication note:** Auto-fallback is for detected CDN/WAF blocking. If a protected app redirects from the requested URL to a same-site login page, treat that as an authentication handoff: retry with `headed: true` and the same persistent profile, let the user complete login, then verify whether headless can reuse that profile state.
|
|
403
425
|
|
|
404
426
|
**Environment:** Tier 3 requires a display (macOS/Windows desktop, or Linux with `$DISPLAY`). In server/container environments without a display, Tier 3 is gracefully skipped.
|
|
405
427
|
|
|
@@ -426,15 +448,22 @@ If client A opens five tabs and client B opens five tabs, all ten `tabId`s are d
|
|
|
426
448
|
|
|
427
449
|
### How do I handle sites that require interactive login (password, 2FA, CAPTCHA)?
|
|
428
450
|
|
|
429
|
-
|
|
451
|
+
Use two mechanisms, but keep their guarantees separate:
|
|
452
|
+
|
|
453
|
+
**1. Persistent-profile headless — reuse an already-authenticated profile.**
|
|
454
|
+
Point OpenChrome at a persistent `userDataDir` (+ optional `profileDirectory`) so cookies / `localStorage` / IndexedDB can survive across runs. If that persistent profile already contains a valid session, subsequent **headless** runs stay logged in until the site invalidates the session.
|
|
430
455
|
|
|
431
|
-
**
|
|
432
|
-
|
|
456
|
+
**2. Headed-by-default / headed fallback — let the user complete an interactive step.**
|
|
457
|
+
Since #657 the launcher runs headed by default, so first-time login, 2FA, CAPTCHA, and WebAuthn can use a real visible window without extra flags. CI / Docker users opt into headless via `--headless` or `OPENCHROME_HEADLESS=1` after their persistent profile is bootstrapped. When a Tier-1/Tier-2 headless attempt is blocked by a CDN/WAF, OpenChrome can also lazy-launch a separate headed Chrome on a different debug port and register the headed page back into the same logical session.
|
|
433
458
|
|
|
434
|
-
**
|
|
435
|
-
When a human action is genuinely required (first-time login, 2FA, CAPTCHA, WebAuthn) or when a Tier-1/Tier-2 headless attempt is blocked by a CDN/WAF, OpenChrome lazy-launches a separate headed Chrome on a different debug port. Cookies are sync'd from the real Chrome profile before launch, and the headed page is registered back into the same logical session so the surrounding workflow continues seamlessly.
|
|
459
|
+
**Important:** a headed tab being authenticated does not automatically prove that a new headless tab can reuse the session after the headed tab is closed. Sites differ in how they bind cookies, storage, browser fingerprints, and session freshness. Always verify the handoff by closing/restarting the headed path you plan to stop using and navigating headless to the protected URL with the same persistent profile.
|
|
436
460
|
|
|
437
|
-
**
|
|
461
|
+
**Recommended flow:**
|
|
462
|
+
1. Start with the persistent `userDataDir` / `profileDirectory` you intend to keep using.
|
|
463
|
+
2. Navigate to the protected URL. If it resolves to `/login` or another auth page, do not keep retrying unauthenticated headless navigation.
|
|
464
|
+
3. Use the visible headed window (default) or navigate with `headed: true` and the same profile context, then let the user complete login/2FA/CAPTCHA.
|
|
465
|
+
4. Retry the protected URL with the same profile in the mode you intend to automate.
|
|
466
|
+
5. If headless still lands on the login page, keep the headed tab open for that site or reconfigure persistence; do not assume the headed auth state transferred.
|
|
438
467
|
|
|
439
468
|
### Does OpenChrome steal focus with popup windows?
|
|
440
469
|
|
|
@@ -442,12 +471,12 @@ When a human action is genuinely required (first-time login, 2FA, CAPTCHA, WebAu
|
|
|
442
471
|
|
|
443
472
|
The headed-browser focus-stealing pattern that users encounter with some MCP servers (cross-Space jumps on macOS, un-minimizable popups, per-tool-call window raises) comes from designs where the MCP drives a user-visible browser and creates OS windows as it works. OpenChrome is architected differently:
|
|
444
473
|
|
|
445
|
-
- **Default mode is headless** — no window exists, so there is nothing to take focus.
|
|
446
474
|
- **`tabs_create` opens a tab, not an OS window.** New tabs are created via CDP inside the already-running Chrome, and OpenChrome never calls `page.bringToFront()` anywhere in the codebase.
|
|
447
|
-
- **
|
|
448
|
-
- **
|
|
475
|
+
- **No per-call window raises.** Each navigation/click/tool call runs against the existing window without `bringToFront()`, `focus()`, or any other stealing primitive. After the initial Chrome launch you keep working in your other apps without interruption.
|
|
476
|
+
- **One Chrome per server lifetime.** Auto-launch creates Chrome **once** at startup and reuses it for every later tool call — no popup-per-action loop.
|
|
477
|
+
- **Headless opt-in available.** For CI/server use, `--headless` or `OPENCHROME_HEADLESS=1` runs without any window at all. The default is headed since #657 because headless mode is materially more prone to silent hangs and login failures on real-world sites.
|
|
449
478
|
|
|
450
|
-
The only scenario in which a
|
|
479
|
+
The only scenario in which a focus grab can happen is the very first Chrome launch — not one per tool call, never one per tab.
|
|
451
480
|
|
|
452
481
|
---
|
|
453
482
|
|
|
@@ -535,6 +564,10 @@ docker run openchrome
|
|
|
535
564
|
| `CHROME_USER_DATA_DIR` | Custom profile directory |
|
|
536
565
|
| `CI` | Detected automatically; adds `--no-sandbox` |
|
|
537
566
|
| `DOCKER` | Detected automatically; adds `--no-sandbox` |
|
|
567
|
+
| `OPENCHROME_PPID_WATCH` | Set to `0` to disable the parent-process watcher in stdio mode. Default: enabled. The watcher exits the server when its launching MCP-client parent dies, so abrupt parent termination (force-quit, `kill -9`, tmux teardown) does not orphan the openchrome process. HTTP and `both` transport modes ignore this flag — they remain daemon-capable. |
|
|
568
|
+
| `OPENCHROME_PPID_WATCH_INTERVAL_MS` | Polling interval for the parent watcher in milliseconds. Default: `2000`. Clamped to `[500, 60000]`. |
|
|
569
|
+
| `OPENCHROME_HEALTH_ENDPOINT` | Force-enable (`1`/`true`) or force-disable (`0`/`false`) the `/health` and `/metrics` HTTP listener. Default: on for `--transport http` / `both`, off for `--transport stdio`. Stdio-mode instances usually talk to a single MCP client over the pipe and do not need an external monitoring port; disabling it saves ~200-300 KB heap + one file descriptor per instance. Operators who run stdio under a supervisor can opt in with `OPENCHROME_HEALTH_ENDPOINT=1`; daemon-mode operators who run the health check externally can opt out with `OPENCHROME_HEALTH_ENDPOINT=0`. Invalid values (e.g. `yes`, `2`) fall through to the transport-mode default. |
|
|
570
|
+
| `OPENCHROME_HEADLESS` | Opt into headless Chrome from CI / Docker without `--headless`. Accepts `1`/`true`/`yes` (headless) or `0`/`false`/`no` (headed). Lower precedence than the CLI flag, higher than persisted config. Default since #657 is headed. |
|
|
538
571
|
|
|
539
572
|
### Individual flags
|
|
540
573
|
|
|
@@ -550,9 +583,10 @@ openchrome serve \
|
|
|
550
583
|
| Flag | Default | Description |
|
|
551
584
|
|------|---------|-------------|
|
|
552
585
|
| `--auto-launch` | `false` | Auto-launch Chrome if not running |
|
|
586
|
+
| `--headless` | `false` | Run Chrome headless. Also: `OPENCHROME_HEADLESS=1`. Default since #657 is headed. |
|
|
553
587
|
| `--headless-shell` | `false` | Use chrome-headless-shell binary |
|
|
554
|
-
| `--visible` |
|
|
555
|
-
| `--server-mode` | `false` | Compound flag for server deployment |
|
|
588
|
+
| `--visible` | (deprecated) | No-op alias for headed; the new default is headed since #657. Will be removed in a future release. |
|
|
589
|
+
| `--server-mode` | `false` | Compound flag for server deployment (forces `--headless` + auto-launch) |
|
|
556
590
|
|
|
557
591
|
---
|
|
558
592
|
|
|
Binary file
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* - Old snapshots are pruned to keep disk usage bounded.
|
|
14
14
|
* - All restore operations are best-effort (try/catch, non-fatal).
|
|
15
15
|
*/
|
|
16
|
+
import { IdleState } from '../utils/idle-state';
|
|
16
17
|
export interface BrowserSnapshot {
|
|
17
18
|
timestamp: number;
|
|
18
19
|
cookies: Array<{
|
|
@@ -32,13 +33,17 @@ export declare class BrowserStateManager {
|
|
|
32
33
|
private readonly intervalMs;
|
|
33
34
|
private readonly maxSnapshots;
|
|
34
35
|
private readonly snapshotDir;
|
|
36
|
+
private readonly idleState;
|
|
35
37
|
private lastSnapshotAt;
|
|
36
38
|
private snapshotCount;
|
|
39
|
+
private stopped;
|
|
40
|
+
private lastDelayMs;
|
|
37
41
|
private getCookiesFn;
|
|
38
42
|
private getTabUrlsFn;
|
|
39
43
|
constructor(opts?: {
|
|
40
44
|
intervalMs?: number;
|
|
41
45
|
maxSnapshots?: number;
|
|
46
|
+
idleState?: IdleState;
|
|
42
47
|
});
|
|
43
48
|
/**
|
|
44
49
|
* Register the cookie retrieval function (called from index.ts after CDP client is ready).
|
|
@@ -51,6 +56,13 @@ export declare class BrowserStateManager {
|
|
|
51
56
|
setTabUrlProvider(fn: () => Promise<string[]>): void;
|
|
52
57
|
start(): Promise<void>;
|
|
53
58
|
stop(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Current scheduling delay in ms — exposed for tests asserting the
|
|
61
|
+
* active/idle rate transition (issue #649 §3.1).
|
|
62
|
+
*/
|
|
63
|
+
getCurrentDelayMs(): number;
|
|
64
|
+
private nextDelayMs;
|
|
65
|
+
private scheduleNext;
|
|
54
66
|
takeSnapshot(): Promise<void>;
|
|
55
67
|
/**
|
|
56
68
|
* Load the latest snapshot's cookies (raw data for the caller to apply via CDP).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/browser-state/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/browser-state/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,EAAgC,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQ9E,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,OAAO,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,YAAY,CAAuC;IAC3D,OAAO,CAAC,YAAY,CAA0C;gBAElD,IAAI,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,SAAS,CAAA;KAAE;IAOxF;;;OAGG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;IAIjD;;OAEG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAI9C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,IAAI,IAAI,IAAI;IAQZ;;;OAGG;IACH,iBAAiB,IAAI,MAAM;IAI3B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,YAAY;IAed,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BnC;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YAmBjC,cAAc;IAkB5B,SAAS,IAAI;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE;CAG/D"}
|
|
@@ -53,19 +53,29 @@ const path = __importStar(require("path"));
|
|
|
53
53
|
const os = __importStar(require("os"));
|
|
54
54
|
const fs = __importStar(require("fs/promises"));
|
|
55
55
|
const defaults_1 = require("../config/defaults");
|
|
56
|
+
const idle_state_1 = require("../utils/idle-state");
|
|
57
|
+
/**
|
|
58
|
+
* Idle cadence. 300 s is 5× slower than the default 60 s active rate
|
|
59
|
+
* (issue #649 Part A §3.1 — snapshot is rebuilt on next RPC regardless).
|
|
60
|
+
*/
|
|
61
|
+
const IDLE_SNAPSHOT_INTERVAL_MS = 300_000;
|
|
56
62
|
class BrowserStateManager {
|
|
57
63
|
timer = null;
|
|
58
64
|
intervalMs;
|
|
59
65
|
maxSnapshots;
|
|
60
66
|
snapshotDir;
|
|
67
|
+
idleState;
|
|
61
68
|
lastSnapshotAt = 0;
|
|
62
69
|
snapshotCount = 0;
|
|
70
|
+
stopped = true;
|
|
71
|
+
lastDelayMs = 0;
|
|
63
72
|
getCookiesFn = null;
|
|
64
73
|
getTabUrlsFn = null;
|
|
65
74
|
constructor(opts) {
|
|
66
75
|
this.intervalMs = opts?.intervalMs ?? defaults_1.DEFAULT_SNAPSHOT_INTERVAL_MS;
|
|
67
76
|
this.maxSnapshots = opts?.maxSnapshots ?? defaults_1.DEFAULT_SNAPSHOT_MAX_COUNT;
|
|
68
77
|
this.snapshotDir = path.join(os.homedir(), '.openchrome', 'snapshots');
|
|
78
|
+
this.idleState = opts?.idleState ?? (0, idle_state_1.getIdleState)();
|
|
69
79
|
}
|
|
70
80
|
/**
|
|
71
81
|
* Register the cookie retrieval function (called from index.ts after CDP client is ready).
|
|
@@ -82,22 +92,44 @@ class BrowserStateManager {
|
|
|
82
92
|
}
|
|
83
93
|
async start() {
|
|
84
94
|
this.stop();
|
|
95
|
+
this.stopped = false;
|
|
85
96
|
await fs.mkdir(this.snapshotDir, { recursive: true });
|
|
86
97
|
// Don't take immediate snapshot — wait for first interval
|
|
87
|
-
this.
|
|
88
|
-
this.takeSnapshot().catch(err => {
|
|
89
|
-
console.error('[BrowserState] Snapshot failed:', err);
|
|
90
|
-
});
|
|
91
|
-
}, this.intervalMs);
|
|
92
|
-
this.timer.unref();
|
|
98
|
+
this.scheduleNext(this.nextDelayMs());
|
|
93
99
|
console.error(`[BrowserState] Snapshot service started (interval: ${this.intervalMs}ms, dir: ${this.snapshotDir})`);
|
|
94
100
|
}
|
|
95
101
|
stop() {
|
|
102
|
+
this.stopped = true;
|
|
96
103
|
if (this.timer) {
|
|
97
|
-
|
|
104
|
+
clearTimeout(this.timer);
|
|
98
105
|
this.timer = null;
|
|
99
106
|
}
|
|
100
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Current scheduling delay in ms — exposed for tests asserting the
|
|
110
|
+
* active/idle rate transition (issue #649 §3.1).
|
|
111
|
+
*/
|
|
112
|
+
getCurrentDelayMs() {
|
|
113
|
+
return this.lastDelayMs;
|
|
114
|
+
}
|
|
115
|
+
nextDelayMs() {
|
|
116
|
+
return this.idleState.isIdle(idle_state_1.IDLE_WINDOW_MS) ? IDLE_SNAPSHOT_INTERVAL_MS : this.intervalMs;
|
|
117
|
+
}
|
|
118
|
+
scheduleNext(delay) {
|
|
119
|
+
if (this.stopped)
|
|
120
|
+
return;
|
|
121
|
+
this.lastDelayMs = delay;
|
|
122
|
+
this.timer = setTimeout(() => {
|
|
123
|
+
this.takeSnapshot()
|
|
124
|
+
.catch(err => {
|
|
125
|
+
console.error('[BrowserState] Snapshot failed:', err);
|
|
126
|
+
})
|
|
127
|
+
.finally(() => {
|
|
128
|
+
this.scheduleNext(this.nextDelayMs());
|
|
129
|
+
});
|
|
130
|
+
}, delay);
|
|
131
|
+
this.timer.unref();
|
|
132
|
+
}
|
|
101
133
|
async takeSnapshot() {
|
|
102
134
|
if (!this.getCookiesFn)
|
|
103
135
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/browser-state/snapshot.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAA6B;AAC7B,uCAAyB;AACzB,gDAAkC;AAClC,iDAG4B;
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/browser-state/snapshot.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAA6B;AAC7B,uCAAyB;AACzB,gDAAkC;AAClC,iDAG4B;AAC5B,oDAA8E;AAE9E;;;GAGG;AACH,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAiB1C,MAAa,mBAAmB;IACtB,KAAK,GAA0B,IAAI,CAAC;IAC3B,UAAU,CAAS;IACnB,YAAY,CAAS;IACrB,WAAW,CAAS;IACpB,SAAS,CAAY;IAC9B,cAAc,GAAG,CAAC,CAAC;IACnB,aAAa,G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,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACvD,MAAM,QAAQ,GAAoB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACtD,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,cAAc;QAC1B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACjD,MAAM,aAAa,GAAG,KAAK;iBACxB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;iBAC7D,IAAI,EAAE;iBACN,OAAO,EAAE,CAAC;YAEb,gCAAgC;YAChC,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACxD,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC5B,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,sBAAsB;QACxB,CAAC;IACH,CAAC;IAED,SAAS;QACP,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;IACpF,CAAC;CACF;AAvJD,kDAuJC"}
|
package/dist/cdp/client.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export declare class CDPClient {
|
|
|
60
60
|
private pingLatencies;
|
|
61
61
|
private static readonly MAX_PING_SAMPLES;
|
|
62
62
|
private static readonly COOKIE_CACHE_TTL;
|
|
63
|
+
private static readonly COOKIE_SOURCE_CACHE_MAX;
|
|
64
|
+
private static readonly COOKIE_DATA_CACHE_MAX;
|
|
63
65
|
private reconnecting;
|
|
64
66
|
private reconnectingAttempt;
|
|
65
67
|
private reconnectNextRetryAt;
|
|
@@ -100,6 +102,20 @@ export declare class CDPClient {
|
|
|
100
102
|
*/
|
|
101
103
|
private onTargetDestroyed;
|
|
102
104
|
private touchTargetActivity;
|
|
105
|
+
/**
|
|
106
|
+
* Insert or refresh an entry in cookieSourceCache with a FIFO size cap.
|
|
107
|
+
* When the cache is at capacity AND the key is new, the oldest-inserted
|
|
108
|
+
* entry is evicted. Existing keys update in place without eviction.
|
|
109
|
+
* See issue #647.
|
|
110
|
+
*/
|
|
111
|
+
private setCookieSourceCacheEntry;
|
|
112
|
+
/**
|
|
113
|
+
* Insert or refresh an entry in cookieDataCache with a FIFO size cap.
|
|
114
|
+
* When the cache is at capacity AND the key is new, the oldest-inserted
|
|
115
|
+
* entry is evicted. Existing keys update in place without eviction.
|
|
116
|
+
* See issue #647.
|
|
117
|
+
*/
|
|
118
|
+
private setCookieDataCacheEntry;
|
|
103
119
|
getLastCookieScanResult(): CookieScanResult | null;
|
|
104
120
|
/**
|
|
105
121
|
* Emit connection event
|
package/dist/cdp/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/cdp/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA0B9F,OAAO,EAAE,MAAM,EAAsB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/cdp/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA0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IjB;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS;CAG1E;AAKD,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAKlE;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAqC;IAEpD;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS;IAShE;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAIxC;;OAEG;IACH,MAAM,IAAI,SAAS,EAAE;IAIrB;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CASrC;AAKD,wBAAgB,mBAAmB,IAAI,gBAAgB,CAKtD"}
|
package/dist/cdp/client.js
CHANGED
|
@@ -55,6 +55,7 @@ const with_timeout_1 = require("../utils/with-timeout");
|
|
|
55
55
|
const collector_1 = require("../metrics/collector");
|
|
56
56
|
const connection_1 = require("../errors/connection");
|
|
57
57
|
const fingerprint_defense_1 = require("../stealth/fingerprint-defense");
|
|
58
|
+
const idle_state_1 = require("../utils/idle-state");
|
|
58
59
|
function parseEnvInt(name, fallback) {
|
|
59
60
|
const raw = process.env[name];
|
|
60
61
|
if (raw === undefined)
|
|
@@ -105,6 +106,15 @@ class CDPClient {
|
|
|
105
106
|
pingLatencies = []; // rolling window
|
|
106
107
|
static MAX_PING_SAMPLES = 60; // ~5 min at 5s interval
|
|
107
108
|
static COOKIE_CACHE_TTL = 300000; // 5 minutes
|
|
109
|
+
// Bounded cookie cache sizes (see issue #647).
|
|
110
|
+
// Entries are evicted FIFO on write once at cap, and on read-miss when stale.
|
|
111
|
+
// Rationale:
|
|
112
|
+
// - 64 source entries ≈ 64 distinct domains per instance (edge case fan-out
|
|
113
|
+
// degrades gracefully to the existing fresh-scan slow path).
|
|
114
|
+
// - 16 data entries ≈ typical open-tab count; one entry holds a full cookie
|
|
115
|
+
// array (~50–100 KB) so this is the dominant memory line.
|
|
116
|
+
static COOKIE_SOURCE_CACHE_MAX = 64;
|
|
117
|
+
static COOKIE_DATA_CACHE_MAX = 16;
|
|
108
118
|
// Reconnection progress (exposed via getConnectionMetrics)
|
|
109
119
|
reconnecting = false;
|
|
110
120
|
reconnectingAttempt = 0;
|
|
@@ -202,6 +212,38 @@ class CDPClient {
|
|
|
202
212
|
touchTargetActivity(targetId) {
|
|
203
213
|
this.targetActivityAt.set(targetId, Date.now());
|
|
204
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Insert or refresh an entry in cookieSourceCache with a FIFO size cap.
|
|
217
|
+
* When the cache is at capacity AND the key is new, the oldest-inserted
|
|
218
|
+
* entry is evicted. Existing keys update in place without eviction.
|
|
219
|
+
* See issue #647.
|
|
220
|
+
*/
|
|
221
|
+
setCookieSourceCacheEntry(key, value) {
|
|
222
|
+
if (this.cookieSourceCache.size >= CDPClient.COOKIE_SOURCE_CACHE_MAX &&
|
|
223
|
+
!this.cookieSourceCache.has(key)) {
|
|
224
|
+
const firstKey = this.cookieSourceCache.keys().next().value;
|
|
225
|
+
if (firstKey !== undefined) {
|
|
226
|
+
this.cookieSourceCache.delete(firstKey);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
this.cookieSourceCache.set(key, value);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Insert or refresh an entry in cookieDataCache with a FIFO size cap.
|
|
233
|
+
* When the cache is at capacity AND the key is new, the oldest-inserted
|
|
234
|
+
* entry is evicted. Existing keys update in place without eviction.
|
|
235
|
+
* See issue #647.
|
|
236
|
+
*/
|
|
237
|
+
setCookieDataCacheEntry(key, value) {
|
|
238
|
+
if (this.cookieDataCache.size >= CDPClient.COOKIE_DATA_CACHE_MAX &&
|
|
239
|
+
!this.cookieDataCache.has(key)) {
|
|
240
|
+
const firstKey = this.cookieDataCache.keys().next().value;
|
|
241
|
+
if (firstKey !== undefined) {
|
|
242
|
+
this.cookieDataCache.delete(firstKey);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
this.cookieDataCache.set(key, value);
|
|
246
|
+
}
|
|
205
247
|
getLastCookieScanResult() {
|
|
206
248
|
return this.lastCookieScanResult;
|
|
207
249
|
}
|
|
@@ -610,6 +652,8 @@ class CDPClient {
|
|
|
610
652
|
// Set up disconnect handler
|
|
611
653
|
// Non-null assertion: the retry loop above either sets this.browser and breaks, or throws.
|
|
612
654
|
this.browser.on('disconnected', () => {
|
|
655
|
+
// Inbound CDP event — reset idle window (issue #649 Part A).
|
|
656
|
+
(0, idle_state_1.getIdleState)().notifyActive();
|
|
613
657
|
console.error('[CDPClient] Browser disconnected');
|
|
614
658
|
this.handleDisconnect().catch((err) => {
|
|
615
659
|
console.error('[CDPClient] handleDisconnect failed:', err);
|
|
@@ -617,11 +661,15 @@ class CDPClient {
|
|
|
617
661
|
});
|
|
618
662
|
// Set up target destroyed handler
|
|
619
663
|
this.browser.on('targetdestroyed', (0, safe_listener_1.safeAsyncListener)('targetdestroyed', async (target) => {
|
|
664
|
+
// Inbound CDP event — reset idle window (issue #649 Part A).
|
|
665
|
+
(0, idle_state_1.getIdleState)().notifyActive();
|
|
620
666
|
const targetId = (0, puppeteer_helpers_1.getTargetId)(target);
|
|
621
667
|
console.error(`[CDPClient] Target destroyed: ${targetId}`);
|
|
622
668
|
this.onTargetDestroyed(targetId);
|
|
623
669
|
}));
|
|
624
670
|
this.browser.on('targetchanged', (0, safe_listener_1.safeAsyncListener)('targetchanged', async (target) => {
|
|
671
|
+
// Inbound CDP event — reset idle window (issue #649 Part A).
|
|
672
|
+
(0, idle_state_1.getIdleState)().notifyActive();
|
|
625
673
|
if (target.type() !== 'page')
|
|
626
674
|
return;
|
|
627
675
|
const targetId = (0, puppeteer_helpers_1.getTargetId)(target);
|
|
@@ -639,6 +687,8 @@ class CDPClient {
|
|
|
639
687
|
// (popup/window.open). This makes OAuth redirects, popups, and cross-origin navigations
|
|
640
688
|
// visible without materializing unrelated Chrome-internal targets.
|
|
641
689
|
this.browser.on('targetcreated', (0, safe_listener_1.safeAsyncListener)('targetcreated', async (target) => {
|
|
690
|
+
// Inbound CDP event — reset idle window (issue #649 Part A).
|
|
691
|
+
(0, idle_state_1.getIdleState)().notifyActive();
|
|
642
692
|
// Only track 'page' type targets (skip service_worker, browser, etc.)
|
|
643
693
|
if (target.type() !== 'page')
|
|
644
694
|
return;
|
|
@@ -1001,6 +1051,11 @@ class CDPClient {
|
|
|
1001
1051
|
this.lastCookieScanResult = result;
|
|
1002
1052
|
return result;
|
|
1003
1053
|
}
|
|
1054
|
+
if (cached) {
|
|
1055
|
+
// Stale entry: drop it so the cache does not retain expired data when
|
|
1056
|
+
// the fresh scan path below produces a new result (see issue #647).
|
|
1057
|
+
this.cookieSourceCache.delete(cacheKey);
|
|
1058
|
+
}
|
|
1004
1059
|
// Promise coalescing: if a scan for this domain is already in-flight, reuse it
|
|
1005
1060
|
const existing = this.inFlightCookieScans.get(cacheKey);
|
|
1006
1061
|
if (existing) {
|
|
@@ -1145,7 +1200,7 @@ class CDPClient {
|
|
|
1145
1200
|
if (cookieCount > 0) {
|
|
1146
1201
|
const domainScore = targetDomain ? this.domainMatchScore(candidate.url, targetDomain) : 0;
|
|
1147
1202
|
console.error(`[CDPClient] Found authenticated page ${candidate.targetId.slice(0, 8)} at ${candidate.url.slice(0, 50)} (${cookieCount} cookies, domain score: ${domainScore})`);
|
|
1148
|
-
this.
|
|
1203
|
+
this.setCookieSourceCacheEntry(cacheKey, { targetId: candidate.targetId, timestamp: Date.now() });
|
|
1149
1204
|
this.touchTargetActivity(candidate.targetId);
|
|
1150
1205
|
const status = targetsScanned < candidates.length ? 'partial' : 'complete';
|
|
1151
1206
|
const resultSummary = buildResult(status, candidates.length, candidate.targetId);
|
|
@@ -1203,6 +1258,11 @@ class CDPClient {
|
|
|
1203
1258
|
await destSession.detach().catch(() => { });
|
|
1204
1259
|
}
|
|
1205
1260
|
}
|
|
1261
|
+
if (cachedData) {
|
|
1262
|
+
// Stale entry: drop it so the cache does not retain expired data when
|
|
1263
|
+
// the fresh scan path below produces a new result (see issue #647).
|
|
1264
|
+
this.cookieDataCache.delete(sourceTargetId);
|
|
1265
|
+
}
|
|
1206
1266
|
// Attach to the source target via the multiplexed browser CDP session
|
|
1207
1267
|
const browser = this.getBrowser();
|
|
1208
1268
|
const browserSession = await browser.target().createCDPSession();
|
|
@@ -1226,7 +1286,7 @@ class CDPClient {
|
|
|
1226
1286
|
const result = await browserSession.send('Network.getAllCookies', undefined, { sessionId });
|
|
1227
1287
|
const cookies = result?.cookies || [];
|
|
1228
1288
|
// Store in cookie data cache
|
|
1229
|
-
this.
|
|
1289
|
+
this.setCookieDataCacheEntry(sourceTargetId, { cookies, timestamp: Date.now() });
|
|
1230
1290
|
if (cookies.length === 0) {
|
|
1231
1291
|
console.error('[CDPClient] No cookies found in source page');
|
|
1232
1292
|
return 0;
|