Skip to content

Commit

Permalink
app: support remote puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Oct 7, 2018
1 parent 18e1d75 commit e7da789
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ module.exports = {
name: process.env.HTTP_BASIC_AUTH_NAME || 'usernam3',
pass: process.env.HTTP_BASIC_AUTH_PASS || 'passw0rd',
},
puppeteerWSEndpoint: process.env.PUPPETEER_WS_ENDPOINT || null,
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"pidusage": "^2.0.17",
"plist": "^3.0.1",
"puppeteer": "^1.8.0",
"puppeteer-core": "^1.9.0",
"raven": "^2.6.4",
"readall": "1.1.0",
"redis": "2.8.0",
Expand Down
13 changes: 11 additions & 2 deletions utils/puppeteer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const puppeteer = require('puppeteer');
const logger = require('./logger');
const config = require('../config');

Expand All @@ -10,7 +9,17 @@ const options = {
};

module.exports = (async () => {
const browser = await puppeteer.launch(options);
let browser;
if (config.puppeteerWSEndpoint) {
const puppeteer = require('puppeteer-core');
browser = await puppeteer.connect({
browserWSEndpoint: config.puppeteerWSEndpoint,
});
} else {
const puppeteer = require('puppeteer');
browser = await puppeteer.launch(options);
}

logger.info('Puppeteer launched.');

return async () => {
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6154,6 +6154,19 @@ punycode@^1.2.4, punycode@^1.4.1:
version "1.4.1"
resolved "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"

puppeteer-core@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/puppeteer-core/-/puppeteer-core-1.9.0.tgz#3859a4ebfc4b8a965bfdd4cc6c4ee93087142024"
dependencies:
debug "^3.1.0"
extract-zip "^1.6.6"
https-proxy-agent "^2.2.1"
mime "^2.0.3"
progress "^2.0.0"
proxy-from-env "^1.0.0"
rimraf "^2.6.1"
ws "^5.1.1"

puppeteer@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.8.0.tgz#9e8bbd2f5448cc19cac220efc0512837104877ad"
Expand Down

0 comments on commit e7da789

Please sign in to comment.