HyperionGray / trio-chrome-devtools-protocol

Trio driver for Chrome DevTools Protocol (CDP)
MIT License
60 stars 17 forks source link

API simplified calling, implementation for discussion #6

Closed auphofBSF closed 4 years ago

auphofBSF commented 4 years ago

The following PR is a candidate for Issue API redesign Issue: #1 It allows an alternative call directly to the domain function ie `page.navigate('https://example.com')

see the examples/get_title_simple_calls.py

This PR is offered as a discussion, there are many ways to do this, so I thought I will just try 1 way and see what roadblocks emerge. The session is stored in a Singleton class. The cdp api is decorated with the necessary calls and is then transparent in that the documentation is passed through as well, results etc,

One can change the session by CDP_Active_Session_Manager.getInstance().session = await conn.open_session(<TARGET_ID>) Possibly something can be done to here to enable switching different sessions by some form of context - Needs further exploration

This has been a steep learning exercise in decorators and I do not profess to have a perfect implementation but it is working for me and my source code is tidy.

I have been using this in Jupyter with great work done by @mehaase in gettting trio to work in Jupyter using the GLOBAL_NURSERY.

For working in jupyter ensure IPython 7.12 is installed and install the ipykernal from https://github.com/HyperionGray/ipykernel.git checkout branch trio-loop and install for development with pip install -e .

auphofBSF commented 4 years ago

This PR Travis failures are addressed in PR #7

mehaase commented 4 years ago

Thank you for writing this up and submitting it. It's definitely a novel solution that I had not thought of. I checked it out inside a Jupyter notebook to play around with it.

Pros:

Cons:

This is a great PR for discussion, however. I have an idea I will post on the original issue.

auphofBSF commented 4 years ago

I will close this PR , have not had time to merge #9 but cant see any issue, and look forward to trying it