Skip to main content

Playwright connect_over_cdp — parse endpoints, MLX Launcher start, CDP health + retry. CLI: cdp-connect.

Project description

cdp-connect-kit

Playwright connect_over_cdp kit — parse MLX Launcher ports, health-check CDP, retry Playwright attach with metrics.

PyPI version Python versions License: MIT

pip install cdp-connect-kit
cdp-connect ping 127.0.0.1:9222

CLI: cdp-connect · Python 3.10+ · optional [mlx] for Launcher helpers

CDP connection toolkit — parse Chrome DevTools Protocol endpoints, validate WebSocket URLs, connect Playwright with retry + timeout + health metrics, and watch endpoint uptime.

Optional [mlx] extra: start Multilogin X profiles via Launcher API → auto connect_over_cdp.

Problem

Connecting Playwright to a remote or antidetect browser over CDP fails for predictable reasons:

  • Wrong URL shape (ws:// vs http://127.0.0.1:PORT)
  • Browser not finished starting
  • Fragile one-shot connect_over_cdp with no metrics

cdp-connect normalizes endpoints, waits for /json/version, retries connections, and reports health.

Install

pip install cdp-connect-kit
playwright install chromium

MLX Launcher integration:

pip install cdp-connect-kit[mlx]

Quick start

# Ping a CDP endpoint (HTTP or WebSocket URL)
cdp-connect ping ws://127.0.0.1:9222/devtools/browser/abc

# Connect Playwright and screenshot
cdp-connect playwright --endpoint http://127.0.0.1:9222 --screenshot out.png

# Watch health — JSON Lines for farm-runner piping
cdp-connect watch --endpoint 127.0.0.1:9222 --interval 5 | tee health.jsonl

Connection flow

sequenceDiagram
    participant MLX as MLX Launcher
    participant CDP as CDP HTTP :PORT
    participant PW as Playwright

    MLX->>MLX: GET /profile/.../start
    MLX-->>CDP: data.port → http://127.0.0.1:PORT
    PW->>CDP: GET /json/version
    CDP-->>PW: webSocketDebuggerUrl
    PW->>PW: connect_over_cdp(http://127.0.0.1:PORT)

CLI

Command Description
cdp-connect ping ENDPOINT Validate /json/version, print WebSocket URL
cdp-connect playwright --endpoint URL [--screenshot FILE] Connect with retry, emit metrics JSON
cdp-connect watch --endpoint URL Poll health as JSON Lines (default)
cdp-connect watch --format plain Human-readable UP/DOWN lines
cdp-connect playwright --max-retries N Connect with exponential backoff
cdp-connect mlx-start --profile-id UUID [--print-cdp-url] Start MLX profile, wait for CDP ([mlx])
cdp-connect mlx-stop --profile-id UUID Stop MLX profile — idempotent ([mlx])
cdp-connect mlx-list List running Launcher sessions ([mlx])

Endpoint formats: http://127.0.0.1:9222, ws://127.0.0.1:9222/devtools/browser/…, 127.0.0.1:9222 (shorthand; default port 9222).

MLX launcher flow

  1. GET launcher.mlx.yt:45001/api/v2/profile/f/{folder}/p/{profile}/start?automation_type=playwright
  2. Read data.port from JSON response
  3. CDP HTTP base = http://127.0.0.1:{port}
  4. GET /json/versionwebSocketDebuggerUrl
  5. playwright.chromium.connect_over_cdp(http://127.0.0.1:{port})

Canonical MLX bridge for the monorepo: docs/MLX_INTEGRATION.md · Env: docs/ENV.md

export MLX_TOKEN="..."
export MLX_FOLDER_ID="..."
export MLX_LAUNCHER_URL="https://launcher.mlx.yt:45001"   # optional

# Scripting: CDP URL on stdout
CDP_URL=$(cdp-connect mlx-start --profile-id PROFILE_UUID --print-cdp-url)

cdp-connect mlx-list
cdp-connect mlx-stop --profile-id PROFILE_UUID

API

from cdp_connect_kit import CdpClient, connect_playwright, parse_endpoint
import asyncio

async def main():
    client = CdpClient("127.0.0.1:9222")
    print(client.resolve_websocket_url())
    browser, pw, metrics = await connect_playwright("127.0.0.1:9222", max_retries=5)
    print(metrics.to_dict())
    await browser.close()
    await pw.stop()

asyncio.run(main())
Symbol Description
parse_endpoint(url) Normalize HTTP / WS / host:port
CdpClient /json/version, /json/list, health_snapshot()
connect_playwright(endpoint) Retry wrapper → (browser, playwright, ConnectMetrics)
watch_endpoint(endpoint) Async health polling

ConnectMetrics

{
  "endpoint": "http://127.0.0.1:9222",
  "web_socket_url": "ws://127.0.0.1:9222/devtools/browser/...",
  "attempts": 1,
  "connect_ms": 842.1,
  "ready_ms": 120.5,
  "target_count": 3
}

When connect_over_cdp keeps failing (playbook)

Most failures are endpoint shape or browser not ready — not Playwright bugs.

Error pattern Likely cause Fix
Connection refused Port not open yet cdp-connect ping in a loop; MLX: mlx-start --wait-timeout
Invalid URL / WS mismatch Passed raw ws://… without version fetch Use HTTP base http://127.0.0.1:PORT; let client resolve WS
Works once, flaky in farm Race on profile start watch --endpoint URL → JSONL for farm-runner; retry connect_playwright
Chrome 136+ local profile Default user-data-dir blocks CDP Custom profile dir or antidetect Launcher port
MLX 401 / timeout Agent not running or wrong token MLX_TOKEN, desktop agent up; see docs/ENV.md

MLX → Playwright pipeline:

export MLX_TOKEN=... MLX_FOLDER_ID=...
CDP_URL=$(cdp-connect mlx-start --profile-id PROFILE_UUID --print-cdp-url)
cdp-connect ping "$CDP_URL"
cdp-connect playwright --endpoint "$CDP_URL" --max-retries 5
# farm scripts: export CDP_URL for child processes
cdp-probe run --cdp-endpoint "$CDP_URL" --url https://example.com
cdp-connect mlx-stop --profile-id PROFILE_UUID

Canonical API details: docs/MLX_INTEGRATION.md.

Limitations

  • Chromium CDP onlyconnect_over_cdp targets Chromium-based browsers.
  • MLX requires local agent — Launcher API needs Multilogin desktop running.
  • Watch mode uses HTTP discovery only; JSONL output is designed for automation-farm-runner ingestion.
  • Not a fingerprint tool — connects to browsers; does not modify profiles.

Production

Use cdp-connect mlx-startconnect_playwright in farm scripts and probes; pair with farm-runner (automation-farm-runner) for folder pools. Export CDP_URL for human-input-kit warmup and playwright-cdp-probe checks on the same Launcher session.

Partner note (affiliate): When Playwright must attach to Multilogin X Launcher CDP ports (not vanilla --remote-debugging-port), isolated profiles are the intended production path. Eligible new browser purchases may accept code SAAS50 at multilogin.com — verify terms before checkout. ping / playwright / watch work on any CDP server without MLX. Full disclosure: docs/AFFILIATE.md. Coupon details only via cdp-connect --show-deal (never printed by default).

FAQ: docs/FAQ.md — Playwright connect_over_cdp, Multilogin Launcher, CDP health check.

Related tools (on PyPI)

Package CLI Role
playwright-cdp-probe cdp-probe CDP / WebDriver exposure score
cookie-jar-bridge cookie-bridge Netscape ↔ Playwright cookies
proxy-lane-checker proxy-lane Proxy TCP / HTTP / geo / DNSBL
fingerprint-coherence fp-coherence UA / screen / timezone lint

Toolkit pipeline: proxy-lane checkfp-coherence audit → automate → cdp-probe runcookie-bridge validate

License

MIT


Production antidetect: Multilogin X · Code SAAS50 (-50% browser) · MIN50 (-50% cloud phone)
More scripts: @Multilogin_Scripts_Bot · Coupons

Project details


Download files

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

Source Distribution

cdp_connect_kit-0.3.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdp_connect_kit-0.3.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file cdp_connect_kit-0.3.1.tar.gz.

File metadata

  • Download URL: cdp_connect_kit-0.3.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for cdp_connect_kit-0.3.1.tar.gz
Algorithm Hash digest
SHA256 dbfedf4d7f2ef8d1bf223d1bd744b7ee5faf637490f5628885067d43cd08ae93
MD5 6af51cb3c3e6048d20eb85b77949f7f4
BLAKE2b-256 a691961eae3829652fcb4c610965c77676e9b3d69e8e10093806d2ec66cad983

See more details on using hashes here.

File details

Details for the file cdp_connect_kit-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cdp_connect_kit-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef1f1c27955164f876b654902ea72900b96908cc5ac23e6d5a8a82e57060c4d2
MD5 b4504b6923f7f7b8f6988b801159774c
BLAKE2b-256 45b3ea585eb4aa4232c604c42f8cad5ba1968f56ab466a81b2214ae1017c4e24

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