{"library":"pychrome","title":"A Python Package for the Google Chrome Dev Protocol","description":"pychrome is a Python package designed for interacting with Google Chrome via the Chrome DevTools Protocol. It enables automation and inspection of web pages, allowing users to control browser behavior, capture network traffic, manipulate the DOM, and more. The current version is 0.2.4, with development actively maintained on GitHub.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install -U pychrome"],"cli":null},"imports":["import pychrome\nbrowser = pychrome.Browser()","import pychrome\nbrowser = pychrome.Browser()\ntab = browser.new_tab()"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pychrome\nimport os\nimport subprocess\nimport time\n\n# --- Step 1: Ensure Chrome is running with remote debugging enabled ---\n# This command typically opens Chrome (or a headless instance) on port 9222.\n# Adjust the path to your Chrome executable if needed.\n# For headless mode: 'google-chrome --headless --disable-gpu --remote-debugging-port=9222'\n\n# Check if Chrome is already running on the debug port\ntry:\n    # Attempt to connect to check if a browser is already listening\n    _ = pychrome.Browser(url=\"http://127.0.0.1:9222\").list_tab()\n    print(\"Chrome with remote debugging already running.\")\nexcept Exception:\n    print(\"Starting Chrome with remote debugging...\")\n    # Example for Linux/macOS. Adjust for Windows (e.g., 'start chrome.exe ...')\n    # Using os.environ.get for robustness in different environments\n    chrome_cmd = os.environ.get('CHROME_EXECUTABLE', 'google-chrome')\n    try:\n        # Start Chrome in headless mode for automation\n        subprocess.Popen([chrome_cmd, '--headless', '--disable-gpu', '--remote-debugging-port=9222'],\n                           stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n        time.sleep(2) # Give Chrome a moment to start up\n    except FileNotFoundError:\n        print(f\"Error: Chrome executable '{chrome_cmd}' not found. Please set CHROME_EXECUTABLE environment variable or ensure Chrome is in your PATH.\")\n        exit(1)\n\n# --- Step 2: Connect to Chrome and perform actions ---\nbrowser = pychrome.Browser(url=\"http://127.0.0.1:9222\")\n\n# List existing tabs or create a new one\ntabs = browser.list_tab()\nif not tabs:\n    tab = browser.new_tab()\nelse:\n    # Use the first available tab, or iterate to find a specific one\n    tab = tabs[0]\n\ndef request_will_be_sent(**kwargs):\n    \"\"\"Callback function to print URLs of outgoing requests\"\"\"\n    url = kwargs.get('request', {}).get('url')\n    if url:\n        print(f\"  Loading: {url}\")\n\ntry:\n    print(f\"Interacting with tab: {tab.id}\")\n    tab.start()\n    tab.Network.enable()\n    tab.Network.requestWillBeSent = request_will_be_sent # Register callback\n\n    print(\"Navigating to example.com...\")\n    tab.Page.navigate(url=\"https://www.example.com\", _timeout=5)\n    tab.wait(5) # Wait for page to load events for 5 seconds\n\n    # Execute some JavaScript on the page\n    result = tab.Runtime.evaluate(expression=\"document.title\")\n    print(f\"Page title: {result['result']['value']}\")\n\nfinally:\n    # Clean up: stop the tab and close it\n    if tab:\n        tab.stop()\n        browser.close_tab(tab.id)\n        print(f\"Closed tab: {tab.id}\")\n    # In a real application, you might also want to close the browser process\n    # if it was started by your script, but care is needed not to close \n    # a user's active browser session.\n","lang":"python","description":"This quickstart demonstrates how to connect to a running Chrome instance with remote debugging enabled, create a new tab, navigate to a URL, register a callback for network requests, and execute JavaScript to get the page title. It includes a robust way to ensure Chrome is running on the correct port before attempting to connect.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"0.2.4","pypi_latest":"0.2.4","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.3,"avg_import_s":0.61,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.59,"mem_mb":10.6,"disk_size":"22.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.4,"mem_mb":10.6,"disk_size":"23M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.76,"mem_mb":11.8,"disk_size":"25.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.4,"import_time_s":0.7,"mem_mb":11.8,"disk_size":"26M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.65,"mem_mb":11.6,"disk_size":"16.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.67,"mem_mb":11.6,"disk_size":"17M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.67,"mem_mb":11.9,"disk_size":"16.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.64,"mem_mb":11.9,"disk_size":"17M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.52,"mem_mb":10.2,"disk_size":"21.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"-U","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.48,"mem_mb":10.2,"disk_size":"22M"}]}}