If you have an existing instance of Chrome or Chromium running with remote debugging enabled, you can connect to it using connectOverCDP(). This is only supported for Chromium-based browsers.
1. Start Chrome with remote debugging
Launch your browser with the --remote-debugging-port flag. For example, on macOS:
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-pw
2. Connect with connectOverCDP()
Pass the debugging URL (e.g., http://127.0.0.1:9222) to the connectOverCDP() method.
<?php
require __DIR__.'/vendor/autoload.php';
use Playwright\PlaywrightFactory;
$playwright = PlaywrightFactory::create();
$cdpEndpoint = getenv('CDP_ENDPOINT') ?: 'http://127.0.0.1:9222';
$browser = $playwright->chromium()->connectOverCDP($cdpEndpoint);
$context = $browser->newContext();
$page = $context->newPage();
$page->goto('https://example.com');
echo $page->title().PHP_EOL;
$browser->close();
$playwright->close();