Skip to main content

CDP-Socket

Feel free to test my code!

Getting Started

Dependencies

Installing

getting started

from cdp_socket.utils.utils import launch_chrome, random_port
from cdp_socket.utils.conn import get_websock_url

from cdp_socket.socket import SingleCDPSocket

import os
import asyncio


async def main():
    PORT = random_port()
    process = launch_chrome(PORT)

    websock_url = await get_websock_url(PORT, timeout=5)
    async with SingleCDPSocket(websock_url, timeout=5) as conn:
        targets = await conn.exec("Target.getTargets")
        print(targets)

    os.kill(process.pid, 15)


asyncio.run(main())

on_closed callback

from cdp_socket.socket import SingleCDPSocket

def on_closed(code, reason):
    print("Closed with: ", code, reason)

async with SingleCDPSocket('ws://localhost:52395/devtools/page/9E297E3F03148EFBC52F26EB3E5A6474', timeout=5) as conn:
    conn.on_closed = on_closed
    targets = await conn.exec("Target.getTargets")
    print(targets)

add event listener

from cdp_socket.socket import SingleCDPSocket
import asyncio

def on_detached(params):
    print("Detached with: ", params)
    
async with SingleCDPSocket('ws://localhost:52395/devtools/page/9E297E3F03148EFBC52F26EB3E5A6474', timeout=5) as conn:
        conn.add_listener('Inspector.detached', on_detached)
        await asyncio.sleep(1000)

iterate over event

from cdp_socket.socket import SingleCDPSocket

async with SingleCDPSocket('ws://localhost:52395/devtools/page/9E297E3F03148EFBC52F26EB3E5A6474', timeout=5) as conn:
    async for i in conn.method_iterator('Inspector.detached'):
        print(i)
        break

wait for event

from cdp_socket.socket import SingleCDPSocket

async with SingleCDPSocket('ws://localhost:52395/devtools/page/9E297E3F03148EFBC52F26EB3E5A6474', timeout=5) as conn:
    res = await conn.wait_for('Inspector.detached')
    print(res)

Help

Please feel free to open an issue or fork!

Todo

Deprecated

Authors

Aurin Aegerter

License

Shield: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Disclaimer

I am not responsible what you use the code for!!! Also no warranty!

Acknowledgments

Inspiration, code snippets, etc.

contributors

  • thanks to @Redrrx who gave me some starting-points

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdp-socket-1.0.tar.gz (8.6 kB view details)

Uploaded Source

File details

Details for the file cdp-socket-1.0.tar.gz.

File metadata

  • Download URL: cdp-socket-1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for cdp-socket-1.0.tar.gz
Algorithm Hash digest
SHA256 6fa40a534d7eb106f4ad69362f9bb7f1ca2e202de34f0a8f664fccccca34c8e9
MD5 85ae4f6335083615d0c6ac14097335cb
BLAKE2b-256 b1e54280bba629efa18aa33b3b938e74f08c7bfa2eb2885c41cd7a346e17aa3c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page