You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the ChromeSession class with Android devices, I've stumbled upon a couple of improvements which can be made. I haven't had the time yet to backport those changes to ChromeDevTools, but wanted to share them here just in case:
Async all the wayEnsureInit calls Init.Wait(). You can make EnsureInit async by using a SemaphoreSlim instead of a lock to protect the _webSocket field; SemaphoreSlim has a WaitAsync method
Avoid Task.Run A couple of methods which wait for ManualResetEvent classes use Task.Run because ManualResetEvent.WaitOne is a sync method. I've used Nito.AsyncEx, which has an AsyncManualResetEvent, which has an async wait method
Timeouts For whatever reason, the debugger server may not respond, so the code ends up waiting forever in the WaitOne methods. When using the async variant, you can await the MRE & a Delay task, implementing a kind of time-out mechanism.
Recovering from closed socketsEnsureInit checks for _webSocket being null, but it does not account for scenarios where the socket was closed. We're not quite sure yet why we end up with closed sockets from time to time (we believe it may be a server-side timeout), but having EnsureInit check for a closed socket & reopen the socket in that case worked for us
If I find the time 😄 , I'll try to create a PR for this, in meanwhile, already wanted to share this, may be useful for others.
The text was updated successfully, but these errors were encountered:
When using the
ChromeSession
class with Android devices, I've stumbled upon a couple of improvements which can be made. I haven't had the time yet to backport those changes to ChromeDevTools, but wanted to share them here just in case:EnsureInit
callsInit.Wait()
. You can makeEnsureInit
async by using aSemaphoreSlim
instead of a lock to protect the_webSocket
field;SemaphoreSlim
has aWaitAsync
methodTask.Run
A couple of methods which wait forManualResetEvent
classes useTask.Run
becauseManualResetEvent.WaitOne
is a sync method. I've used Nito.AsyncEx, which has anAsyncManualResetEvent
, which has an async wait methodWaitOne
methods. When using the async variant, you can await the MRE & a Delay task, implementing a kind of time-out mechanism.EnsureInit
checks for_webSocket
being null, but it does not account for scenarios where the socket was closed. We're not quite sure yet why we end up with closed sockets from time to time (we believe it may be a server-side timeout), but havingEnsureInit
check for a closed socket & reopen the socket in that case worked for usIf I find the time 😄 , I'll try to create a PR for this, in meanwhile, already wanted to share this, may be useful for others.
The text was updated successfully, but these errors were encountered: