0.8.0 • Published 6 years ago

chrome-connector v0.8.0

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

Chrome Connector

Control any Chrome using Chrome Debugging Protocol.

  • Promise-based sendCommand (async/await)
  • Works everywhere (browser, Node.js, Electron, etc)
  • Thin on dependencies

Usage

First you need to obtain a remote debugging target.

Here's an example of how to do this manually:

# Start Chrome in debugging mode
/path/to/chrome/Chrome --remote-debugging-port=9222
# Obtain a webSocketDebuggerUrl
curl http://localhost:9222/json

This will give you an array of debugging targets like this:

[{
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/74863d10-ff7c-43d9-b847-104c3a39e43f",
   "faviconUrl": "https://www.google.ru/favicon.ico",
   "id": "74863d10-ff7c-43d9-b847-104c3a39e43f",
   "title": "New Tab",
   "type": "page",
   "url": "chrome://newtab/",
   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/74863d10-ff7c-43d9-b847-104c3a39e43f"
}, ...]

You'll need webSocketDebuggerUrl there:

const { ChromeConnector } = require('chrome-connector');

const chrome = new ChromeConnector('ws://localhost:9222/devtools/page/74863d10-ff7c-43d9-b847-104c3a39e43f');

await chrome.connect();

// Send CDP commands
const res = await chrome.sendCommand('Page.navigate', { url: 'http://github.com' });
// Read CDP response
const { frameId } = res;

// Subscribe to CDP events
chrome.on('Page.frameStoppedLoading', params => {
    // Access CDP event parameters
    const { frameId } = params;
});
0.8.0

6 years ago

0.7.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago