Skip to content

Implement upstream PR #14430 - dispose sub-classes correctly - #3454

Merged
kblok merged 1 commit into
masterfrom
implement-upstream-change-14430
May 14, 2026
Merged

kblok merged 1 commit into
masterfrom
implement-upstream-change-14430

Conversation

@kblok

@kblok kblok commented May 13, 2026

Copy link
Copy Markdown
Member

Ports the spirit of upstream Puppeteer PR #14430 ("perf: dispose sub-classes correctly").

Upstream's fix is mostly about TypeScript's disposeSymbol / asyncDisposeSymbol pattern and an internal EventEmitter that removes all subscribers on dispose. PuppeteerSharp uses standard C# events whose delegate list is not cleared by Dispose, so the listener-removed-before-event-fires bug doesn't manifest the same way for us — most of the upstream diff is a no-op in C#.

The one place where the ordering actually matters in our code is FrameManager.RemoveFramesRecursively. Frame.Detach() does internal cleanup (world detachment, raising the per-frame FrameDetached) and used to run before the manager-level FrameDetached event. Now we mirror upstream: remove from the tree, fire FrameDetached on the manager, and only then call frame.Detach(). This keeps observability consistent if anything ever subscribes to manager-level detach events expecting the frame state hasn't been torn down yet.

Verified with the Frame, Navigation, Lifecycle, and Page test suites on Chrome + CDP — all green.

Mirrors upstream Puppeteer PR #14430 ("perf: dispose sub-classes
correctly"). In the original change, frame disposal was moved to run
after the FrameDetached events fire so that listeners aren't torn down
before they can observe the event.

Most of upstream's changes target TypeScript's disposeSymbol /
asyncDisposeSymbol pattern and an internal EventEmitter that removes
all listeners on dispose. PuppeteerSharp uses standard C# events, which
keep their delegate list intact across Dispose, so the underlying bug
does not manifest the same way. The one place the structural ordering
matters is FrameManager.RemoveFramesRecursively, where Frame.Detach
performs internal cleanup (world detachment, etc.) before emitting
FrameDetached on the frame itself. Reordering aligns us with upstream
and keeps event observability consistent with the rest of the codebase.

Refs: puppeteer/puppeteer#14430
@kblok
kblok merged commit 5cf4ba2 into master May 14, 2026
35 of 37 checks passed
@kblok
kblok deleted the implement-upstream-change-14430 branch May 14, 2026 14:14
sondresjolyst added a commit to sondresjolyst/garge-api that referenced this pull request Jun 8, 2026
Updated [PuppeteerSharp](https://github.com/hardkoded/puppeteer-sharp)
from 24.42.0 to 25.0.4.

<details>
<summary>Release notes</summary>

_Sourced from [PuppeteerSharp's
releases](https://github.com/hardkoded/puppeteer-sharp/releases)._

## 25.0.4

## What's New
* chore: roll Firefox to 150.0.3 (upstream #​14983) by @​kblok in
hardkoded/puppeteer-sharp#3468
* chore: roll Chrome to 148.0.7778.167 (upstream #​14980) by @​kblok in
hardkoded/puppeteer-sharp#3469
* feat(webmcp): add UntrustedContent annotation support by @​kblok in
hardkoded/puppeteer-sharp#3442

## What's Changed
* Update sponsors by @​github-actions[bot] in
hardkoded/puppeteer-sharp#3444
* fix: do not open DevTools if it is already open by @​kblok in
hardkoded/puppeteer-sharp#3443
* feat: implement URL allowlist for network restrictions (upstream
#​14897, #​14931) by @​kblok in
hardkoded/puppeteer-sharp#3445
* fix: disable WebUIReloadButton experiment in Chrome launcher by
@​kblok in hardkoded/puppeteer-sharp#3438
* Fix #​3448: correct CDP_ONLY condition check and missing using guards
by @​kblok in hardkoded/puppeteer-sharp#3449
* chore: sync WebMCP test expectations from upstream PR #​14918
(#​14918) by @​kblok in
hardkoded/puppeteer-sharp#3450
* Implement upstream PR #​14821: browser extensions API by @​kblok in
hardkoded/puppeteer-sharp#3404
* remove networkidle from setContent by @​kblok in
hardkoded/puppeteer-sharp#3453
* fix: reject BiDi URL restrictions by @​kblok in
hardkoded/puppeteer-sharp#3452
* Implement upstream PR #​14430 - dispose sub-classes correctly by
@​kblok in hardkoded/puppeteer-sharp#3454
* Implement upstream PR #​14946 - Roll Firefox to 150.0.2 by @​kblok in
hardkoded/puppeteer-sharp#3451
* Implement upstream PR #​14945 - optimize url blocking on navigation by
@​kblok in hardkoded/puppeteer-sharp#3455
* fix: normalize newline-separated headers to comma-separated (upstream
#​14492) by @​kblok in
hardkoded/puppeteer-sharp#3457
* fix: block emulateNetworkConditions when block/allowlist is active
(upstream #​14976) by @​kblok in
hardkoded/puppeteer-sharp#3458
* fix: don't store request on BrowsingContext (upstream #​14966) by
@​kblok in hardkoded/puppeteer-sharp#3460
* fix!: remove Cookie SameParty attribute (upstream #​14545) by @​kblok
in hardkoded/puppeteer-sharp#3461
* chore: track upstream #​14910 (remove deprecated
Browser.isConnected()) by @​kblok in
hardkoded/puppeteer-sharp#3464
* fix: route CDP responses by callback id when sessionId missing
(upstream #​14975) by @​kblok in
hardkoded/puppeteer-sharp#3456
* fix: enabled features take precedence over disabled features (upstream
#​14985) by @​kblok in
hardkoded/puppeteer-sharp#3470
* chore: bump version to 25.0.4 by @​kblok in
hardkoded/puppeteer-sharp#3471


**Full Changelog**:
hardkoded/puppeteer-sharp@v24.42.0...v25.0.4

Commits viewable in [compare
view](hardkoded/puppeteer-sharp@v24.42.0...v25.0.4).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=PuppeteerSharp&package-manager=nuget&previous-version=24.42.0&new-version=25.0.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sondre Sjølyst <18713420+sondresjolyst@users.noreply.github.com>
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.

1 participant