refactor: align ChromeTargetManager with Puppeteer PR #14602#3107
Merged
refactor: align ChromeTargetManager with Puppeteer PR #14602#3107
Conversation
Co-authored-by: kblok <2198466+kblok@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Review proposed changes to Puppeteer repository
refactor: align ChromeTargetManager with Puppeteer PR #14602
Jan 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR ports refactoring changes from puppeteer/puppeteer#14602 to improve code organization and maintainability in the ChromeTargetManager class.
Changes:
- Extracts
SilentDetachAsyncas a reusable class method and addsGetParentTargethelper for cleaner code organization - Refines service worker destruction logic by separating type checking from attachment checking for better clarity
- Improves pattern matching in
OnDetachedFromTargetfor more explicit control flow - Adjusts filtered target initialization to mark parent Tab targets as initialized instead of filtered targets, better reflecting target hierarchy initialization state
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+195
to
203
| if (targetInfo?.Type == TargetType.ServiceWorker) | ||
| { | ||
| TargetGone?.Invoke(this, new TargetChangedArgs { Target = target, TargetInfo = targetInfo }); | ||
| // Special case for service workers: report TargetGone event when | ||
| // the worker is destroyed. | ||
| if (_attachedTargetsByTargetId.TryRemove(e.TargetId, out var target)) | ||
| { | ||
| TargetGone?.Invoke(this, new TargetChangedArgs { Target = target, TargetInfo = targetInfo }); | ||
| } | ||
| } |
There was a problem hiding this comment.
These 'if' statements can be combined.
This was referenced Feb 2, 2026
This was referenced Feb 9, 2026
This was referenced Feb 16, 2026
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.
Ports refactoring changes from puppeteer/puppeteer#14602 to improve code organization and maintainability in
ChromeTargetManager.Changes
SilentDetachAsyncas class method - Promotes local function to reusable method for better code organizationGetParentTargethelper - Centralizes parent target extraction with properCdpTargetcastingOnDetachedFromTarget- Uses pattern matching instead of null-conditional castingFinishInitializationIfReadyon the parent's ID instead of the filtered target's IDBehavior Change
The target filter logic now only marks parent Tab targets as initialized when child targets are filtered, rather than marking the filtered target itself. This better reflects the initialization state of the target hierarchy.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.