Skip to content

Jeomon/CDP-Client

Repository files navigation

CDP Client

Python wrapper for Chrome DevTools Protocol.

Installation

pip install chromedeveloperprotocol-client

Usage

This example shows how to connect to a running browser and fetch its version information.

Hello World Example

import asyncio
import httpx
from cdp import Client

async def get_ws_url(port=9222):
    async with httpx.AsyncClient() as http:
        resp = await http.get(f"http://localhost:{port}/json/version")
        return resp.json()['webSocketDebuggerUrl']

async def main():
    # Connect to an existing browser session
    # Browser must be started with --remote-debugging-port=9222
    ws_url = await get_ws_url()
    
    async with Client(ws_url) as client:
        # Fetch browser version information
        version = await client.browser.get_version({})
        print(f"Browser: {version['product']}")
        
        # Create a new page and navigate
        target = await client.target.create_target({"url": "https://www.google.com"})
        print(f"Created target: {target['targetId']}")

if __name__ == "__main__":
    asyncio.run(main())

Running the Examples

Ensure you have a browser (Chrome or Edge) running with remote debugging enabled:

chrome.exe --remote-debugging-port=9222

About

Python Wrapper for Chrome DevTools Protocol

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors