chrome-remote-interface
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -12,3 +12,3 @@ #!/usr/bin/env node | ||
.option('-p, --port <port>', 'Remote Debugging Protocol port') | ||
.option('-j, --protocol <file.json>', 'Remote Debugging Protocol description') | ||
.option('-j, --protocol <file.json>', 'Remote Debugging Protocol descriptor') | ||
.parse(process.argv); | ||
@@ -15,0 +15,0 @@ |
@@ -5,2 +5,3 @@ var defaults = require('./defaults.js'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
var WebSocket = require('ws'); | ||
@@ -33,20 +34,44 @@ | ||
options = options || {}; | ||
// TODO: this is not currently implemented in chrome but it is likely that | ||
// this feature will be added soon; the path is just a guess, if not present | ||
// Chrome will reply with a 404 | ||
options.path = '/json/protocol'; | ||
devToolsInterface(options, function (error, status, data) { | ||
var protocol; | ||
var fromChrome; | ||
try { | ||
if (error || status != 200) { | ||
protocol = require('./protocol.json'); | ||
fromChrome = false; | ||
} else { | ||
protocol = JSON.parse(data); | ||
fromChrome = true; | ||
} | ||
callback(null, fromChrome, protocol); | ||
} catch (err) { | ||
callback(err); | ||
var fallbackProtocol = require('./protocol.json'); | ||
// attempt to fetch the protocol directly from the Chromium repository | ||
// according to the current version; fallback to the hardcoded version | ||
// | ||
// Thanks to Paul Irish. | ||
// (see https://github.com/cyrus-and/chrome-remote-interface/issues/10#issuecomment-146032907) | ||
Chrome.Version(options, function (err, info) { | ||
if (err) { | ||
callback(null, false, fallbackProtocol); | ||
} else { | ||
var version = info['WebKit-Version']; | ||
var match = version.match(/\s\(@(\b[0-9a-f]{5,40}\b)/); | ||
var hash = match[1]; | ||
var fromChromiumDotOrg = (hash <= 202666); | ||
var template = (fromChromiumDotOrg ? | ||
'https://src.chromium.org/blink/trunk/Source/devtools/protocol.json?p=%s': | ||
'https://chromium.googlesource.com/chromium/src/+/%s/third_party/WebKit/Source/devtools/protocol.json?format=TEXT'); | ||
var url = util.format(template, hash); | ||
var request = https.get(url, function (response) { | ||
var data = ''; | ||
response.on('data', function (chunk) { | ||
data += chunk; | ||
}); | ||
response.on('end', function () { | ||
if (response.statusCode === 200) { | ||
try { | ||
// the file is served base64 encoded from googlesource.com | ||
if (!fromChromiumDotOrg) { | ||
data = new Buffer(data, 'base64').toString(); | ||
} | ||
callback(null, true, JSON.parse(data)); | ||
} catch (err) { | ||
callback(null, false, fallbackProtocol); | ||
} | ||
} else { | ||
callback(null, false, fallbackProtocol); | ||
} | ||
}); | ||
}); | ||
request.on('error', function (err) { | ||
callback(null, false, fallbackProtocol); | ||
}); | ||
} | ||
@@ -258,3 +283,3 @@ }); | ||
var continueConnection = function () { | ||
// build the API from the protocol description | ||
// build the API from the protocol descriptor | ||
addCommandShorthands.call(self); | ||
@@ -283,4 +308,6 @@ Chrome.List(options, function (err, tabs) { | ||
}; | ||
// try fetching the protocol from Chrome unless not specified | ||
if (typeof self.protocol === 'undefined') { | ||
// fetch the protocol | ||
if (self.protocol === null) { | ||
// try fetching the protocol from Chrome falling back to the hardcoded | ||
// version otherwise | ||
Chrome.Protocol(options, function (err, fromChrome, protocol) { | ||
@@ -295,2 +322,6 @@ if (err) { | ||
} else { | ||
// use the one provided falling back to the hardcoded version otherwise | ||
if (typeof self.protocol === 'undefined') { | ||
self.protocol = require('./protocol.json'); | ||
} | ||
continueConnection(); | ||
@@ -297,0 +328,0 @@ } |
{ | ||
"name": "chrome-remote-interface", | ||
"author": "Andrea Cardaci <cyrus.and@gmail.com>", | ||
"license": "MIT", | ||
"contributors": [ | ||
@@ -11,3 +12,3 @@ "Andrey Sidorov <sidoares@yandex.ru>", | ||
"homepage": "https://github.com/cyrus-and/chrome-remote-interface", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"repository": { | ||
@@ -21,3 +22,3 @@ "type": "git", | ||
"dependencies": { | ||
"ws": "0.4.x", | ||
"ws": "0.x.x", | ||
"commander": "2.1.x" | ||
@@ -24,0 +25,0 @@ }, |
@@ -101,10 +101,15 @@ chrome-remote-interface | ||
([`protocol.json`][local-json]) directly from the instrumented Chrome instance | ||
(see [#10][issue]); that file is fetched from time to time from the | ||
[Blink repo][remote-json] and pushed to this repository. To use some of the | ||
bleeding edge features that still does not appear in the provided | ||
[`protocol.json`][local-json], there are basically two options: | ||
(see [#10][issue]); rather, that file can be fetched from the proper [source | ||
repository][remote-json] at every connection. By default, the [hardcoded local | ||
version][local-json] is used. | ||
To override the above behavior there are basically three options: | ||
1. update the local copy with `make update-protocol`; | ||
2. use the *raw* version of the [commands](#chromesendmethod-params-callback) | ||
2. pass a custom protocol descriptor (use `null` to fetch it from the remote | ||
repository) upon | ||
[connection](https://github.com/cyrus-and/chrome-remote-interface#moduleoptions-callback); | ||
3. use the *raw* version of the [commands](#chromesendmethod-params-callback) | ||
and [events](#event-method) interface. | ||
@@ -128,5 +133,7 @@ | ||
currently active tab (`function (tabs) { return 0; }`). | ||
- `protocol`: [Remote Debugging Protocol][rdb] descriptor. Defaults to the | ||
protocol fetched directly from Chrome, if available, otherwise falls back to | ||
an hardcoded version. | ||
- `protocol`: [Remote Debugging Protocol][rdb] descriptor object. Passing `null` | ||
causes the proper protocol descriptor to be fetched from the remote Chrome | ||
repository according to the version exposed by the instrumented Chrome | ||
instance, falling back to the default if that is not possible. Defaults to the | ||
[hardcoded local version][local-json]. | ||
@@ -161,4 +168,5 @@ `callback` is a listener automatically added to the `connect` event of the | ||
Fetch the [Remote Debugging Protocol][rdb] descriptor from the remote Chrome | ||
instance, or fall back to the local hardcoded version if not available. | ||
Fetch the [Remote Debugging Protocol][rdb] descriptor from the Chrome repository | ||
according to the version of the remote Chrome instance, or fall back to the | ||
local hardcoded version if not available. | ||
@@ -175,3 +183,3 @@ `options` is an object with the following optional properties: | ||
- `fromChrome`: a boolean indicating whether the protocol has been fetched from | ||
Chrome or not; | ||
the Chrome repository or not; | ||
- `protocol`: the [Remote Debugging Protocol][rdb] descriptor. | ||
@@ -464,5 +472,7 @@ | ||
- [Chrome Debugger Protocol Viewer][rdb-viewer] | ||
- [Chrome Developer Tools: Remote Debugging Protocol v1.1][rdb] | ||
- [Showcase Chrome Debugging Protocol Clients][clients] | ||
[rdb-viewer]: http://chromedevtools.github.io/debugger-protocol-viewer/ | ||
[rdb]: https://developer.chrome.com/devtools/docs/protocol/1.1/index | ||
@@ -474,3 +484,3 @@ [clients-cri]: https://developer.chrome.com/devtools/docs/debugging-clients#chrome-remote-interface | ||
[local-json]: lib/protocol.json | ||
[remote-json]: https://src.chromium.org/blink/trunk/Source/devtools/protocol.json | ||
[remote-json]: https://chromium.googlesource.com/chromium/blink/+/master/Source/devtools/protocol.json | ||
[issue]: https://github.com/cyrus-and/chrome-remote-interface/issues/10 |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
350867
6023
481
2
+ Addedbindings@1.2.1(transitive)
+ Addedbufferutil@1.2.1(transitive)
+ Addednan@2.20.02.4.0(transitive)
+ Addedultron@1.0.2(transitive)
+ Addedutf-8-validate@1.2.2(transitive)
+ Addedws@0.8.1(transitive)
- Removednan@1.0.0(transitive)
- Removedtinycolor@0.0.1(transitive)
- Removedws@0.4.32(transitive)
Updatedws@0.x.x