Skip to content

Commit 0c42e64

Browse files
authored
Rename Closed to Disconnected (#797)
1 parent 8057843 commit 0c42e64

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

lib/PuppeteerSharp/Browser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Browser(
6565
_contexts = contextIds.ToDictionary(keySelector: contextId => contextId,
6666
elementSelector: contextId => new BrowserContext(Connection, this, contextId));
6767

68-
Connection.Closed += (object sender, EventArgs e) => Disconnected?.Invoke(this, new EventArgs());
68+
Connection.Disconnected += (object sender, EventArgs e) => Disconnected?.Invoke(this, new EventArgs());
6969
Connection.MessageReceived += Connect_MessageReceived;
7070

7171
_chromiumProcess = chromiumProcess;

lib/PuppeteerSharp/CDPSession.cs

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal CDPSession(IConnection connection, TargetType targetType, string sessio
8787
/// <summary>
8888
/// Occurs when the connection is closed.
8989
/// </summary>
90-
public event EventHandler Closed;
90+
public event EventHandler Disconnected;
9191
/// <summary>
9292
/// Gets or sets a value indicating whether this <see cref="CDPSession"/> is closed.
9393
/// </summary>
@@ -295,7 +295,7 @@ internal void Close(string closeReason)
295295
));
296296
}
297297
_callbacks.Clear();
298-
Closed?.Invoke(this, EventArgs.Empty);
298+
Disconnected?.Invoke(this, EventArgs.Empty);
299299
Connection = null;
300300
}
301301

lib/PuppeteerSharp/Connection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal Connection(string url, int delay, IConnectionTransport transport, ILogg
6161
/// <summary>
6262
/// Occurs when the connection is closed.
6363
/// </summary>
64-
public event EventHandler Closed;
64+
public event EventHandler Disconnected;
6565
/// <summary>
6666
/// Occurs when a message from chromium is received.
6767
/// </summary>
@@ -149,7 +149,7 @@ internal void Close(string closeReason)
149149
CloseReason = closeReason;
150150

151151
Transport.StopReading();
152-
Closed?.Invoke(this, new EventArgs());
152+
Disconnected?.Invoke(this, new EventArgs());
153153

154154
foreach (var session in _sessions.Values.ToArray())
155155
{
@@ -288,7 +288,7 @@ internal static async Task<Connection> Create(string url, IConnectionOptions con
288288

289289
/// <summary>
290290
/// Releases all resource used by the <see cref="Connection"/> object.
291-
/// It will raise the <see cref="Closed"/> event and dispose <see cref="Transport"/>.
291+
/// It will raise the <see cref="Disconnected"/> event and dispose <see cref="Transport"/>.
292292
/// </summary>
293293
/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="Connection"/>. The
294294
/// <see cref="Dispose"/> method leaves the <see cref="Connection"/> in an unusable state.

lib/PuppeteerSharp/IConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ internal interface IConnection
4040
/// </summary>
4141
IConnection Connection { get; }
4242
/// <summary>
43-
/// Occurs when the connection is closed.
43+
/// Occurs when the connection is Disconnected.
4444
/// </summary>
45-
event EventHandler Closed;
45+
event EventHandler Disconnected;
4646
/// <summary>
4747
/// Close the connection.
4848
/// </summary>

lib/PuppeteerSharp/LifecycleWatcher.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)