feat(cli): emit Page.lifecycleEvent in browse cdp#2056
Merged
derekmeegan merged 1 commit intomainfrom Apr 27, 2026
Merged
Conversation
`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) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: fce3171 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant CLI as Browse CLI
participant WS as WebSocket Connection
participant Browser as Chrome/Browser (CDP)
participant UI as Console Output
Note over CLI,Browser: Domain Initialization
CLI->>WS: sendCDP("Page.enable")
WS->>Browser: Enable Page domain
opt domain == "Page"
CLI->>WS: NEW: sendCDP("Page.setLifecycleEventsEnabled", {enabled: true})
WS->>Browser: Subscribe to granular lifecycle milestones
end
Note over CLI,Browser: Navigation/Runtime Flow
Browser-->>WS: Event: Page.lifecycleEvent (e.g. "DOMContentLoaded")
WS-->>CLI: Raw JSON payload
alt --pretty flag enabled
CLI->>CLI: CHANGED: Parse params.name from event
CLI->>UI: "[Page.lifecycleEvent] DOMContentLoaded"
else Default (NDJSON)
CLI->>UI: {"method": "Page.lifecycleEvent", "params": {...}}
end
Browser-->>WS: Event: Page.lifecycleEvent (e.g. "networkIdle")
WS-->>CLI: Raw JSON payload
opt --pretty flag
CLI->>UI: "[Page.lifecycleEvent] networkIdle"
end
5 tasks
shrey150
approved these changes
Apr 27, 2026
derekmeegan
added a commit
to browserbase/skills
that referenced
this pull request
Apr 27, 2026
* Add browser-observability skill
Capture the full CDP firehose plus periodic screenshots and DOM dumps
alongside any browser automation (browse, Stagehand, Playwright, Puppeteer
— anything that speaks CDP), then bisect the stream into per-page
searchable buckets keyed by top-level navigations.
The skill is purely observational: it adds a second CDP client that
enables read-only domains (Network, Console, Runtime, Log, Page) and
never sends action commands, so it can attach to an in-flight automation
without disrupting it.
Layout produced under .o11y/<run-id>/:
manifest.json, index.jsonl
cdp/raw.ndjson full firehose, NDJSON
cdp/summary.json {sessionId, duration, totalEvents, pages[]}
cdp/<domain>/... session-wide buckets
cdp/pages/<pid>/ per-page slices, indexed by Page.frameNavigated
summary.json, raw.jsonl, network/, console/, page/, ...
screenshots/<iso-ts>.png, dom/<iso-ts>.html
browserbase/ added by bb-finalize.sh on remote runs
Scripts (pure bash + jq, no Python/Node deps beyond the existing browse CLI):
start-capture.sh / stop-capture.sh / snapshot-loop.sh
bisect-cdp.sh — splits raw.ndjson into session-wide and per-page buckets,
writes the structured summary.json
query.sh — drill-down helper: list, page <pid> [bucket], errors,
hosts, host <h>, timeline, summary
bb-capture.sh / bb-finalize.sh — Browserbase wrappers; bb-capture handles
--keep-alive + connectUrl resolution + manifest stamping with
the session id, region, and live debugger URL; bb-finalize
writes browserbase/{session.json, logs.json, downloads.zip}
and optionally releases the session
The CDP firehose is sourced via `browse cdp <target>`, which streams
DevTools-protocol events as NDJSON. That command requires
@browserbasehq/browse-cli alpha or a release that includes
browserbase/stagehand#1905; lifecycle events specifically require
browserbase/stagehand#2056.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Convert browser-observability scripts from bash to .mjs
Mirrors the cookie-sync skill's pattern: each script becomes a Node ESM
module, with a shared scripts/lib.mjs for common helpers and a minimal
package.json (no dependencies — pure Node stdlib, so no `npm install`
step is needed).
scripts/lib.mjs shared helpers, BUCKETS table, isTopNav
scripts/start-capture.mjs spawn detached `browse cdp` + sampler
scripts/snapshot-loop.mjs screenshot+DOM+url poll loop (internal)
scripts/stop-capture.mjs SIGTERM+grace+SIGKILL, sweep .partials
scripts/bisect-cdp.mjs page-aware bisect + structured summary.json
scripts/query.mjs drill-down: list/page/errors/hosts/host/timeline
scripts/bb-capture.mjs Browserbase wrapper (--new or attach by id)
scripts/bb-finalize.mjs pull session.json/logs.json/downloads.zip
Output layout, per-page bisection logic, summary.json shape, and the
query.mjs subcommands are identical to the bash versions. SKILL.md,
REFERENCE.md, and EXAMPLES.md updated to invoke `node scripts/foo.mjs`
instead of `bash scripts/foo.sh`.
Dogfooded end-to-end against a Browserbase session and against the
saved /Users/d/Desktop/browserbase/o11y-demo-1 run — page bisection,
durations, error attribution, host counts all match the bash output.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Rename browser-observability → browser-trace
Shorter, more action-oriented name that reads cleanly as a slash command
and pairs naturally with the autobrowse skill (which can use the trace
output as the structured "what just happened" data for its loop).
Renames:
- skills/browser-observability/ → skills/browser-trace/
- SKILL.md frontmatter `name`, doc H1s, package.json name
- marketplace.json plugin entry (name, skills path, description, keywords)
- README.md skills table row
- "observer" → "tracer" throughout the prose for consistency with the new name
No behaviour change — all script interfaces, output layout, summary.json
shape, and query.mjs subcommands are unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Address Cursor Bugbot review on browser-trace
Fix three issues flagged on PR #83:
- query.mjs cmdTimeline: was printing every navigation followed by every
lifecycle event, so all `[NAV …]` lines bunched before any
`[init]`/`[load]` lines. Now reads cdp/raw.ndjson directly and emits
top-level frameNavigated and lifecycle events in actual stream order.
- query.mjs cmdHost: was using `url.startsWith('https://' + hostname)`,
which would match `https://api.example.com.evil.tld/...` when the user
asked for `api.example.com`. Switched to exact `new URL(url).hostname`
comparison via a small `hostMatches` helper.
- query.mjs: removed the unused `emitJsonl` helper (defined but never
called — same class of dead-code issue Bugbot raised against the bash
version's `cat_bucket_across`).
Bugbot also flagged the bash bb-capture.sh's `| grep ... || true` that
silently swallowed start-capture failures. The .mjs version already
handles this correctly via `if (start.status !== 0) process.exit(...)`,
so no change needed there.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Fix Console domain bucket + align hosts/host port handling
Two more issues from Cursor Bugbot on PR #83:
1. Console errors and warnings were being silently dropped from the
per-page summary. computePageSummary classified each event by
`method.split('.')[0]`, which puts Runtime.consoleAPICalled events
into a `Runtime` bucket — but errors/warnings from those events were
being recorded under the key `Console`. The output loop iterates
`counts.entries()` and looks up errors/warnings by that domain key,
so the Console errors/warnings never made it into the rollup.
Added a `domainFor(method)` helper that returns 'Console' for
`Runtime.consoleAPICalled` and the standard `method.split('.')[0]`
otherwise. Now matches the schema documented in SKILL.md.
2. cmdHosts grouped by `URL.host` (port included) but cmdHost compared
against `URL.hostname` (port stripped), so `hosts` output couldn't
be piped into `host` when a port was present. Switched
`hostMatches` to `URL.host` for consistency. Impostor protection
(rejecting `example.com.evil.tld` for `example.com` queries) is
preserved by the exact-equality check.
Verified against /Users/d/Desktop/browserbase/o11y-demo-1: every page
now shows Console + Runtime as distinct domain blocks; page 4
(httpbin/418) correctly attributes the 418 status to a Log error.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
browse cdpenables the Page domain viaPage.enable, butPage.enabledoes not by itself emitPage.lifecycleEvent— that requires a separatePage.setLifecycleEventsEnabledopt-in. As a result, consumers ofbrowse cdptoday see onlyPage.frameNavigatedand miss the granular lifecycle milestones (init,commit,DOMContentLoaded,load,firstPaint,firstContentfulPaint,firstMeaningfulPaint,networkAlmostIdle,networkIdle).This PR enables lifecycle events whenever the Page domain is enabled (so it covers both the default-domain set and explicit
--domain Page), and adds a--prettyformatter case that prints the milestone name.Why
These events are exactly what observability/perf tools want from the firehose:
DOMContentLoaded/load)networkIdle)firstPaint/firstContentfulPaint/firstMeaningfulPaint)Without the opt-in, all of those have to be approximated from
Page.frameNavigated+Network.loadingFinished, which loses the per-milestone resolution.Verification
Built locally with
pnpm exec tsx src/index.ts cdp 9333against a debuggable Chrome and triggered anexample.comnavigation. Before this patch, noPage.lifecycleEventlines. After:Default mode (NDJSON) emits the same events with full params:
{"sessionId":"…","method":"Page.lifecycleEvent","params":{"frameId":"…","loaderId":"…","name":"DOMContentLoaded","timestamp":468107.080156}}Test plan
pnpm --filter @browserbasehq/browse-cli typecheckpassespnpm --filter @browserbasehq/browse-cli eslintpassespnpm --filter @browserbasehq/browse-cli test— no new failures (pre-existing failures incli.test.ts/mode.test.tsreproduce onmainand are unrelated to this change)browse cdp <port>against a debuggable Chrome showsPage.lifecycleEventlines after a navigationbrowse cdp <port> --prettyformats[Page.lifecycleEvent] <name>browse cdp <port> --domain Network --domain Console(no Page) emits no lifecycle events — the opt-in is gated correctly🤖 Generated with Claude Code