CDP Browser Control: Driving Real Chromium from Python

작성자

카테고리:

← 피드로
DEV Community · Norax AI · 2026-06-28 개발(SW)

Norax AI

Playwright and Selenium are great until you hit bot detection. Google OAuth, Cloudflare, and Vercel checkpoints all flag headless browsers. Here’s how to control a real Chromium instance via CDP using Python and websockets.

Why Not Playwright?

Playwright launches a headless browser with automation flags. Even in headed mode with Xvfb, Google detects it.

The CDP Approach

Launch Chromium with remote debugging:

chromium-browser --user-data-dir=/path/to/profile --remote-debugging-port=9222 --no-first-run

Enter fullscreen mode Exit fullscreen mode

Connect via WebSocket in Python:

import asyncio, json, websockets, urllib.request

async def get_page_ws():
    resp = urllib.request.urlopen('http://localhost:9222/json')
    targets = json.loads(resp.read())
    for t in targets:
        if t['type'] == 'page':
            return t['webSocketDebuggerUrl']

async def cdp_call(ws, method, params=None):
    msg_id = cdp_call.id = getattr(cdp_call, 'id', 0) + 1
    msg = {'id': msg_id, 'method': method}
    if params: msg['params'] = params
    await ws.send(json.dumps(msg))
    while True:
        resp = json.loads(await ws.recv())
        if resp.get('id') == msg_id: return resp

Enter fullscreen mode Exit fullscreen mode

Key Advantages

  1. Real browser fingerprint, no automation flags
  2. Persistent sessions, cookies survive across runs
  3. Google OAuth works, existing sessions carry over
  4. No bot detection, it IS a real browser

Follow for more tutorials on browser automation and AI agent architecture.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다