Skip to content

Comments

refactor: align ChromeTargetManager with Puppeteer PR #14602#3107

Merged
kblok merged 2 commits intomasterfrom
copilot/check-apply-changes-puppeteer
Jan 28, 2026
Merged

refactor: align ChromeTargetManager with Puppeteer PR #14602#3107
kblok merged 2 commits intomasterfrom
copilot/check-apply-changes-puppeteer

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Ports refactoring changes from puppeteer/puppeteer#14602 to improve code organization and maintainability in ChromeTargetManager.

Changes

  • Extract SilentDetachAsync as class method - Promotes local function to reusable method for better code organization
  • Add GetParentTarget helper - Centralizes parent target extraction with proper CdpTarget casting
  • Refine service worker destruction logic - Separates type check from attachment check for clarity
  • Improve type handling in OnDetachedFromTarget - Uses pattern matching instead of null-conditional casting
  • Adjust filtered target initialization - When filtering targets with Tab parents, call FinishInitializationIfReady on the parent's ID instead of the filtered target's ID

Behavior 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.

// Before
if (_targetFilterFunc?.Invoke(target) == false)
{
    FinishInitializationIfReady(targetInfo.TargetId);
}

// After  
if (_targetFilterFunc?.Invoke(target) == false)
{
    if (parentTarget?.TargetInfo.Type == TargetType.Tab)
    {
        FinishInitializationIfReady(parentTarget.TargetId);
    }
}

💡 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.

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
Copilot AI requested a review from kblok January 27, 2026 21:06
@kblok kblok marked this pull request as ready for review January 28, 2026 01:53
Copilot AI review requested due to automatic review settings January 28, 2026 01:53
@kblok kblok merged commit 7d05289 into master Jan 28, 2026
14 of 16 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports refactoring changes from puppeteer/puppeteer#14602 to improve code organization and maintainability in the ChromeTargetManager class.

Changes:

  • Extracts SilentDetachAsync as a reusable class method and adds GetParentTarget helper for cleaner code organization
  • Refines service worker destruction logic by separating type checking from attachment checking for better clarity
  • Improves pattern matching in OnDetachedFromTarget for 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 });
}
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 'if' statements can be combined.

Copilot uses AI. Check for mistakes.
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.

2 participants