2525using System . Collections . Generic ;
2626using System . Linq ;
2727using System . Threading . Tasks ;
28+ using Microsoft . Extensions . Logging ;
2829using PuppeteerSharp . Bidi . Core ;
2930using PuppeteerSharp . Cdp . Messaging ;
3031using PuppeteerSharp . Helpers ;
@@ -37,9 +38,12 @@ public class BidiFrame : Frame
3738 private readonly ConcurrentDictionary < BrowsingContext , BidiFrame > _frames = new ( ) ;
3839 private readonly Realms _realms ;
3940
40- internal BidiFrame ( BidiPage parentPage , BidiFrame parentFrame , BrowsingContext browsingContext )
41+ private readonly ILoggerFactory _loggerFactory ;
42+
43+ internal BidiFrame ( BidiPage parentPage , BidiFrame parentFrame , BrowsingContext browsingContext , ILoggerFactory loggerFactory )
4144 {
42- Client = new BidiCdpSession ( this , parentPage . BidiBrowser . LoggerFactory ) ;
45+ Client = new BidiCdpSession ( this , loggerFactory ) ;
46+ _loggerFactory = loggerFactory ;
4347 ParentPage = parentPage ;
4448 ParentFrame = parentFrame ;
4549 BrowsingContext = browsingContext ;
@@ -52,7 +56,18 @@ internal BidiFrame(BidiPage parentPage, BidiFrame parentFrame, BrowsingContext b
5256 }
5357
5458 /// <inheritdoc />
55- public override IReadOnlyCollection < IFrame > ChildFrames { get ; }
59+ public override IReadOnlyCollection < IFrame > ChildFrames
60+ {
61+ get
62+ {
63+ return BrowsingContext . Children . Select ( child =>
64+ {
65+ _frames . TryGetValue ( child , out var frame ) ;
66+
67+ return frame ;
68+ } ) . Where ( frame => frame != null ) . ToList ( ) ;
69+ }
70+ }
5671
5772 /// <inheritdoc/>
5873 public override string Url => BrowsingContext . Url ;
@@ -186,16 +201,16 @@ async Task<Navigation> WaitForEventNavigationAsync()
186201 return waitForResponseTask . Result ;
187202 }
188203
189- internal static BidiFrame From ( BidiPage parentPage , BidiFrame parentFrame , BrowsingContext browsingContext )
204+ /// <inheritdoc />
205+ protected override DeviceRequestPromptManager GetDeviceRequestPromptManager ( ) => throw new System . NotImplementedException ( ) ;
206+
207+ internal static BidiFrame From ( BidiPage parentPage , BidiFrame parentFrame , BrowsingContext browsingContext , ILoggerFactory loggerFactory )
190208 {
191- parentFrame = new BidiFrame ( parentPage , parentFrame , browsingContext ) ;
209+ parentFrame = new BidiFrame ( parentPage , parentFrame , browsingContext , loggerFactory ) ;
192210 parentFrame . Initialize ( ) ;
193211 return parentFrame ;
194212 }
195213
196- /// <inheritdoc />
197- protected internal override DeviceRequestPromptManager GetDeviceRequestPromptManager ( ) => throw new System . NotImplementedException ( ) ;
198-
199214 private PuppeteerException RewriteNavigationError ( Exception ex , string url , int timeoutSettingsNavigationTimeout )
200215 {
201216 return ex is TimeoutException
@@ -259,12 +274,12 @@ private void Initialize()
259274 {
260275 foreach ( var browsingContext in BrowsingContext . Children )
261276 {
262- CreateFrameTarget ( browsingContext ) ;
277+ CreateFrameTarget ( browsingContext , _loggerFactory ) ;
263278 }
264279
265280 BrowsingContext . BrowsingContextCreated += ( sender , args ) =>
266281 {
267- CreateFrameTarget ( args . BrowsingContext ) ;
282+ CreateFrameTarget ( args . BrowsingContext , _loggerFactory ) ;
268283 } ;
269284
270285 BrowsingContext . Closed += ( sender , args ) =>
@@ -322,9 +337,9 @@ private void Initialize()
322337 } ;
323338 }
324339
325- private void CreateFrameTarget ( BrowsingContext browsingContext )
340+ private void CreateFrameTarget ( BrowsingContext browsingContext , ILoggerFactory loggerFactory )
326341 {
327- var frame = From ( null , this , browsingContext ) ;
342+ var frame = From ( null , this , browsingContext , loggerFactory ) ;
328343 _frames . TryAdd ( browsingContext , frame ) ;
329344 ( ( BidiPage ) Page ) . OnFrameAttached ( new FrameEventArgs ( frame ) ) ;
330345
0 commit comments