From fce317183f14ef59cc92afbcf11bc2943ae47583 Mon Sep 17 00:00:00 2001 From: Derek Meegan Date: Mon, 27 Apr 2026 10:36:11 -0700 Subject: [PATCH] feat(cli): emit Page.lifecycleEvent in `browse cdp` `Page.enable` does not emit `Page.lifecycleEvent` on its own; it requires a separate `Page.setLifecycleEventsEnabled` call. Without this, consumers of `browse cdp` see only `Page.frameNavigated` and miss the granular lifecycle milestones (`init`, `commit`, `DOMContentLoaded`, `load`, `firstPaint`, `firstContentfulPaint`, `networkAlmostIdle`, `networkIdle`, etc.). Enable lifecycle events whenever the Page domain is enabled, and format them in `--pretty` mode using the milestone name. Co-Authored-By: Claude Opus 4.7 (1M context) --- .changeset/cdp-lifecycle-events.md | 5 +++++ packages/cli/src/index.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .changeset/cdp-lifecycle-events.md diff --git a/.changeset/cdp-lifecycle-events.md b/.changeset/cdp-lifecycle-events.md new file mode 100644 index 000000000..22a6a4593 --- /dev/null +++ b/.changeset/cdp-lifecycle-events.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/browse-cli": patch +--- + +`browse cdp` now also calls `Page.setLifecycleEventsEnabled` whenever the Page domain is enabled, so consumers receive `Page.lifecycleEvent` notifications (`init`, `commit`, `DOMContentLoaded`, `load`, `firstPaint`, `firstContentfulPaint`, `networkAlmostIdle`, `networkIdle`, etc.) in addition to `Page.frameNavigated`. `--pretty` mode formats lifecycle events with the milestone name. No effect on consumers that pass `--domain` without `Page`. diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 1e979a9d3..8e1d22c3b 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -2754,6 +2754,18 @@ program } else { sendCDP(ws, `${domain}.enable`, {}, sessionId); } + + // Page.enable does not emit Page.lifecycleEvent on its own; it requires + // a separate opt-in. Enable it so consumers see DOMContentLoaded, load, + // firstPaint, networkIdle, etc. + if (domain === "Page") { + sendCDP( + ws, + "Page.setLifecycleEventsEnabled", + { enabled: true }, + sessionId, + ); + } } } @@ -2822,6 +2834,11 @@ program if (url) line += ` ${url}`; break; } + case "Page.lifecycleEvent": { + const name = (params?.name as string) ?? ""; + if (name) line += ` ${name}`; + break; + } case "Target.attachedToTarget": { const info = params?.targetInfo as | { type?: string; url?: string }