chrome-pool
Advanced tools
Comparing version 1.0.8 to 1.0.9
28
index.js
'use strict'; | ||
const net = require('net'); | ||
const Runner = require('chrome-runner'); | ||
const { launchWithHeadless, launchWithoutNoise } = require('chrome-runner'); | ||
const chrome = require('chrome-remote-interface'); | ||
@@ -9,18 +9,11 @@ const ProtocolDomains = require('chrome-remote-interface/lib/protocol.json').domains; | ||
* launch Chrome | ||
* @returns {Promise.<function>} chrome launcher | ||
*/ | ||
async function launchChrome(port) { | ||
const chromeFlags = [ | ||
'--disable-gpu', | ||
'--disable-extensions', | ||
'--disable-speech-api', | ||
]; | ||
if (!process.env.SHOW_CHROME) { | ||
chromeFlags.push('--headless') | ||
async function launchChrome() { | ||
let runner; | ||
if (process.env.SHOW_CHROME) { | ||
runner = await launchWithoutNoise(); | ||
} else { | ||
runner = await launchWithHeadless(); | ||
} | ||
const runner = new Runner({ | ||
port: port, | ||
chromeFlags, | ||
}); | ||
return await runner.launch(); | ||
return runner; | ||
} | ||
@@ -51,3 +44,2 @@ | ||
* maxTab: {number} max tab to render pages, default is no limit. | ||
* port: {number} chrome debug port, default is random a free port. | ||
* protocols: {array} require chrome devtool protocol to enable. | ||
@@ -58,5 +50,5 @@ * } | ||
static async new(options = {}) { | ||
let { maxTab = Infinity, port, protocols = [] } = options; | ||
let { maxTab = Infinity, protocols = [] } = options; | ||
const chromePoll = new ChromePool(); | ||
chromePoll.chromeRunner = await launchChrome(port); | ||
chromePoll.chromeRunner = await launchChrome(); | ||
chromePoll.port = chromePoll.chromeRunner.port;// chrome remote debug port | ||
@@ -63,0 +55,0 @@ chromePoll.protocols = protocols; |
{ | ||
"name": "chrome-pool", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "headless chrome tabs manage pool", | ||
@@ -26,3 +26,3 @@ "keywords": [ | ||
"chrome-remote-interface": "^0.23.2", | ||
"chrome-runner": "^1.0.4" | ||
"chrome-runner": "^1.1.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
@@ -14,3 +14,2 @@ [![Npm Package](https://img.shields.io/npm/v/chrome-pool.svg?style=flat-square)](https://www.npmjs.com/package/chrome-pool) | ||
2. start ChromePool: | ||
@@ -28,3 +27,2 @@ ```js | ||
- `maxTab`: {number} max tab to render pages, default is no limit. | ||
- `port`: {number} chrome debug port, default is random a free port. | ||
- `protocols`: {array} require chrome devtool protocol to be enable before use. e.g `['Network','Log']`. | ||
@@ -36,3 +34,2 @@ | ||
3. require a tab to use: | ||
@@ -49,3 +46,2 @@ ```js | ||
@@ -57,4 +53,3 @@ 4. use protocol to control tab: | ||
protocol detail use see [chrome-devtools-protocol doc](https://chromedevtools.github.io/devtools-protocol/). | ||
all protocol required be enable before use has been enable by chrome-pool. | ||
@@ -65,5 +60,4 @@ 5. after use a tab release it to pool: | ||
``` | ||
`release` will all resource used by this tab include removeAllListeners. | ||
`release` will all resource used by this tab include removeAllListeners, so you don't need to removeListener by yourself. | ||
see [test](./index.test.js) for more use case. | ||
@@ -74,9 +68,11 @@ 6. show chrome | ||
## Dependencies | ||
1. [Chrome 59+](https://www.google.com/chrome/browser/desktop/index.html) should install on you system | ||
2. Nodejs 7+ | ||
see [test](./index.test.js) for more use case. | ||
#### Notice [chrome 59+](https://www.google.com/chrome/browser/desktop/index.html) must install on you system | ||
## Friends | ||
- [chrome-render](https://github.com/gwuhaolin/chrome-render) general server render base on chrome. | ||
- [chrome-runner](https://github.com/gwuhaolin/chrome-runner) launch chrome by code. | ||
- [koa-chrome-render](https://github.com/gwuhaolin/koa-chrome-render) chrome-render middleware for koa | ||
- [koa-seo](https://github.com/gwuhaolin/koa-seo) koa SEO middleware |
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
13199
268
72
Updatedchrome-runner@^1.1.0