chrome-remote-interface
Advanced tools
Comparing version 0.25.3 to 0.25.4
@@ -14,3 +14,3 @@ 'use strict'; | ||
class ProtocolError extends Error { | ||
constructor(response) { | ||
constructor(request, response) { | ||
let message = response.message; | ||
@@ -22,2 +22,3 @@ if (response.data) { | ||
// attach the original response as well | ||
this.request = request; | ||
this.response = response; | ||
@@ -91,5 +92,9 @@ } | ||
if (error) { | ||
const request = { | ||
'method': method, | ||
'params': params | ||
}; | ||
reject(error instanceof Error | ||
? error // low-level WebSocket error | ||
: new ProtocolError(response)); | ||
: new ProtocolError(request, response)); | ||
} else { | ||
@@ -96,0 +101,0 @@ fulfill(response); |
@@ -17,25 +17,10 @@ 'use strict'; | ||
} | ||
// try to fecth the browser version information and the protocol (remotely) | ||
module.exports.Version(options, function (err, info) { | ||
// try to fecth the protocol remotely | ||
options.path = '/json/protocol'; | ||
devToolsInterface(options, function (err, descriptor) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} else { | ||
callback(null, JSON.parse(descriptor)); | ||
} | ||
// fetch the reported browser info (Node.js returns an array) | ||
const browser = (info[0] || info).Browser; | ||
// use the proper protocol fetcher | ||
if (!browser.match(/^(Headless)?Chrome\//) && | ||
!browser.match(/^Microsoft Edge /) && | ||
!browser.match(/^node.js\//)) { | ||
callback(new Error('Unknown implementation')); | ||
return; | ||
} | ||
fetchFromHttpEndpoint(options, info, function (err, descriptor) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// use the remotely fetched descriptor | ||
callback(null, descriptor); | ||
}); | ||
}); | ||
@@ -136,13 +121,1 @@ }); | ||
} | ||
// callback(err, descriptor) | ||
function fetchFromHttpEndpoint(options, info, callback) { | ||
options.path = '/json/protocol'; | ||
devToolsInterface(options, function (err, descriptor) { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(null, JSON.parse(descriptor)); | ||
} | ||
}); | ||
} |
@@ -27,4 +27,9 @@ const EventEmitter = require('events'); | ||
send(data) { | ||
this._ws.send(data); | ||
send(data, callback) { | ||
try { | ||
this._ws.send(data); | ||
callback(); | ||
} catch (err) { | ||
callback(err); | ||
} | ||
} | ||
@@ -31,0 +36,0 @@ } |
@@ -12,3 +12,3 @@ { | ||
"homepage": "https://github.com/cyrus-and/chrome-remote-interface", | ||
"version": "0.25.3", | ||
"version": "0.25.4", | ||
"repository": { | ||
@@ -15,0 +15,0 @@ "type": "git", |
@@ -73,3 +73,3 @@ 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) | ||
[Google Chrome][1.1] | [tip-of-tree][1.2] | yes | yes | yes | yes | yes | yes | ||
[Microsoft Edge][2.1] | [*partial*][2.2] | yes | yes | no | no | no | yes | ||
[Opera][2.1] | [tip-of-tree][2.2] | yes | yes | yes | yes | yes | yes | ||
[Node.js][3.1] ([v6.3.0]+) | [node][3.2] | yes | no | no | no | no | yes | ||
@@ -81,4 +81,4 @@ [Safari (iOS)][4.1] | [*partial*][4.2] | no | yes | no | no | no | no | ||
[2.1]: #edge | ||
[2.2]: https://github.com/Microsoft/edge-diagnostics-adapter/wiki/Supported-features-and-API | ||
[2.1]: #opera | ||
[2.2]: https://chromedevtools.github.io/devtools-protocol/tot/ | ||
@@ -147,7 +147,7 @@ [3.1]: #nodejs | ||
### Edge | ||
### Opera | ||
Install and run the [Edge Diagnostics Adapter][edge-adapter]. | ||
Start Opera with the `--remote-debugging-port` option, for example: | ||
[edge-adapter]: https://github.com/Microsoft/edge-diagnostics-adapter | ||
opera --remote-debugging-port=9222 | ||
@@ -753,5 +753,6 @@ ### Node.js | ||
When `callback` is omitted a `Promise` object is returned instead, with the | ||
fulfilled/rejected states implemented according to the `error` parameter. | ||
In case of low-level WebSocket errors, the `error` parameter contains the | ||
fulfilled/rejected states implemented according to the `error` parameter. The | ||
`Error` object returned contains two additional parameters: `request` and | ||
`response` which contain the raw massages, useful for debugging purposes. In | ||
case of low-level WebSocket errors, the `error` parameter contains the | ||
originating `Error` object and no `response` is returned. | ||
@@ -758,0 +759,0 @@ |
Sorry, the diff of this file is too big to display
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
896
1048813
15527