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.1.1 to 0.2.0

bin/repl.js

8

index.js

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

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

@@ -15,3 +15,3 @@ options = undefined;

var notifier = new events.EventEmitter();
if (typeof callback == 'function') {
if (typeof callback === 'function') {
notifier.on('connect', callback);

@@ -23,4 +23,4 @@ }

// to simply check the connection
if (notifier.listeners('connect').length == 0) {
notifier.on('connect', function(chrome) {
if (notifier.listeners('connect').length === 0) {
notifier.on('connect', function (chrome) {
chrome.close();

@@ -27,0 +27,0 @@ });

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

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

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

connectToChrome.call(self, options.host, options.port, options.chooseTab);
}
};

@@ -22,3 +22,3 @@ util.inherits(Chrome, events.EventEmitter);

var id = self.nextCommandId++;
if (typeof params == 'function') {
if (typeof params === 'function') {
callback = params;

@@ -30,6 +30,6 @@ params = undefined;

// register command response callback
if (typeof callback == 'function') {
if (typeof callback === 'function') {
self.callbacks[id] = callback;
}
}
};

@@ -40,17 +40,55 @@ Chrome.prototype.close = function () {

self.ws.close();
};
function addCommand(domainName, command) {
var self = this;
Chrome.prototype[domainName][command.name] = function (params, callback) {
self.send(domainName + '.' + command.name, params, callback);
};
Chrome.prototype[domainName][command.name].help = command;
}
function addEvent(domainName, event) {
var self = this;
Chrome.prototype[domainName][event.name] = function (handler) {
self.on(domainName + '.' + event.name, handler);
};
Chrome.prototype[domainName][event.name].help = event;
}
function addType(domainName, type) {
var self = this;
Chrome.prototype[domainName][type.id] = type;
}
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);
for (var domainIdx in protocol.domains) {
var domain = protocol.domains[domainIdx];
var domainName = domain.domain;
Chrome.prototype[domainName] = {};
// add commands
var commands = domain.commands;
if (commands) {
for (var commandIdx in commands) {
var command = commands[commandIdx];
addCommand.call(self, domainName, command);
}
}
// add events
var events = domain.events;
if (events) {
for (var eventIdx in events) {
var event = events[eventIdx];
addEvent.call(self, domainName, event);
}
}
// add types
var types = domain.types;
if (types) {
for (var typeIdx in types) {
var type = types[typeIdx];
addType.call(self, domainName, type);
}
}
}

@@ -68,2 +106,3 @@ }

response.on('end', function () {
var error;
var tabs = JSON.parse(data);

@@ -77,7 +116,7 @@ var tab = tabs[chooseTab(tabs)];

// a WebSocket is already connected to this tab?
var error = new Error('Unable to connect to the WebSocket');
error = new Error('Unable to connect to the WebSocket');
self.notifier.emit('error', error);
}
} else {
var error = new Error('Invalid tab index');
error = new Error('Invalid tab index');
self.notifier.emit('error', error);

@@ -95,3 +134,3 @@ }

self.ws = new WebSocket(url);
self.ws.on('open', function() {
self.ws.on('open', function () {
self.notifier.emit('connect', self);

@@ -98,0 +137,0 @@ });

{
"name": "chrome-remote-interface",
"author": "Andrea Cardaci <cyrus.and@gmail.com>",
"contributors": [
{
"name": "Andrey Sidorov",
"email": "sidoares@yandex.ru"
}
],
"description": "Chrome Remote Debugging Protocol interface",
"keywords": ["chrome", "remote", "debug", "interface"],
"homepage": "https://github.com/cyrus-and/chrome-remote-interface",
"version": "0.1.1",
"version": "0.2.0",
"repository": {

@@ -18,2 +24,5 @@ "type": "git",

},
"bin": {
"chrome-repl": "./bin/repl.js"
},
"devDependencies": {

@@ -20,0 +29,0 @@ "mocha": "*"

@@ -21,4 +21,4 @@ chrome-remote-interface

Sample usage
------------
Sample API usage
----------------

@@ -44,2 +44,39 @@ The following snippet loads `https://github.com` and dumps every request made.

REPL interface and embedded documentation
-----------------------------------------
This module comes with a REPL interface that can be used to interactively
control Chrome. The context is set to the `chrome` object so any issued command
operates on it, just like the statements contained in the `with` block in the
above example. Here's a sample session:
```javascript
chrome> Network.enable()
chrome> Network.requestWillBeSent(console.log)
chrome> Page.navigate({url: 'https://github.com'})
```
Using the provided `help` field it's possible to obtain information on the
events and methods available through the [Remote Debugging Protocol][1]. For
example to learn how to call `Page.navigate` type:
```javascript
chrome> Page.navigate.help
{ name: 'navigate',
parameters:
[ { name: 'url',
type: 'string',
description: 'URL to navigate the page to.' } ],
description: 'Navigates current page to the given URL.' }
```
For what concerns the types instead, just type its name:
```javascript
chrome> Network.Timestamp
{ id: 'Timestamp',
type: 'number',
description: 'Number of seconds since epoch.' }
```
API

@@ -135,8 +172,18 @@ ---

chrome.send('Domain.method', params, callback)
chrome.send('Domain.method', params, callback);
For example:
chrome.Page.navigate({'url': 'https://github.com'})
chrome.Page.navigate({'url': 'https://github.com'});
#### chrome.Domain.event(callback)
Just a shorthand for:
chrome.on('Domain.event', callback);
For example:
chrome.Network.requestWillBeSent(console.log);
#### chrome.close()

@@ -146,2 +193,7 @@

Contributors
------------
* [Andrey Sidorov](https://github.com/sidorares)
Resources

@@ -148,0 +200,0 @@ ---------

@@ -7,3 +7,3 @@ var Chrome = require('../');

it('should succeed with "connect" callback passed as an argument', function (done) {
Chrome(function(chrome) {
Chrome(function (chrome) {
chrome.close();

@@ -16,3 +16,3 @@ done();

it('should succeed with "connect" callback registered later', function (done) {
Chrome().on('connect', function(chrome) {
Chrome().on('connect', function (chrome) {
chrome.close();

@@ -27,3 +27,3 @@ done();

it('should succeed with "connect" callback passed as an argument', function (done) {
Chrome({'host': 'localhost', 'port': 9222}, function(chrome) {
Chrome({'host': 'localhost', 'port': 9222}, function (chrome) {
chrome.close();

@@ -33,6 +33,6 @@ done();

assert(false);
});;
});
});
it('should succeed with "connect" callback registered later', function (done) {
Chrome({'host': 'localhost', 'port': 9222}).on('connect', function(chrome) {
Chrome({'host': 'localhost', 'port': 9222}).on('connect', function (chrome) {
chrome.close();

@@ -39,0 +39,0 @@ done();

@@ -7,4 +7,4 @@ var Chrome = require('../');

it('should give the raw message', function (done) {
Chrome(function(chrome) {
chrome.once('event', function(message) {
Chrome(function (chrome) {
chrome.once('event', function (message) {
chrome.close();

@@ -19,15 +19,24 @@ assert(message.method);

});
describe('"Console.messagesCleared"', function () {
it('should give the payload ony', function (done) {
Chrome(function(chrome) {
chrome.once('Network.requestWillBeSent', function(message) {
chrome.close();
assert(!message.method);
done();
});
chrome.send('Network.enable');
chrome.send('Page.reload');
it('should give the payload only', function (done) {
Chrome(function (chrome) {
chrome.once('Network.requestWillBeSent', function (message) {
chrome.close();
assert(!message.method);
done();
});
chrome.send('Network.enable');
chrome.send('Page.reload');
});
});
it('should give the payload only (alternate syntax)', function (done) {
Chrome(function (chrome) {
chrome.Network.requestWillBeSent(function (message) {
chrome.close();
assert(!message.method);
done();
});
chrome.send('Network.enable');
chrome.send('Page.reload');
});
});
});

@@ -7,4 +7,4 @@ var Chrome = require('../');

it('should succeed', function (done) {
Chrome(function(chrome) {
chrome.once('Network.requestWillBeSent', function() {
Chrome(function (chrome) {
chrome.once('Network.requestWillBeSent', function () {
chrome.close();

@@ -20,3 +20,3 @@ done();

it('should succeed', function (done) {
Chrome(function(chrome) {
Chrome(function (chrome) {
chrome.send('Page.enable', function (error, response) {

@@ -32,3 +32,3 @@ chrome.close();

it('should succeed', function (done) {
Chrome(function(chrome) {
Chrome(function (chrome) {
chrome.send('Network.setCacheDisabled', {'cacheDisabled': true}, function (error, response) {

@@ -44,4 +44,4 @@ chrome.close();

it('should succeed', function (done) {
Chrome(function(chrome) {
chrome.once('Network.requestWillBeSent', function() {
Chrome(function (chrome) {
chrome.once('Network.requestWillBeSent', function () {
chrome.close();

@@ -57,3 +57,3 @@ done();

it('should succeed', function (done) {
Chrome(function(chrome) {
Chrome(function (chrome) {
chrome.Page.enable(function (error, response) {

@@ -69,3 +69,3 @@ chrome.close();

it('should succeed', function (done) {
Chrome(function(chrome) {
Chrome(function (chrome) {
chrome.Network.setCacheDisabled({'cacheDisabled': true}, function (error, response) {

@@ -72,0 +72,0 @@ chrome.close();

Sorry, the diff of this file is not supported yet

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