@@ -18,12 +18,11 @@ internal class LifecycleWatcher : IDisposable
1818 [ WaitUntilNavigation . Networkidle2 ] = "networkAlmostIdle"
1919 } ;
2020
21- private static readonly WaitUntilNavigation [ ] _defaultWaitUntil = new [ ] { WaitUntilNavigation . Load } ;
21+ private static readonly WaitUntilNavigation [ ] _defaultWaitUntil = { WaitUntilNavigation . Load } ;
2222
2323 private readonly FrameManager _frameManager ;
2424 private readonly Frame _frame ;
2525 private readonly NavigationOptions _options ;
26- private readonly IConnection _connection ;
2726 private readonly IEnumerable < string > _expectedLifecycle ;
2827 private readonly int _timeout ;
2928 private readonly string _initialLoaderId ;
@@ -33,7 +32,7 @@ internal class LifecycleWatcher : IDisposable
3332 private TaskCompletionSource < bool > _sameDocumentNavigationTaskWrapper ;
3433 private TaskCompletionSource < bool > _lifecycleTaskWrapper ;
3534 private TaskCompletionSource < bool > _terminationTaskWrapper ;
36- private Task _timeoutTask ;
35+ private readonly Task _timeoutTask ;
3736
3837 public LifecycleWatcher (
3938 FrameManager frameManager ,
@@ -66,8 +65,7 @@ public LifecycleWatcher(
6665 frameManager . FrameNavigatedWithinDocument += NavigatedWithinDocument ;
6766 frameManager . FrameDetached += OnFrameDetached ;
6867 frameManager . NetworkManager . Request += OnRequest ;
69- _connection = Connection . FromSession ( frameManager . Client ) ;
70- _connection . Closed += OnConnectionClosed ;
68+ frameManager . Client . Disconnected += OnClientDisconnected ;
7169
7270 _sameDocumentNavigationTaskWrapper = new TaskCompletionSource < bool > ( ) ;
7371 _newDocumentNavigationTaskWrapper = new TaskCompletionSource < bool > ( ) ;
@@ -84,23 +82,23 @@ public LifecycleWatcher(
8482 public Task < Task > TimeoutOrTerminationTask => Task . WhenAny ( _timeoutTask , _terminationTaskWrapper . Task ) ;
8583 public Task LifecycleTask => _lifecycleTaskWrapper . Task ;
8684
87- #endregion
88-
89- #region Private methods
85+ #endregion
9086
91- private void OnConnectionClosed ( object sender , EventArgs e )
92- => Terminate ( new TargetClosedException ( "Navigation failed because browser has disconnected!" , _connection . CloseReason ) ) ;
87+ #region Private methods
9388
94- private void OnFrameDetached ( object sender , FrameEventArgs e )
95- {
96- var frame = e . Frame ;
97- if ( _frame == frame )
98- {
99- Terminate ( new PuppeteerException ( "Navigating frame was detached" ) ) ;
100- return ;
101- }
102- CheckLifecycleComplete ( sender , e ) ;
103- }
89+ private void OnClientDisconnected ( object sender , EventArgs e )
90+ => Terminate ( new TargetClosedException ( "Navigation failed because browser has disconnected!" , _frameManager . Client . CloseReason ) ) ;
91+
92+ private void OnFrameDetached ( object sender , FrameEventArgs e )
93+ {
94+ var frame = e . Frame ;
95+ if ( _frame == frame )
96+ {
97+ Terminate ( new PuppeteerException ( "Navigating frame was detached" ) ) ;
98+ return ;
99+ }
100+ CheckLifecycleComplete ( sender , e ) ;
101+ }
104102
105103 private void CheckLifecycleComplete ( object sender , FrameEventArgs e )
106104 {
@@ -175,7 +173,7 @@ public void Dispose(bool disposing)
175173 _frameManager . FrameNavigatedWithinDocument -= NavigatedWithinDocument ;
176174 _frameManager . FrameDetached -= OnFrameDetached ;
177175 _frameManager . NetworkManager . Request -= OnRequest ;
178- _connection . Closed -= OnConnectionClosed ;
176+ _frameManager . Client . Disconnected -= OnClientDisconnected ;
179177 }
180178
181179 #endregion
0 commit comments