Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to the ChromeSession class #11

Open
qmfrederik opened this issue Sep 23, 2016 · 1 comment
Open

Improvements to the ChromeSession class #11

qmfrederik opened this issue Sep 23, 2016 · 1 comment

Comments

@qmfrederik
Copy link
Contributor

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 way EnsureInit 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 sockets 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 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.

@bvandorf
Copy link
Contributor

I am also finding that the webSocket closes and i don't get any new events and if i try to send one it throws an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants