chrome-remote-interface
Advanced tools
Comparing version 0.14.3 to 0.15.0
@@ -28,2 +28,3 @@ #!/usr/bin/env node | ||
function inspect(target, args, options) { | ||
options.remote = args.remote; | ||
// otherwise the active tab | ||
@@ -225,3 +226,4 @@ if (target) { | ||
.option('-w, --web-socket', 'interpret <target> as a WebSocket URL instead of a tab id') | ||
.option('-j, --protocol <file.json>', 'Remote Debugging Protocol descriptor') | ||
.option('-j, --protocol <file.json>', 'Remote Debugging Protocol descriptor (overrides `--remote`)') | ||
.option('-r, --remote', 'Attempt to fetch the protocol descriptor remotely') | ||
.action(function (target, args) { | ||
@@ -228,0 +230,0 @@ action = inspect.bind(null, target, args); |
@@ -9,31 +9,41 @@ const http = require('http'); | ||
module.exports.Protocol = promisesWrapper(function (options, callback) { | ||
const localProtocol = require('./protocol.json'); | ||
const protocol = {'remote': false, 'descriptor': localProtocol}; | ||
// if the local protocol is explicitly requested | ||
// if the local protocol is requested | ||
if (!options.remote) { | ||
callback(null, protocol); | ||
const localDescriptor = require('./protocol.json'); | ||
callback(null, { | ||
'remote': false, | ||
'descriptor': localDescriptor | ||
}); | ||
return; | ||
} | ||
// try to fecth the browser version informaion | ||
// try to fecth the browser version information and the protocol (remotely) | ||
module.exports.Version(options, function (err, info) { | ||
if (err) { | ||
callback(null, protocol); | ||
callback(err); | ||
return; | ||
} | ||
// fetch the reported browser info (Node.js returns an array) | ||
const browser = (info[0] || info).Browser; | ||
// use the proper protocol fetcher | ||
var fetcher; | ||
if (info.Browser.match(/^Chrome\//)) { | ||
fetcher = fetchFromChrome; | ||
} else if (info.Browser.match(/^Microsoft Edge /)) { | ||
fetcher = fetchFromEdge; | ||
if (browser.match(/^Chrome\//)) { | ||
fetcher = fetchFromChromeRepo; | ||
} else if (browser.match(/^Microsoft Edge /)) { | ||
fetcher = fetchFromHttpEndpoint; | ||
} else if (browser.match(/^node.js\//)) { | ||
fetcher = fetchFromHttpEndpoint; | ||
} else { | ||
callback(null, protocol); | ||
callback(new Error('Unknown implementation')); | ||
return; | ||
} | ||
fetcher(options, info, function (descriptor) { | ||
if (descriptor) { | ||
protocol.remote = true; | ||
protocol.descriptor = descriptor; | ||
fetcher(options, info, function (err, descriptor) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
callback(null, protocol); | ||
// use the remotely fetched descriptor | ||
callback(null, { | ||
'remote': true, | ||
'descriptor': descriptor | ||
}); | ||
}); | ||
@@ -155,6 +165,6 @@ }); | ||
// callback(protocol) | ||
// callback(err, descriptor) | ||
// XXX this function needs a proper refactor but the inconsistency of the | ||
// fetching process makes it useless for now | ||
function fetchFromChrome(options, info, callback) { | ||
function fetchFromChromeRepo(options, info, callback) { | ||
function explodeVersion(v) { | ||
@@ -193,3 +203,3 @@ return v.split('.').map(function (x) { | ||
fetchObject(https, url, function (err, data) { | ||
var descriptor; // undefined == fallback | ||
var descriptor; | ||
if (!err) { | ||
@@ -203,3 +213,3 @@ try { | ||
} catch (_) { | ||
// fall back | ||
// abort later | ||
} | ||
@@ -211,3 +221,3 @@ } | ||
if (descriptors.indexOf(undefined) !== -1) { | ||
callback(); | ||
callback(new Error('Cannot fetch from Chromium repo')); | ||
return; | ||
@@ -222,3 +232,3 @@ } | ||
}); | ||
callback(descriptors[0]); | ||
callback(null, descriptors[0]); | ||
} | ||
@@ -229,11 +239,12 @@ }); | ||
function fetchFromEdge(options, info, callback) { | ||
// callback(err, descriptor) | ||
function fetchFromHttpEndpoint(options, info, callback) { | ||
options.path = '/json/protocol'; | ||
devToolsInterface(options, function (err, descriptor) { | ||
if (err) { | ||
callback(); | ||
callback(err); | ||
} else { | ||
callback(JSON.parse(descriptor)); | ||
callback(null, JSON.parse(descriptor)); | ||
} | ||
}); | ||
} |
@@ -12,3 +12,3 @@ { | ||
"homepage": "https://github.com/cyrus-and/chrome-remote-interface", | ||
"version": "0.14.3", | ||
"version": "0.15.0", | ||
"repository": { | ||
@@ -15,0 +15,0 @@ "type": "git", |
@@ -289,5 +289,5 @@ chrome-remote-interface | ||
use the protocol chosen according to the `remote` option; | ||
- `remote`: a boolean indicating whether the protocol must be fetched | ||
*remotely* or if the local version must be used. It has not effect if the | ||
`protocol` option is set. Defaults to `false`. | ||
- `remote`: a boolean indicating whether the protocol must be fetched *remotely* | ||
or if the local version must be used. It has no effect if the `protocol` | ||
option is set. Defaults to `false`. | ||
@@ -294,0 +294,0 @@ `callback` is a listener automatically added to the `connect` event of the |
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
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
582495
13212