Skip to content

Instantly share code, notes, and snippets.

@diloabininyeri
Last active March 21, 2025 21:16
Show Gist options
  • Save diloabininyeri/7115b2b9aa6ec8367b48b6aed7fd7fb6 to your computer and use it in GitHub Desktop.
Save diloabininyeri/7115b2b9aa6ec8367b48b6aed7fd7fb6 to your computer and use it in GitHub Desktop.
connect to the chrome devtools with the php
<?php
$host = '127.0.0.1';
$port = 9222;
$path = '/devtools/browser/919ac3d2-8dca-4cc9-8a26-c719c19a7b8b';
$socket = stream_socket_client(
'tcp://' . $host . ':' . $port,
$errno,
$errstr,
30,
);
$key = base64_encode(random_bytes(16));
$headers =
"GET $path HTTP/1.1\r\n" .
"Host: $host\r\n" .
"Upgrade: websocket\r\n" .
"Connection: Upgrade\r\n" .
"Sec-WebSocket-Key: $key\r\n" .
"Sec-WebSocket-Version: 13\r\n\r\n";
fwrite($socket, $headers);
$response= fread($socket, 1024);
if(str_contains($response,'HTTP/1.1 101')) {
echo "Connected";
}else{
echo "Not connected";
}
@diloabininyeri
Copy link
Author

google-chrome --headless --remote-debugging-port=9222 --remote-debugging-host=127.0.0.1 --no-sandbox --remote-allow-origins=*
to start google chrome console devtools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment