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

Event example ? #14

Open
benoitgaly opened this issue May 23, 2020 · 1 comment
Open

Event example ? #14

benoitgaly opened this issue May 23, 2020 · 1 comment

Comments

@benoitgaly
Copy link

Hi,

If it is possible in the documentation to understand how to use trio_cdp for event management like cdp.network.RequestWillBeSent ... it would be of great help

@mehaase
Copy link
Contributor

mehaase commented May 26, 2020

The documentation definitely needs to be improved for event handling. On the Trio CDP side, there are two APIs. The first API waits for a single event and returns the result.

async with session.wait_for(network.RequestWillBeSent) as result:
   await ... # do something here that triggers an event
print(result.value) # the value is available after leaving the block

The second API is for getting a stream of events:

async for event in session.listen(network.RequestWillBeSent):
  print("got event", event)

Since this one loops over the events, you'll want to call it in a new task so that you can keep doing work on the main task.

On the Chrome side, the protocol events are documented pretty poorly. I've figured out a few of them by trial and error, though. With the network domain, you will need to call network.enable() prior to getting any events. You might also try the fetch domain which has similar features but is a little friendlier.

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