Repository navigation
refactor(browser): decide target_changed from one document identity owner - #10703
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d22061e9c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
[Medium impact] The PR appears safe to merge; the earlier findings are fixed and no new blocking issues were found. SummaryCentralizes document identity checks across page capture, screenshots, WebMCP discovery, and runtime inspection.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Selected document] --> B[Read frame tree or receive navigation event]
B --> C[Compare frame and loader]
C --> D{Proven document change?}
D -->|Yes| E[Report target_changed]
D -->|No| F[Check current origin]
F --> G{Origin allowed?}
G -->|No| H[Refuse capture]
G -->|Yes| I[Apply consumer coverage and URL rules]
Reviews (3) · Last reviewed commit: "fix(browser): compare the selected docum..." · Reviewed by Greptile |
4d6e3e6 to
ff6751a
Compare
d614d04 to
37e5133
Compare
ff6751a to
7e5d555
Compare
487d125 to
c31aed9
Compare
00ae917 to
d9ef2d2
Compare
…stered-command owner
…h a malformed reply A schema-rejected success reply means the browser applied the Emulation override, so the attached environment owner records the reset obligation before reporting the protocol error. Only a rejected or unanswered command leaves no obligation.
…stered-command owner (#10710)
The verifier scripts send Browser.close, Page.createIsolatedWorld, Page.navigate, Page.reload, Target.activateTarget, Target.closeTarget and Target.createTarget through CdpConnection, which now admits every reply through its command's result schema. Register those schemas, refuse an unregistered run-time name as a typed malformed reply instead of a TypeError, and check script send literals against the registry.
Final-capture retries and the pre-capture frame-tree read now observe each reply through the selected document tracker before scope, and a screenshot command failure after a proven document change reports target_changed with the failure as its cause.
9244f80 to
6dc4280
Compare
d9ef2d2 to
e02d2f8
Compare
Summary
One owner decides whether the selected browser target changed document.
CdpTargetSession.tsnow holdsCdpDocumentIdentity(root frame, loader, URL),compareCdpDocuments,cdpRootDocumentandCdpDocumentTracker. Page capture, WebMCP discovery, screenshot capture and the runtime session use it instead of four separate rules. Stacked on #10666.Problem and expected behavior
target_changedwas decided in five places with different rules. Some treated a URL change with unknown loader IDs as a document change. WebMCP and screenshot capture returnedprotocol_errorwhen a known loader was later missing. Page capture checked origin before identity, and its final check compared URLs only. The runtime session reported an out-of-scope frame with no loader ID astarget_changed.The owner's rule is that only a different root frame ID or a different known loader ID proves a change. A missing loader ID means the identity is
unknown. A known, unchanged loader ID at a new URL means asame_document_navigation. Each consumer decides what each outcome means for its evidence.Change and scope
Behaviour changes (decided by the coordinator; each one is a row in
tests/boundary/browser/cdpTargetChanged.test.ts):CdpRuntimeSession.assertDocument): when there is no loader ID, an out-of-scope or unsupported frame is now a scope refusal (target_not_allowed) for the current document instead oftarget_changed. A proven change is still checked first.framesorwebmcp_toolssection is markedattach_limitedand a limitation is added; it is no longertarget_changed. A URL change with a known, unchanged loader is a same-document navigation, so the result is accepted with full coverage.protocol_error. The first document stays the result'starget. Screenshot capture had the same rule and now behaves the same way.frameNavigatedduring page capture:protocol_errorremains for malformed root identity: a missing or invalid frame ID or parent, and now also a non-stringloaderId. A well-formed root event without a loader ID gives limited coverage.target_changedbefore any scope decision, and it carries the failure it caused ascause. Scope checks apply to the current document. A loader-less (unproven) navigation to another origin is stilltarget_not_allowed.target_changed; before, it was accepted. A document change observed during the observation window now fails at the end of that window instead of after the full capture.Unchanged by design:
target_changed, including a same-document one. The image would not match the reported URL.target_changed. Runtime evidence has no limited-coverage form.CdpExecutionCapture, and Electron's generation counter remain separate checks. Electron is not touched because the D7 isolation work is in progress elsewhere.Not included: WebMCP subframe tool retention (
hasNewDocument) and the timeline main-frame tracking inCdpObservationSessionkeep their own rules. They do not producetarget_changed.Contract and boundary impact
No schema change. The visible effects are the result reasons and coverage listed above. The new limitation texts are "The initial/final document loader identity was unavailable, so document stability could not be verified. Retry after the page finishes loading."
Evidence and regression coverage
cdpTargetChanged.test.tsand two runtime rows. They characterize the current rule of each consumer and pass on the unchanged code: 56/56 with the runtime file.Validation performed
npm run test:focused -- <44 browser/MCP test files touching frame identity, frameNavigated, getFrameTree or target_changed>: 920 passed.npm run check:fast: passed.npx oxfmton changed files.target_changed): the 3 new regressions intests/boundary/browser/cdpTargetChanged.test.tsfailed on the previous head and pass now;npm run test:focusedover 12 touched browser test files: 298 passed;npm run check:fast: passed.Compatibility
There are no API or schema changes. Callers that relied on
protocol_errorfor a missing final loader, or ontarget_changedfor loader-less URL moves, now get a completed result withattach_limitedcoverage.Author readiness
Human owner:
Before merge
type(scope): outcome.