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.0.1 to 0.1.0

lib/protocol.js

2

index.js

@@ -5,3 +5,3 @@ var events = require('events');

module.exports = function (options, callback) {
if (typeof callback == 'undefined') {
if (typeof options == 'function') {
callback = options;

@@ -8,0 +8,0 @@ options = undefined;

@@ -0,1 +1,2 @@

var protocol = require('./protocol.js');
var util = require('util');

@@ -8,2 +9,3 @@ var events = require('events');

var self = this;
addCommandShorthands.call(self);
self.notifier = notifier;

@@ -22,3 +24,3 @@ self.callbacks = {};

callback = params;
params = {};
params = undefined;
}

@@ -38,2 +40,18 @@ var message = {'id': id, 'method': method, 'params': params};

function addCommandShorthands() {
var self = this;
for (var domain in protocol.commands) {
Chrome.prototype[domain] = {};
var commands = protocol.commands[domain];
for (var i = 0; i < commands.length; i++) {
var command = commands[i];
(function (method) {
Chrome.prototype[domain][command] = function (params, callback) {
self.send(method, params, callback);
};
})(domain + '.' + command);
}
}
}
function connectToChrome(host, port, chooseTab) {

@@ -49,7 +67,18 @@ var self = this;

var tabs = JSON.parse(data);
var tabIndex = chooseTab(tabs);
var tabDebuggerUrl = tabs[tabIndex].webSocketDebuggerUrl;
connectToWebSocket.call(self, tabDebuggerUrl);
var tab = tabs[chooseTab(tabs)];
if (tab) {
var tabDebuggerUrl = tab.webSocketDebuggerUrl;
if (tabDebuggerUrl) {
connectToWebSocket.call(self, tabDebuggerUrl);
} else {
// a WebSocket is already connected to this tab?
var error = new Error('Unable to connect to the WebSocket');
self.notifier.emit('error', error);
}
} else {
var error = new Error('Invalid tab index');
self.notifier.emit('error', error);
}
});
})
});
request.on('error', function (error) {

@@ -56,0 +85,0 @@ self.notifier.emit('error', error);

@@ -7,3 +7,3 @@ {

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

@@ -18,3 +18,9 @@ "type": "git",

"ws": "0.4.x"
},
"devDependencies": {
"mocha": "*"
},
"scripts": {
"test": "make test"
}
}
chrome-remote-interface
=======================
Chrome [Remote Debugging Protocol][1] interface.
[Remote Debugging Protocol][1] interface that helps to instrument Chrome by
providing a simple abstraction of the two main objects exposed by the protocol
in a Node.js fashion: commands and notifications.

@@ -15,5 +17,5 @@ Installation

Chrome needs to be started with the `--remote-debugging-port=<port>` option to
enable the [Remote Debugging Protocol][1] on the specified port, for example:
enable the [Remote Debugging Protocol][1], for example:
google-chrome --remote-debugging-port=9222 --enable-benchmarking
google-chrome --remote-debugging-port=9222

@@ -28,13 +30,13 @@ Sample usage

Chrome(function (chrome) {
chrome.on('Network.requestWillBeSent', function (message) {
console.log(message.request.url);
});
chrome.on('Page.loadEventFired', function (message) {
chrome.close();
});
chrome.send('Network.enable');
chrome.send('Page.enable');
chrome.send('Page.navigate', {'url': 'https://github.com'});
with (chrome) {
on('Network.requestWillBeSent', function (message) {
console.log(message.request.url);
});
on('Page.loadEventFired', close);
Network.enable();
Page.enable();
Page.navigate({'url': 'https://github.com'});
}
}).on('error', function () {
console.log('Cannot connect to Chrome');
console.error('Cannot connect to Chrome');
});

@@ -80,2 +82,4 @@ ```

`error` is an instance of `Error`.
### Class: Chrome

@@ -106,4 +110,6 @@

This is just a utility event that allows to easily filter out specific
notifications (see the documentation of `event`).
notifications (see the documentation of `event`), for example:
chrome.on('Network.requestWillBeSent', console.log);
#### chrome.send(method, [params], [callback])

@@ -124,2 +130,15 @@

Note that the field `id` mentioned in the [Remote Debugging Protocol
specifications][1] is managed internally and it's not exposed to the user.
#### chrome.Domain.method([params], [callback])
Just a shorthand for:
chrome.send('Domain.method', params, callback)
For example:
chrome.Page.navigate({'url': 'https://github.com'})
#### chrome.close()

@@ -126,0 +145,0 @@

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