@@ -89,6 +89,8 @@ await _connection.SendAsync(
89
89
await _initializeCompletionSource . Task . ConfigureAwait ( false ) ;
90
90
}
91
91
92
+ public IEnumerable < ITarget > GetChildTargets ( ITarget target ) => target . ChildTargets ;
93
+
92
94
private void StoreExistingTargetsForInit ( )
93
95
{
94
96
foreach ( var kv in _discoveredTargetsByTargetId )
@@ -101,8 +103,11 @@ private void StoreExistingTargetsForInit()
101
103
null ,
102
104
_browser . ScreenshotTaskQueue ) ;
103
105
104
- if ( ( _targetFilterFunc == null || _targetFilterFunc ( targetForFilter ) ) &&
105
- kv . Value . Type != TargetType . Browser )
106
+ // Targets from extensions and the browser that will not be
107
+ // auto-attached. Therefore, we should not add them to
108
+ // #targetsIdsForInit.
109
+ var skipTarget = kv . Value . Type == TargetType . Browser || kv . Value . Url . StartsWith ( "chrome-extension://" , StringComparison . OrdinalIgnoreCase ) ;
110
+ if ( ! skipTarget && ( _targetFilterFunc == null || _targetFilterFunc ( targetForFilter ) ) )
106
111
{
107
112
_targetsIdsForInit . Add ( kv . Key ) ;
108
113
}
@@ -292,6 +297,8 @@ private async Task OnAttachedToTargetAsync(object sender, TargetAttachedToTarget
292
297
_attachedTargetsBySessionId . TryAdd ( session . Id , target ) ;
293
298
}
294
299
300
+ var parentTarget = parentSession ? . Target ;
301
+ parentTarget ? . AddChildTarget ( target ) ;
295
302
( parentSession ?? parentConnection as CDPSession ) ? . OnSessionReady ( session ) ;
296
303
297
304
await EnsureTargetsIdsForInitAsync ( ) . ConfigureAwait ( false ) ;
@@ -380,6 +387,7 @@ private void OnDetachedFromTarget(object sender, TargetDetachedFromTargetRespons
380
387
return ;
381
388
}
382
389
390
+ ( sender as CdpCDPSession ) ? . Target . RemoveChildTarget ( target ) ;
383
391
_attachedTargetsByTargetId . TryRemove ( target . TargetId , out _ ) ;
384
392
TargetGone ? . Invoke ( this , new TargetChangedArgs { Target = target } ) ;
385
393
}