Skip to main content

CDP Command Forwarding

The primary method for browser control is forwardCDPCommand, which proxies Chrome DevTools Protocol commands.

forwardCDPCommand

method
string
required
The CDP method to execute (e.g., Page.navigate)
params
object
Parameters for the CDP method
sessionId
string
Target session ID (optional - defaults to first attached tab)
Navigate to a URL.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Page.navigate",
    "params": {
      "url": "https://example.com"
    }
  }
}

Page.reload

Reload the current page.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Page.reload",
    "params": {
      "ignoreCache": true
    }
  }
}

Tab Management

Target.createTarget

Open a new tab.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Target.createTarget",
    "params": {
      "url": "https://example.com"
    }
  }
}

Target.closeTarget

Close a tab.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Target.closeTarget",
    "params": {
      "targetId": "XYZ789"
    }
  }
}

Target.activateTarget

Bring a tab to focus.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Target.activateTarget",
    "params": {
      "targetId": "XYZ789"
    }
  }
}

JavaScript Execution

Runtime.evaluate

Execute JavaScript in the page context.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Runtime.evaluate",
    "params": {
      "expression": "document.title",
      "returnByValue": true
    }
  }
}

Input Events

Input.dispatchMouseEvent

Simulate mouse actions.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Input.dispatchMouseEvent",
    "params": {
      "type": "mousePressed",
      "x": 100,
      "y": 200,
      "button": "left",
      "clickCount": 1
    }
  }
}
Mouse event types:
  • mousePressed
  • mouseReleased
  • mouseMoved

Input.dispatchKeyEvent

Simulate keyboard input.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Input.dispatchKeyEvent",
    "params": {
      "type": "keyDown",
      "key": "Enter"
    }
  }
}

Screenshots

Page.captureScreenshot

Capture the visible page area.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "Page.captureScreenshot",
    "params": {
      "format": "png",
      "quality": 100
    }
  }
}
The data field contains base64-encoded image data.

DOM Operations

DOM.getDocument

Get the document root node.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "DOM.getDocument",
    "params": {
      "depth": 2
    }
  }
}

DOM.querySelector

Find an element by CSS selector.
{
  "id": 1,
  "method": "forwardCDPCommand",
  "params": {
    "method": "DOM.querySelector",
    "params": {
      "nodeId": 1,
      "selector": "#search-input"
    }
  }
}

Events

The Gateway forwards CDP events from the browser:
{
  "method": "forwardCDPEvent",
  "params": {
    "sessionId": "cb-tab-1",
    "method": "Page.loadEventFired",
    "params": {
      "timestamp": 12345.678
    }
  }
}
Common events:
  • Page.loadEventFired - Page finished loading
  • Page.frameNavigated - Frame navigation completed
  • Runtime.consoleAPICalled - Console message logged
  • Target.attachedToTarget - Tab attached
  • Target.detachedFromTarget - Tab detached

Full CDP Reference

For complete CDP documentation, see: