Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Playwright/Core/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ internal class Browser : ChannelOwner, IBrowser
internal string? _tracesDir = null;
internal BrowserType _browserType = null!;
internal string? _closeReason;
private readonly EventHandler<Exception> _onConnectionClose;

internal Browser(ChannelOwner parent, string guid, BrowserInitializer initializer) : base(parent, guid)
{
IsConnected = true;
_initializer = initializer;
_onConnectionClose = (_, _) => DidClose();
_connection.Close += _onConnectionClose;
}

public event EventHandler<IBrowser>? Disconnected;
Expand Down Expand Up @@ -286,6 +289,11 @@ private void DidCreateContext(BrowserContext context)

internal void DidClose()
{
if (!IsConnected)
{
return;
}
_connection.Close -= _onConnectionClose;
IsConnected = false;
Disconnected?.Invoke(this, this);
_closedTcs.TrySetResult(true);
Expand Down
Loading