chrome-remote-interface
Advanced tools
Comparing version 0.26.1 to 0.27.0
@@ -285,3 +285,4 @@ #!/usr/bin/env node | ||
.option('-p, --port <port>', 'HTTP frontend port') | ||
.option('-s, --secure', 'HTTPS/WSS frontend'); | ||
.option('-s, --secure', 'HTTPS/WSS frontend') | ||
.option('-n, --use-host-name', 'Do not perform a DNS lookup of the host'); | ||
@@ -347,3 +348,4 @@ program | ||
port: program.port, | ||
secure: program.secure | ||
secure: program.secure, | ||
useHostName: program.useHostName | ||
}; | ||
@@ -350,0 +352,0 @@ |
@@ -43,3 +43,3 @@ 'use strict'; | ||
chrome.on(eventName, handler); | ||
return undefined; | ||
return () => chrome.removeListener(eventName, handler); | ||
} else { | ||
@@ -46,0 +46,0 @@ return new Promise((fulfill, reject) => { |
@@ -54,2 +54,3 @@ 'use strict'; | ||
this.secure = !!(options.secure); | ||
this.useHostName = !!(options.useHostName); | ||
this.protocol = options.protocol; | ||
@@ -101,9 +102,14 @@ this.local = !!(options.local); | ||
const closeWebSocket = (callback) => { | ||
// don't notify on user-initiated shutdown ('disconnect' event) | ||
this._ws.removeAllListeners('close'); | ||
this._ws.close(); | ||
this._ws.once('close', () => { | ||
this._ws.removeAllListeners(); | ||
// don't close if it's already closed | ||
if (this._ws.readyState === 3) { | ||
callback(); | ||
}); | ||
} else { | ||
// don't notify on user-initiated shutdown ('disconnect' event) | ||
this._ws.removeAllListeners('close'); | ||
this._ws.once('close', () => { | ||
this._ws.removeAllListeners(); | ||
callback(); | ||
}); | ||
this._ws.close(); | ||
} | ||
}; | ||
@@ -125,3 +131,4 @@ if (typeof callback === 'function') { | ||
port: this.port, | ||
secure: this.secure | ||
secure: this.secure, | ||
useHostName: this.useHostName | ||
}; | ||
@@ -128,0 +135,0 @@ try { |
@@ -14,2 +14,3 @@ 'use strict'; | ||
options.secure = !!(options.secure); | ||
options.useHostName = !!(options.useHostName); | ||
externalRequest(options.secure ? https : http, options, callback); | ||
@@ -16,0 +17,0 @@ } |
'use strict'; | ||
const dns = require('dns'); | ||
const util = require('util'); | ||
@@ -8,3 +9,3 @@ const REQUEST_TIMEOUT = 10000; | ||
// callback(err, data) | ||
function externalRequest(transport, options, callback) { | ||
async function externalRequest(transport, options, callback) { | ||
// perform the DNS lookup manually so that the HTTP host header generated by | ||
@@ -14,29 +15,32 @@ // http.get will contain the IP address, this is needed because since Chrome | ||
// (see https://github.com/cyrus-and/chrome-remote-interface/issues/340) | ||
dns.lookup(options.host, (err, address) => { | ||
if (err) { | ||
if (!options.useHostName) { | ||
try { | ||
const {address} = await util.promisify(dns.lookup)(options.host); | ||
options = Object.assign({}, options); | ||
options.host = address; | ||
} catch (err) { | ||
callback(err); | ||
return; | ||
} | ||
const resolved = Object.assign({}, options); | ||
resolved.host = address; | ||
const request = transport.get(resolved, (response) => { | ||
let data = ''; | ||
response.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
response.on('end', () => { | ||
if (response.statusCode === 200) { | ||
callback(null, data); | ||
} else { | ||
callback(new Error(data)); | ||
} | ||
}); | ||
} | ||
// perform the actual request | ||
const request = transport.get(options, (response) => { | ||
let data = ''; | ||
response.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
request.setTimeout(REQUEST_TIMEOUT, () => { | ||
request.abort(); | ||
response.on('end', () => { | ||
if (response.statusCode === 200) { | ||
callback(null, data); | ||
} else { | ||
callback(new Error(data)); | ||
} | ||
}); | ||
request.on('error', callback); | ||
}); | ||
request.setTimeout(REQUEST_TIMEOUT, () => { | ||
request.abort(); | ||
}); | ||
request.on('error', callback); | ||
} | ||
module.exports = externalRequest; |
@@ -18,3 +18,3 @@ { | ||
"homepage": "https://github.com/cyrus-and/chrome-remote-interface", | ||
"version": "0.26.1", | ||
"version": "0.27.0", | ||
"repository": { | ||
@@ -32,3 +32,3 @@ "type": "git", | ||
"commander": "2.11.x", | ||
"ws": "^3.3.3" | ||
"ws": "^6.1.0" | ||
}, | ||
@@ -45,8 +45,9 @@ "files": [ | ||
}, | ||
"main": "index.js", | ||
"browser": "chrome-remote-interface.js", | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-loader": "^6.2.8", | ||
"babel-plugin-transform-async-to-generator": "^6.24.1", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-loader": "6.x.x", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"eslint": "^3.19.0", | ||
@@ -53,0 +54,0 @@ "json-loader": "^0.5.4", |
@@ -22,5 +22,6 @@ 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) | ||
async function example() { | ||
let client; | ||
try { | ||
// connect to endpoint | ||
let client = await CDP(); | ||
client = await CDP(); | ||
// extract domains | ||
@@ -425,2 +426,3 @@ const {Network, Page} = client; | ||
- `secure`: HTTPS/WSS frontend. Defaults to `false`; | ||
- `useHostName`: do not perform a DNS lookup of the host. Defaults to `false`; | ||
- `target`: determines which target this client should attach to. The behavior | ||
@@ -487,2 +489,3 @@ changes according to the type: | ||
- `secure`: HTTPS/WSS frontend. Defaults to `false`; | ||
- `useHostName`: do not perform a DNS lookup of the host. Defaults to `false`; | ||
- `local`: a boolean indicating whether the protocol must be fetched *remotely* | ||
@@ -519,2 +522,3 @@ or if the local version must be returned. Defaults to `false`. | ||
- `secure`: HTTPS/WSS frontend. Defaults to `false`. | ||
- `useHostName`: do not perform a DNS lookup of the host. Defaults to `false`; | ||
@@ -550,2 +554,3 @@ `callback` is executed when the list is correctly received, it gets the | ||
- `secure`: HTTPS/WSS frontend. Defaults to `false`; | ||
- `useHostName`: do not perform a DNS lookup of the host. Defaults to `false`; | ||
- `url`: URL to load in the new target/tab. Defaults to `about:blank`. | ||
@@ -582,2 +587,3 @@ | ||
- `secure`: HTTPS/WSS frontend. Defaults to `false`; | ||
- `useHostName`: do not perform a DNS lookup of the host. Defaults to `false`; | ||
- `id`: Target id. Required, no default. | ||
@@ -612,2 +618,3 @@ | ||
- `secure`: HTTPS/WSS frontend. Defaults to `false`; | ||
- `useHostName`: do not perform a DNS lookup of the host. Defaults to `false`; | ||
- `id`: Target id. Required, no default. | ||
@@ -645,2 +652,3 @@ | ||
- `secure`: HTTPS/WSS frontend. Defaults to `false`. | ||
- `useHostName`: do not perform a DNS lookup of the host. Defaults to `false`; | ||
@@ -811,9 +819,16 @@ `callback` is executed when the version information is correctly received, it | ||
The only difference is that when `callback` is omitted the event is registered | ||
only once and a `Promise` object is returned. | ||
When `callback` is omitted the event is registered only once and a `Promise` | ||
object is returned. | ||
When `callback` is provided, it returns a function that can be used to | ||
unsubscribe `callback` from the event, it can be useful when anonymous functions | ||
are used as callbacks. | ||
For example: | ||
```javascript | ||
client.Network.requestWillBeSent(console.log); | ||
const unsubscribe = client.Network.requestWillBeSent((params) => { | ||
console.log(params.request.url); | ||
}); | ||
unsubscribe(); | ||
``` | ||
@@ -820,0 +835,0 @@ |
@@ -35,3 +35,3 @@ 'use strict'; | ||
], | ||
entry: './index.js', | ||
entry: ['babel-polyfill', './index.js'], | ||
output: { | ||
@@ -38,0 +38,0 @@ libraryTarget: process.env.TARGET || 'commonjs2', |
Sorry, the diff of this file is too big to display
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
1327085
20111
927
+ Addedws@6.2.3(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedultron@1.1.1(transitive)
- Removedws@3.3.3(transitive)
Updatedws@^6.1.0