Skip to content

Commit

Permalink
Ensure members are initialized before attaching event handlers (#2220)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup authored Jun 8, 2023
1 parent c78f094 commit bfb4597
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/PuppeteerSharp/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ internal Connection(string url, int delay, bool enqueueAsyncMessages, IConnectio

_logger = LoggerFactory.CreateLogger<Connection>();

Transport.MessageReceived += Transport_MessageReceived;
Transport.Closed += Transport_Closed;
_callbacks = new ConcurrentDictionary<int, MessageTask>();
_sessions = new ConcurrentDictionary<string, CDPSession>();
MessageQueue = new AsyncMessageQueue(enqueueAsyncMessages, _logger);
_asyncSessions = new AsyncDictionaryHelper<string, CDPSession>(_sessions, "Session {0} not found");

Transport.MessageReceived += Transport_MessageReceived;
Transport.Closed += Transport_Closed;
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions lib/PuppeteerSharp/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ internal Worker(
Url = url;
_consoleAPICalled = consoleAPICalled;
_exceptionThrown = exceptionThrown;
_client.MessageReceived += OnMessageReceived;

_executionContextCallback = new TaskCompletionSource<ExecutionContext>(TaskCreationOptions.RunContinuationsAsynchronously);
_client.MessageReceived += OnMessageReceived;

_ = _client.SendAsync("Runtime.enable").ContinueWith(
task =>
Expand Down

0 comments on commit bfb4597

Please sign in to comment.