Skip to content

Add FrameNavigatedSameDocument / FrameNavigatedNewDocument page events - #3751

Closed
kblok wants to merge 1 commit into
masterfrom
fix/3727-frame-navigated-events
Closed

kblok wants to merge 1 commit into
masterfrom
fix/3727-frame-navigated-events

Conversation

@kblok

@kblok kblok commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Closes #3727

Ports the new PageEvent.FrameNavigatedSameDocument / FrameNavigatedNewDocument events from puppeteer/puppeteer#15760 as IPage.FrameNavigatedSameDocument and IPage.FrameNavigatedNewDocument (with XML docs, and a remark on FrameNavigated).

  • CDP: FrameManager raises them after FrameNavigated (new document / within document).
  • BiDi: fragment navigation and historyUpdated raise FrameNavigated + same-document; DOMContentLoaded raises new-document.
  • Tests ported from upstream frame.test.ts (Chrome/CDP: all FrameTests and NavigationTests pass; the only failure, ShouldWorkHeadful, is an environment limit). BiDi was not run locally.

Upstream parity

Verdict: parity with upstream (api/Page.ts, cdp/Page.ts, cdp/FrameManager.ts, bidi/Frame.ts) including event order and docs. The /hardkoded:upstream-parity-check skill wasn't available in this session, so this was checked manually.


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Added page events for same-document and new-document frame navigations, making it easier to respond to each navigation type separately.
    • The existing frame navigation event continues to cover both types and fires before the corresponding specific event.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The page API now exposes separate events for same-document and new-document frame navigations. CDP and BiDi handlers report the corresponding events. Tests cover event order, frame identity, event counts, and URLs for document, fragment, history API, and child-frame navigation.

Changes: Frame navigation events

Layer / File(s) Summary
Public navigation event contract
lib/PuppeteerSharp/IPage.cs, lib/PuppeteerSharp/Page.cs
The page API documents and exposes FrameNavigatedSameDocument and FrameNavigatedNewDocument. Page adds internal raisers for both events.
CDP event dispatch and navigation tests
lib/PuppeteerSharp/Cdp/FrameManager.cs, lib/PuppeteerSharp/Cdp/CdpPage.cs, lib/PuppeteerSharp.Tests/FrameTests/FrameManagementTests.cs
The CDP frame manager reports new-document and same-document navigations, with FrameNavigated raised first for within-document navigation. Tests assert event ordering, frame identity, counts, and URLs.
BiDi event dispatch
lib/PuppeteerSharp/Bidi/BidiFrame.cs
BiDi fragment and history updates report same-document navigation. The DOM-content-loaded handler reports new-document navigation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant FrameManager
  participant CdpPage
  participant Page
  FrameManager->>CdpPage: FrameNavigated(frame)
  CdpPage->>Page: Report frame navigation
  alt New-document navigation
    FrameManager->>CdpPage: FrameNavigatedNewDocument(frame)
    CdpPage->>Page: Report new-document navigation
  else Same-document navigation
    FrameManager->>CdpPage: FrameNavigatedWithinDocument(frame)
    CdpPage->>Page: Report same-document navigation
  end
Loading
Merge Risk: Minimal · up to 64ad9

This adds same-document and new-document frame navigation events to the page API for both CDP and BiDi, with tests for event order, counts and URLs. No concrete merge-blocking defect was found. One BiDi edge case, cached history restoration, remains unverified. It may be worth a follow-up check on supported browsers but does not block merging.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Out of Scope Changes check Inconclusive Issue #3727 covers documentation only and states 'once the feature is ported', which implies the port is a prerequisite handled elsewhere. This PR also ports the feature: new public events in Page.cs … Confirm whether the feature port belongs in this PR or in a separate change referenced by #3727. Confirm that the reordering of FrameNavigated and FrameNavigatedWithinDocument in FrameManager.cs is intended and required by the port. Provide…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two new public page events, FrameNavigatedSameDocument and FrameNavigatedNewDocument, which are the main change in the PR. The changeset adds these events to IPage and Page, wires …
Linked Issues check Passed Issue #3727 asks for XML docs and site docs for FrameNavigatedSameDocument and FrameNavigatedNewDocument after the feature is ported. The coding requirement is the XML documentation. At head, lib/Pupp…
Full details: Title check

Explanation

The title names the two new public page events, FrameNavigatedSameDocument and FrameNavigatedNewDocument, which are the main change in the PR. The changeset adds these events to IPage and Page, wires them through CdpPage and BidiFrame, and adjusts FrameManager event ordering. The title is specific and matches the primary change, so it passes.

Full details: Linked Issues check

Explanation

Issue #3727 asks for XML docs and site docs for FrameNavigatedSameDocument and FrameNavigatedNewDocument after the feature is ported. The coding requirement is the XML documentation. At head, lib/PuppeteerSharp/IPage.cs documents both events. FrameNavigatedSameDocument states it is raised for same-document navigation, and FrameNavigatedNewDocument states it is raised for new-document navigation. Both remarks state that the event is raised after FrameNavigated. The FrameNavigated remark directs readers to the two new events. Site docs are documentation outside the code and are treated as non-coding, so they are not assessed. The tests in FrameManagementTests.cs cover the event behavior, but the issue does not require tests.

Full details: Out of Scope Changes check

Explanation

Issue #3727 covers documentation only and states 'once the feature is ported', which implies the port is a prerequisite handled elsewhere. This PR also ports the feature: new public events in Page.cs and IPage.cs, CDP raising in CdpPage.cs and FrameManager.cs, and BiDi raising in BidiFrame.cs. These changes are needed for the documented events to exist, so they are not shown to be unrelated. However, FrameManager.cs also changes existing behavior: within-document navigation now updates state and raises FrameNavigated before FrameNavigatedWithinDocument, where the order was previously reversed. The issue does not request this change. The BiDi tests were not run, and the CDP results cover only the author's local run.

Resolution

Confirm whether the feature port belongs in this PR or in a separate change referenced by #3727. Confirm that the reordering of FrameNavigated and FrameNavigatedWithinDocument in FrameManager.cs is intended and required by the port. Provide evidence that the BiDi changes in BidiFrame.cs are covered by tests.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5eeb9ab4-5d29-4af0-8491-c53bf39e6b14
Commits

Reviewing files that changed from the base of the PR and between a08c087 and 64ad9cf.

Files selected for processing: 6

  • lib/PuppeteerSharp.Tests/FrameTests/FrameManagementTests.cs
  • lib/PuppeteerSharp/Bidi/BidiFrame.cs
  • lib/PuppeteerSharp/Cdp/CdpPage.cs
  • lib/PuppeteerSharp/Cdp/FrameManager.cs
  • lib/PuppeteerSharp/IPage.cs
  • lib/PuppeteerSharp/Page.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@kblok kblok closed this Nov 13, 2026

kblok commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Closing: master already contains this change via #3749 (merged before this PR), so this PR is redundant.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Upstream][Docs] Document framenavigatedsamedocument / framenavigatednewdocument page events

2 participants