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.

Partner (optional): Production CDP attach goes through MLX Launcher (isolated profiles). Multilogin X · SAAS50 / MIN50 on eligible new purchases. ping / playwright work on any CDP server without MLX. Affiliate disclosure · Multilogin promo codes.

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

Coupon hub: Multilogin promo codes — guides for SAAS50 / MIN50, pricing comparisons, and workflow playbooks. Farm-scale partner note: Folder pools need stable Launcher CDP — Multilogin X is the [mlx] target stack. Code SAAS50 (browser) · coupons: cdp-connect --show-deal.

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. Deals hub: anti-detect.github.io. 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 (partner): Multilogin X · Code SAAS50 (-50% browser) · MIN50 (-50% cloud phone)
Affiliate disclosure — we may earn a commission; offers change on the vendor site. More scripts: @Multilogin_Scripts_Bot · Multilogin promo codes

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.6.tar.gz (26.2 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.6-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cdp_connect_kit-0.3.6.tar.gz
  • Upload date:
  • Size: 26.2 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.6.tar.gz
Algorithm Hash digest
SHA256 4fcafe0a681720f16ef3740f6a5260b53b4f813defe7eed51d5d9934b71072c2
MD5 e4a67b303306d5de112c3e475a8841a0
BLAKE2b-256 96b89e8dd3d47225e316f39ac0d67e910d16a1c4853726f0ce5eb309568c3c28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cdp_connect_kit-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9a433b58685bdddda51d19934bebc45a41402dfb6cd8e7e01bed04b8d94938c6
MD5 6ffe6ccfec9fe8fee834a10ef89a4347
BLAKE2b-256 24e7a4750e9e8a6eecf19fcc08571bfb5df5c7f218616a6929f4efcf1cc5078b

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