chrome-remote-interface
Advanced tools
Comparing version 0.16.2 to 0.17.0
@@ -7,2 +7,3 @@ 'use strict'; | ||
const defaults = require('./defaults.js'); | ||
const externalRequest = require('./external-request.js'); | ||
@@ -116,3 +117,3 @@ // callback(err, protocol) | ||
options.port = options.port || defaults.PORT; | ||
fetchObject(http, options, callback); | ||
externalRequest(http, options, callback); | ||
} | ||
@@ -147,22 +148,2 @@ | ||
// callback(err, data) | ||
function fetchObject(transport, options, callback) { | ||
const request = transport.get(options, function (response) { | ||
let data = ''; | ||
response.on('data', function (chunk) { | ||
data += chunk; | ||
}); | ||
response.on('end', function () { | ||
if (response.statusCode === 200) { | ||
callback(null, data); | ||
} else { | ||
callback(new Error(data)); | ||
} | ||
}); | ||
}); | ||
request.on('error', function (err) { | ||
callback(err); | ||
}); | ||
} | ||
// callback(err, descriptor) | ||
@@ -214,3 +195,3 @@ // XXX this function needs a proper refactor but the inconsistency of the | ||
urls.forEach(function (url) { | ||
fetchObject(https, url, function (err, data) { | ||
externalRequest(https, url, function (err, data) { | ||
let descriptor; | ||
@@ -217,0 +198,0 @@ if (!err) { |
@@ -12,3 +12,3 @@ { | ||
"homepage": "https://github.com/cyrus-and/chrome-remote-interface", | ||
"version": "0.16.2", | ||
"version": "0.17.0", | ||
"repository": { | ||
@@ -18,4 +18,4 @@ "type": "git", | ||
}, | ||
"bugs" : { | ||
"url" : "http://github.com/cyrus-and/chrome-remote-interface/issues" | ||
"bugs": { | ||
"url": "http://github.com/cyrus-and/chrome-remote-interface/issues" | ||
}, | ||
@@ -32,3 +32,5 @@ "engines": { | ||
"bin", | ||
"index.js" | ||
"index.js", | ||
"chrome-remote-interface.js", | ||
"webpack.config.js" | ||
], | ||
@@ -38,9 +40,17 @@ "bin": { | ||
}, | ||
"browser": "chrome-remote-interface.js", | ||
"devDependencies": { | ||
"mocha": "3.1.x", | ||
"eslint": "3.9.x" | ||
"eslint": "3.9.x", | ||
"babel-core": "^6.18.2", | ||
"babel-loader": "^6.2.8", | ||
"babel-preset-es2015": "^6.18.0", | ||
"json-loader": "^0.5.4", | ||
"webpack": "^1.13.3" | ||
}, | ||
"scripts": { | ||
"test": "./scripts/run-tests.sh" | ||
"test": "./scripts/run-tests.sh", | ||
"webpack": "webpack", | ||
"prepublish": "webpack" | ||
} | ||
} |
@@ -339,2 +339,51 @@ 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) | ||
Browser usage | ||
------------- | ||
This module is able to run within a web context, with obvious limitations | ||
though, namely external HTTP requests | ||
([List](#cdplistoptions-callback), [New](#cdpnewoptions-callback), etc.) cannot | ||
be performed directly, for this reason the user must provide a global | ||
`criRequest` in order to use them: | ||
```js | ||
function criRequest(options, callback) {} | ||
``` | ||
`options` is the same object used by the Node.js `http` module and `callback` is | ||
a function taking two arguments: `err` (JavaScript `Error` object or `null`) and | ||
`data` (string result). | ||
### Using [webpack](https://webpack.github.io/) | ||
It just works, simply require this module: | ||
```js | ||
const CDP = require('chrome-remote-interface'); | ||
``` | ||
To use a non-minified version manually run webpack with: | ||
DEBUG=true npm run webpack | ||
### Using *vanilla* JavaScript | ||
To generate a JavaScript file that can be used with a `<script>` element: | ||
1. run `npm install` from the root directory; | ||
2. manually run webpack with: | ||
TARGET=var npm run webpack | ||
TARGET=var DEBUG=true npm run webpack | ||
3. use as: | ||
```html | ||
<script> | ||
function criRequest(options, callback) { /*...*/ } | ||
</script> | ||
<script src="chrome-remote-interface.js"></script> | ||
``` | ||
API | ||
@@ -341,0 +390,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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
892314
14
14431
801
7
6