Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chrome-remote-interface

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrome-remote-interface - npm Package Compare versions

Comparing version 0.16.1 to 0.16.2

52

bin/client.js

@@ -12,3 +12,3 @@ #!/usr/bin/env node

const Chrome = require('../');
const CDP = require('../');

@@ -36,6 +36,6 @@ function display(object) {

// by WebSocket URL
options.chooseTab = target;
options.tab = target;
} else {
// by tab id
options.chooseTab = function (tabs) {
options.tab = function (tabs) {
return tabs.findIndex(function (tab) {

@@ -52,7 +52,7 @@ return tab.id === target;

Chrome(options, function (chrome) {
CDP(options, function (client) {
// keep track of registered events
const registeredEvents = {};
const chromeRepl = repl.start({
const cdpRepl = repl.start({
'prompt': '\x1b[32m>>>\x1b[0m ',

@@ -83,3 +83,3 @@ 'ignoreUndefined': true,

.forEach(function (entry) {
chromeRepl.history.push(entry);
cdpRepl.history.push(entry);
});

@@ -90,3 +90,3 @@ }

// only store the last chunk
const entries = chromeRepl.history.slice(0, historySize).reverse().join('\n');
const entries = cdpRepl.history.slice(0, historySize).reverse().join('\n');
fs.writeFileSync(historyFile, entries + '\n');

@@ -98,3 +98,3 @@ }

console.log('\x1b[2K\x1b[G%s', string);
chromeRepl.displayPrompt(true);
cdpRepl.displayPrompt(true);
}

@@ -116,4 +116,4 @@

function overrideEvent(chrome, domainName, itemName) {
const event = chrome[domainName][itemName];
function overrideEvent(client, domainName, itemName) {
const event = client[domainName][itemName];
const eventName = domainName + '.' + itemName;

@@ -123,3 +123,3 @@ // hard code a callback to display the event data

// remove all the listeners (just one actually) anyway
chrome.removeAllListeners(eventName);
client.removeAllListeners(eventName);
const status = {};

@@ -155,5 +155,5 @@ // a filter will always enable/update the listener

// disconnect on exit
chromeRepl.on('exit', function () {
cdpRepl.on('exit', function () {
console.log();
chrome.close();
client.close();
saveHistory();

@@ -170,9 +170,9 @@ });

// add protocol API
chrome.protocol.domains.forEach(function (domainObject) {
client.protocol.domains.forEach(function (domainObject) {
// walk the domain names
const domainName = domainObject.domain;
chromeRepl.context[domainName] = {};
Object.keys(chrome[domainName]).forEach(function (itemName) {
cdpRepl.context[domainName] = {};
Object.keys(client[domainName]).forEach(function (itemName) {
// walk the items in the domain and override commands and events
let item = chrome[domainName][itemName];
let item = client[domainName][itemName];
switch (item.category) {

@@ -183,10 +183,10 @@ case 'command':

case 'event':
item = overrideEvent(chrome, domainName, itemName);
item = overrideEvent(client, domainName, itemName);
break;
}
chromeRepl.context[domainName][itemName] = item;
cdpRepl.context[domainName][itemName] = item;
});
});
}).on('error', function (err) {
console.error('Cannot connect to Chrome:', err.toString());
console.error('Cannot connect to remote endpoint:', err.toString());
});

@@ -196,3 +196,3 @@ }

function list(options) {
Chrome.List(options, function (err, tabs) {
CDP.List(options, function (err, tabs) {
if (err) {

@@ -208,3 +208,3 @@ console.error(err.toString());

options.url = url;
Chrome.New(options, function (err, tab) {
CDP.New(options, function (err, tab) {
if (err) {

@@ -220,3 +220,3 @@ console.error(err.toString());

options.id = args;
Chrome.Activate(options, function (err) {
CDP.Activate(options, function (err) {
if (err) {

@@ -231,3 +231,3 @@ console.error(err.toString());

options.id = args;
Chrome.Close(options, function (err) {
CDP.Close(options, function (err) {
if (err) {

@@ -241,3 +241,3 @@ console.error(err.toString());

function version(options) {
Chrome.Version(options, function (err, info) {
CDP.Version(options, function (err, info) {
if (err) {

@@ -253,3 +253,3 @@ console.error(err.toString());

options.remote = args.remote;
Chrome.Protocol(options, function (err, protocol) {
CDP.Protocol(options, function (err, protocol) {
if (err) {

@@ -256,0 +256,0 @@ console.error(err.toString());

@@ -21,8 +21,8 @@ 'use strict';

this.remote = !!(options.remote);
this.chooseTab = options.chooseTab || function () { return 0; };
this.tab = options.tab || options.chooseTab || function () { return 0; };
// locals
EventEmitter.call(this);
this.notifier = notifier;
this.callbacks = {};
this.nextCommandId = 1;
this._notifier = notifier;
this._callbacks = {};
this._nextCommandId = 1;
// operations

@@ -65,6 +65,6 @@ start.call(this);

// don't notify on user-initiated shutdown ('disconnect' event)
chrome.ws.removeAllListeners('close');
chrome.ws.close();
chrome.ws.once('close', function () {
chrome.ws.removeAllListeners();
chrome._ws.removeAllListeners('close');
chrome._ws.close();
chrome._ws.once('close', function () {
chrome._ws.removeAllListeners();
callback();

@@ -85,6 +85,6 @@ });

const chrome = this;
const id = chrome.nextCommandId++;
const id = chrome._nextCommandId++;
const message = {'id': id, 'method': method, 'params': params};
chrome.ws.send(JSON.stringify(message));
chrome.callbacks[id] = callback;
chrome._ws.send(JSON.stringify(message));
chrome._callbacks[id] = callback;
}

@@ -111,6 +111,6 @@

process.nextTick(function () {
chrome.notifier.emit('connect', chrome);
chrome._notifier.emit('connect', chrome);
});
}).catch(function (err) {
chrome.notifier.emit('error', err);
chrome._notifier.emit('error', err);
});

@@ -137,3 +137,3 @@ }

// fetch the WebSocket URL according to 'chooseTab'
// fetch the WebSocket URL according to 'tab'
function fetchDebuggerURL(options) {

@@ -146,10 +146,10 @@ const chrome = this;

let url;
switch (typeof chrome.chooseTab) {
switch (typeof chrome.tab) {
case 'string':
// a WebSocket URL is specified by the user (e.g., node-inspector)
fulfill(chrome.chooseTab);
fulfill(chrome.tab);
break;
case 'object':
// a tab object is specified by the user
url = chrome.chooseTab.webSocketDebuggerUrl;
url = chrome.tab.webSocketDebuggerUrl;
if (url) {

@@ -165,3 +165,3 @@ fulfill(url);

// the index is used to fetch the proper tab from the list
const tab = tabs[chrome.chooseTab(tabs)];
const tab = tabs[chrome.tab(tabs)];
if (tab) {

@@ -192,3 +192,3 @@ url = tab.webSocketDebuggerUrl;

// disable the permessage-deflate as a temporary fix for #39
chrome.ws = new WebSocket(url, {'perMessageDeflate': false});
chrome._ws = new WebSocket(url, {'perMessageDeflate': false});
} catch (err) {

@@ -200,13 +200,13 @@ // handles bad URLs

// set up event handlers
chrome.ws.on('open', function () {
chrome._ws.on('open', function () {
fulfill();
});
chrome.ws.on('message', function (data) {
chrome._ws.on('message', function (data) {
const message = JSON.parse(data);
handleMessage.call(chrome, message);
});
chrome.ws.on('close', function () {
chrome.notifier.emit('disconnect');
chrome._ws.on('close', function () {
chrome._notifier.emit('disconnect');
});
chrome.ws.on('error', function (err) {
chrome._ws.on('error', function (err) {
reject(err);

@@ -222,3 +222,3 @@ });

if (message.id) {
const callback = chrome.callbacks[message.id];
const callback = chrome._callbacks[message.id];
if (!callback) {

@@ -235,5 +235,5 @@ return;

// unregister command response callback
delete chrome.callbacks[message.id];
delete chrome._callbacks[message.id];
// notify when there are no more pending commands
if (Object.keys(chrome.callbacks).length === 0) {
if (Object.keys(chrome._callbacks).length === 0) {
chrome.emit('ready');

@@ -240,0 +240,0 @@ }

@@ -5,3 +5,2 @@ 'use strict';

const https = require('https');
const util = require('util');

@@ -182,21 +181,31 @@ const defaults = require('./defaults.js');

const webKitVersion = info['WebKit-Version'];
const v8Version = info['V8-Version'];
const match = webKitVersion.match(/\s\(@(\b[0-9a-f]{5,40}\b)/);
const hash = match[1];
const fromChromiumDotOrg = (hash <= 202666);
let templates;
let urls;
if (fromChromiumDotOrg) {
templates = ['https://src.chromium.org/blink/trunk/Source/devtools/protocol.json?p=%s'];
urls = [`https://src.chromium.org/blink/trunk/Source/devtools/protocol.json?p=${hash}`];
} else {
const lastBeforeSplitChromeVersion = '53.0.2758.1'; // before the split (https://crbug.com/580337)
const lastBeforeV8ChromeVersion = '55.0.2854.3'; // before using the JSON from the V8 repo
const chromeVersion = explodeVersion(info.Browser.split('/')[1]);
const lastChromeVersion = explodeVersion('53.0.2758.1'); // before the split (https://crbug.com/580337)
// according to https://www.chromium.org/developers/version-numbers
const beforeSplit = (chromeVersion[2] <= lastChromeVersion[2]); // patch not meaningful
templates = (beforeSplit ?
['https://chromium.googlesource.com/chromium/src/+/%s/third_party/WebKit/Source/devtools/protocol.json?format=TEXT'] :
['https://chromium.googlesource.com/chromium/src/+/%s/third_party/WebKit/Source/core/inspector/browser_protocol.json?format=TEXT',
'https://chromium.googlesource.com/chromium/src/+/%s/third_party/WebKit/Source/platform/v8_inspector/js_protocol.json?format=TEXT']);
const beforeSplit = (chromeVersion[2] <= explodeVersion(lastBeforeSplitChromeVersion)[2]); // patch not meaningful
const beforeFromV8 = (chromeVersion[2] <= explodeVersion(lastBeforeV8ChromeVersion)[2]); // patch not meaningful
if (beforeSplit) {
urls = [`https://chromium.googlesource.com/chromium/src/+/${hash}/third_party/WebKit/Source/devtools/protocol.json?format=TEXT`];
} else if (beforeFromV8) {
urls = [`https://chromium.googlesource.com/chromium/src/+/${hash}/third_party/WebKit/Source/core/inspector/browser_protocol.json?format=TEXT`,
`https://chromium.googlesource.com/chromium/src/+/${hash}/third_party/WebKit/Source/platform/v8_inspector/js_protocol.json?format=TEXT`];
} else if (v8Version) {
urls = [`https://chromium.googlesource.com/chromium/src/+/${hash}/third_party/WebKit/Source/core/inspector/browser_protocol.json?format=TEXT`,
`https://chromium.googlesource.com/v8/v8/+/${v8Version}/src/inspector/js_protocol.json?format=TEXT`];
} else {
console.error('Warning: the protocol might be outdated, see: https://groups.google.com/d/topic/chrome-debugging-protocol/HjyOKainKus/discussion');
// releases which do not provide a V8 version get an old version of the V8 protocol
urls = [`https://chromium.googlesource.com/chromium/src/+/${hash}/third_party/WebKit/Source/core/inspector/browser_protocol.json?format=TEXT`,
`https://chromium.googlesource.com/chromium/src/+/${lastBeforeV8ChromeVersion}/third_party/WebKit/Source/platform/v8_inspector/js_protocol.json?format=TEXT`];
}
}
const urls = templates.map(function (template) {
return util.format(template, hash);
});
const descriptors = [];

@@ -203,0 +212,0 @@ urls.forEach(function (url) {

@@ -12,3 +12,3 @@ {

"homepage": "https://github.com/cyrus-and/chrome-remote-interface",
"version": "0.16.1",
"version": "0.16.2",
"repository": {

@@ -15,0 +15,0 @@ "type": "git",

@@ -19,5 +19,5 @@ chrome-remote-interface [![Build Status](https://travis-ci.org/cyrus-and/chrome-remote-interface.svg?branch=master)](https://travis-ci.org/cyrus-and/chrome-remote-interface)

```javascript
const Chrome = require('chrome-remote-interface');
Chrome(function (chrome) {
with (chrome) {
const CDP = require('chrome-remote-interface');
CDP(function (client) {
with (client) {
Network.requestWillBeSent(function (params) {

@@ -36,3 +36,3 @@ console.log(params.request.url);

}).on('error', function (err) {
console.error('Cannot connect to Chrome:', err);
console.error('Cannot connect to remote endpoint:', err);
});

@@ -76,8 +76,8 @@ ```

[Protocol]: #moduleprotocoloptions-callback
[List]: #modulelistoptions-callback
[New]: #modulenewoptions-callback
[Activate]: #moduleactivateoptions-callback
[Close]: #modulecloseoptions-callback
[Version]: #moduleversionoptions-callback
[Protocol]: #cdpprotocoloptions-callback
[List]: #cdplistoptions-callback
[New]: #cdpnewoptions-callback
[Activate]: #cdpactivateoptions-callback
[Close]: #cdpcloseoptions-callback
[Version]: #cdpversionoptions-callback

@@ -107,2 +107,16 @@ Setup

##### WebView
In order to be inspectable, a WebView must
be [configured for debugging][webview] and the corresponding process ID must be
known. There are several ways to obtain it, for example:
adb shell grep -a webview_devtools_remote /proc/net/unix
Finally, port forwarding can be enabled as follows:
adb forward tcp:9222 localabstract:webview_devtools_remote_<pid>
[webview]: https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews#configure_webviews_for_debugging
### Edge

@@ -135,4 +149,4 @@

The bundled client exposes subcommands to interact with the HTTP frontend
(e.g., [List](#modulelistoptions-callback), [New](#modulenewoptions-callback),
etc.), run with `--help` to display the list of available options.
(e.g., [List](#cdplistoptions-callback), [New](#cdpnewoptions-callback), etc.),
run with `--help` to display the list of available options.

@@ -157,4 +171,4 @@ Here are some examples:

Using the `inspect` subcommand it is possible to
perform [command execution](#chromedomainmethodparams-callback)
and [event binding](#chromedomaineventcallback) in a REPL fashion. But unlike
perform [command execution](#clientdomainmethodparams-callback)
and [event binding](#clientdomaineventcallback) in a REPL fashion. But unlike
the regular API the callbacks are overridden to conveniently display the result

@@ -310,3 +324,3 @@ of the commands and the message of the events. Also, the event binding is

This behavior can be changed by setting the `remote` option to `true`
upon [connection](#moduleoptions-callback), in which case the remote instance is
upon [connection](#cdpoptions-callback), in which case the remote instance is
*asked* to provide its own protocol descriptor.

@@ -319,6 +333,6 @@

- pass a custom protocol descriptor upon [connection](#moduleoptions-callback)
- pass a custom protocol descriptor upon [connection](#cdpoptions-callback)
(`protocol` option);
- use the *raw* version of the [commands](#chromesendmethod-params-callback)
- use the *raw* version of the [commands](#clientsendmethod-params-callback)
and [events](#event-method) interface;

@@ -336,4 +350,14 @@

### module([options], [callback])
The API consists of three parts:
- *DevTools* methods (for those [implementations](#implementations) that support
them, e.g., [List](#cdplistoptions-callback), [New](#cdpnewoptions-callback),
etc.);
- [connection](#cdpoptions-callback) establishment;
- the actual [protocol interaction](#class-cdp).
### CDP([options], [callback])
Connects to a remote instance using the [Chrome Debugging Protocol].

@@ -345,4 +369,4 @@

- `port`: HTTP frontend port. Defaults to `9222`;
- `chooseTab`: determines which tab this instance should attach to. The behavior
changes according to the type:
- `tab`: determines which tab this client should attach to. The behavior changes
according to the type:

@@ -363,2 +387,4 @@ - a `function` that takes the array returned by the `List` method and returns

These options are also valid properties of all the instances of the `CDP` class.
`callback` is a listener automatically added to the `connect` event of the

@@ -374,3 +400,3 @@ returned `EventEmitter`. When `callback` is omitted a `Promise` object is

```javascript
function (chrome) {}
function (client) {}
```

@@ -380,3 +406,3 @@

`chrome` is an instance of the `Chrome` class.
`client` is an instance of the `CDP` class.

@@ -405,3 +431,3 @@ #### Event: 'disconnect'

### module.Protocol([options], [callback])
### CDP.Protocol([options], [callback])

@@ -432,4 +458,4 @@ Fetch the [Chrome Debugging Protocol] descriptor.

```javascript
const Chrome = require('chrome-remote-interface');
Chrome.Protocol(function (err, protocol) {
const CDP = require('chrome-remote-interface');
CDP.Protocol(function (err, protocol) {
if (!err) {

@@ -441,3 +467,3 @@ console.log(JSON.stringify(protocol.descriptor, null, 4));

### module.List([options], [callback])
### CDP.List([options], [callback])

@@ -463,4 +489,4 @@ Request the list of the available open tabs of the remote instance.

```javascript
const Chrome = require('chrome-remote-interface');
Chrome.List(function (err, tabs) {
const CDP = require('chrome-remote-interface');
CDP.List(function (err, tabs) {
if (!err) {

@@ -472,3 +498,3 @@ console.log(tabs);

### module.New([options], [callback])
### CDP.New([options], [callback])

@@ -493,4 +519,4 @@ Create a new tab in the remote instance.

```javascript
const Chrome = require('chrome-remote-interface');
Chrome.New(function (err, tab) {
const CDP = require('chrome-remote-interface');
CDP.New(function (err, tab) {
if (!err) {

@@ -502,5 +528,5 @@ console.log(tab);

### module.Activate([options], [callback])
### CDP.Activate([options], [callback])
Activate an open tab of the remote Chrome instance.
Activate an open tab of the remote instance.

@@ -523,6 +549,6 @@ `options` is an object with the following properties:

```javascript
const Chrome = require('chrome-remote-interface');
Chrome.Activate({'id': 'CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC'}, function (err) {
const CDP = require('chrome-remote-interface');
CDP.Activate({'id': 'CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC'}, function (err) {
if (!err) {
console.log('success! tab is closing');
console.log('success! tab is activated');
}

@@ -532,3 +558,3 @@ });

### module.Close([options], [callback])
### CDP.Close([options], [callback])

@@ -553,4 +579,4 @@ Close an open tab of the remote instance.

```javascript
const Chrome = require('chrome-remote-interface');
Chrome.Close({'id': 'CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC'}, function (err) {
const CDP = require('chrome-remote-interface');
CDP.Close({'id': 'CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC'}, function (err) {
if (!err) {

@@ -565,3 +591,3 @@ console.log('success! tab is closing');

### module.Version([options], [callback])
### CDP.Version([options], [callback])

@@ -587,4 +613,4 @@ Request version information from the remote instance.

```javascript
const Chrome = require('chrome-remote-interface');
Chrome.Version(function (err, info) {
const CDP = require('chrome-remote-interface');
CDP.Version(function (err, info) {
if (!err) {

@@ -596,3 +622,3 @@ console.log(info);

### Class: Chrome
### Class: CDP

@@ -618,3 +644,3 @@ #### Event: 'event'

```javascript
chrome.on('event', function (message) {
client.on('event', function (message) {
if (message.method === 'Network.requestWillBeSent') {

@@ -641,3 +667,3 @@ console.log(message.params);

```javascript
chrome.on('Network.requestWillBeSent', console.log);
client.on('Network.requestWillBeSent', console.log);
```

@@ -653,5 +679,6 @@

response from the remote instance. The interaction is asynchronous so the only
way to serialize a sequence of commands is to use the callback provided by the
`chrome.send` method. This event acts as a barrier and it is useful to avoid the
callback hell in certain simple situations.
way to serialize a sequence of commands is to use the callback provided by
the [`send`](#clientsendmethod-params-callback) method. This event acts as a
barrier and it is useful to avoid the callback hell in certain simple
situations.

@@ -662,6 +689,6 @@ For example to load a URL only after having enabled the notifications of both

```javascript
chrome.Network.enable();
chrome.Page.enable();
chrome.once('ready', function () {
chrome.Page.navigate({'url': 'https://github.com'});
client.Network.enable();
client.Page.enable();
client.once('ready', function () {
client.Page.navigate({'url': 'https://github.com'});
});

@@ -674,3 +701,3 @@ ```

#### chrome.send(method, [params], [callback])
#### client.send(method, [params], [callback])

@@ -701,6 +728,6 @@ Issue a command to the remote instance.

```javascript
chrome.send('Page.navigate', {'url': 'https://github.com'}, console.log);
client.send('Page.navigate', {'url': 'https://github.com'}, console.log);
```
#### chrome.`<domain>`.`<method>`([params], [callback])
#### client.`<domain>`.`<method>`([params], [callback])

@@ -710,3 +737,3 @@ Just a shorthand for:

```javascript
chrome.send('<domain>.<method>', params, callback);
client.send('<domain>.<method>', params, callback);
```

@@ -717,6 +744,6 @@

```javascript
chrome.Page.navigate({'url': 'https://github.com'}, console.log);
client.Page.navigate({'url': 'https://github.com'}, console.log);
```
#### chrome.`<domain>`.`<event>`(callback)
#### client.`<domain>`.`<event>`(callback)

@@ -726,3 +753,3 @@ Just a shorthand for:

```javascript
chrome.on('<domain>.<event>', callback);
client.on('<domain>.<event>', callback);
```

@@ -733,6 +760,6 @@

```javascript
chrome.Network.requestWillBeSent(console.log);
client.Network.requestWillBeSent(console.log);
```
#### chrome.close([callback])
#### client.close([callback])

@@ -739,0 +766,0 @@ Close the connection to the remote instance.

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc