{"id":2427,"library":"cdp-use","title":"CDP-Use: Chrome DevTools Protocol Client","description":"CDP-Use is a type-safe Python client library for the Chrome DevTools Protocol (CDP). It provides auto-generated, strongly-typed commands and events, allowing for interaction with browsers like Chrome and Edge, or browser automation tools like Playwright and Puppeteer. It is actively maintained with regular releases, currently at version 1.4.5.","status":"active","version":"1.4.5","language":"en","source_language":"en","source_url":"https://github.com/browser-use/cdp-use","tags":["cdp","chrome-devtools-protocol","browser-automation","testing","devtools","chrome","edge","playwright","puppeteer"],"install":[{"cmd":"pip install cdp-use","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for establishing WebSocket connections to CDP endpoints.","package":"websockets"},{"reason":"Used for type validation and data parsing of CDP messages.","package":"pydantic"}],"imports":[{"note":"The library was renamed from `cdp-py` to `cdp-use` starting with version 1.0.0. Old imports will fail.","wrong":"from cdp_py import CDP","symbol":"CDP","correct":"from cdp_use import CDP"},{"note":"Used to specify the CDP debugging endpoint (e.g., 'http://127.0.0.1:9222').","symbol":"Target","correct":"from cdp_use.target import Target"}],"quickstart":{"code":"import asyncio\nfrom cdp_use import CDP\nfrom cdp_use.target import Target\nimport os\n\nasync def main():\n    # Ensure Chrome/Edge is running with --remote-debugging-port=9222\n    # or connect to a Playwright/Puppeteer launched browser.\n    # The URL can be an HTTP endpoint ('http://...') or a WebSocket URL ('ws://...')\n    cdp_url = os.environ.get(\"CDP_DEBUGGING_URL\", \"http://127.0.0.1:9222\")\n    \n    async with CDP(Target(cdp_url)) as cdp:\n        page = cdp.page\n        await page.enable()\n        print(f\"Navigating to example.com via CDP...\")\n        await page.navigate(\"https://www.example.com\")\n        \n        # Wait for navigation to complete (e.g., load event)\n        await page.await_load_event()\n        \n        current_url = await page.get_navigated_history().result.current_entry.url\n        print(f\"Current URL: {current_url}\")\n        \n        # Example: Get document layout metrics\n        layout_metrics = await page.get_layout_metrics()\n        print(f\"Document content width: {layout_metrics.content_size.width}\")\n\n        await asyncio.sleep(2) # Keep the connection alive briefly for inspection\n\nasyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to connect to a browser's CDP endpoint, navigate to a URL, and fetch some basic page information. Ensure you have a browser running with remote debugging enabled (e.g., `chrome --remote-debugging-port=9222`)."},"warnings":[{"fix":"Update imports from `cdp_py` to `cdp_use` and refactor code to match the new API design. Refer to the `cdp-use` documentation for the updated API.","message":"The library was renamed from `cdp-py` to `cdp-use` starting with version 1.0.0. All previous imports (`from cdp_py import ...`) and parts of the API surface are incompatible with `cdp-use`.","severity":"breaking","affected_versions":"1.0.0+"},{"fix":"Ensure your browser is launched with `--remote-debugging-port=<port>` (e.g., `chrome --remote-debugging-port=9222`) or that your browser automation setup (Playwright, Puppeteer) exposes a CDP endpoint.","message":"CDP-Use connects to an existing Chrome DevTools Protocol endpoint. You must have a browser (Chrome, Edge, Playwright-launched, etc.) running with remote debugging enabled and accessible at the specified `Target` URL.","severity":"gotcha","affected_versions":"All"},{"fix":"Always instantiate and manage the `CDP` client using `async with CDP(Target(...)) as cdp:` within an `async` function.","message":"The `CDP` client is an asynchronous context manager. It's crucial to use it within an `async with` statement to ensure proper connection establishment and graceful closure of the WebSocket connection.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}