Web scraping with Chrome Dev Tools Protocol.
Web scraping with Chrome Dev Tools Protocol.
Create Browser instance with dev tools protocol open on port 9222.
Below is the command for linux. The
google-chrome
part will differ for your operating system.
google-chrome --remote-debugging-port=9222 --no-first-run --no-default-browser-check --disable-default-apps --user-data-dir=./browser-data-tmp/
[
"google-chrome",
"--remote-debugging-port=9222",
"--no-first-run",
" --no-default-browser-check",
"--disable-default-apps",
"--user-data-dir=./browser-data-tmp/",
]
Dev Tool Messages
Set Browser Page Viewport
{
"id": 1,
"method": "Emulation.setDeviceMetricsOverride",
"params": {
"width": 800,
"height": 800,
"deviceScaleFactor": 1,
"mobile": False,
}
}
Navigate to a Page
Capture a Screenshot
Trigger a Mouse Click Event a X, Y in the Page.
{
"id": 4,
"method": "Input.dispatchMouseEvent",
"params": {
"type": "mousePressed",
"x": 600,
"y": 700,
"button": "left",
"clickCount": 1,
},
},
{
"id": 5,
"method": "Input.dispatchMouseEvent",
"params": {
"type": "mouseReleased",
"x": 600,
"y": 700,
"button": "left",
"clickCount": 1,
},
},
Move Mouse to a Location.
{
"id": 6,
"method": "Input.dispatchMouseEvent",
"params": {
"type": "mouseMoved",
"x": 770,
"y": 700
}
},
Scroll with Mouse Wheel
{
"id": 7,
"method": "Input.dispatchMouseEvent",
"params": {
"type": "mouseWheel",
"x": 770,
"y": 700,
"deltaX": 0,
"deltaY": 20
}
}
Focus a dom element to start typing and Type Text.