Skip to content

Commit 98dc09e

Browse files
committed
allow option to create browser using websocket endpoint
1 parent 098dff8 commit 98dc09e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const config = {
88
ALLOW_HTTP: process.env.ALLOW_HTTP === 'true',
99
DEBUG_MODE: process.env.DEBUG_MODE === 'true',
1010
CORS_ORIGIN: process.env.CORS_ORIGIN || '*',
11+
BROWSER_WS_ENDPOINT: process.env.BROWSER_WS_ENDPOINT,
1112
API_TOKENS: [],
1213
};
1314

src/core/render-core.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ const _ = require('lodash');
33
const config = require('../config');
44
const logger = require('../util/logger')(__filename);
55

6+
7+
async function createBrowser(opts) {
8+
const browserOpts = {
9+
ignoreHTTPSErrors: opts.ignoreHttpsErrors,
10+
sloMo: config.DEBUG_MODE ? 250 : undefined,
11+
};
12+
if (config.BROWSER_WS_ENDPOINT) {
13+
browserOpts.browserWSEndpoint = config.BROWSER_WS_ENDPOINT;
14+
return puppeteer.connect(browserOpts);
15+
}
16+
browserOpts.headless = !config.DEBUG_MODE;
17+
browserOpts.args = ['--disable-gpu', '--no-sandbox', '--disable-setuid-sandbox'];
18+
return puppeteer.launch(browserOpts);
19+
}
20+
621
async function render(_opts = {}) {
722
const opts = _.merge({
823
cookies: [],
@@ -37,12 +52,7 @@ async function render(_opts = {}) {
3752

3853
logOpts(opts);
3954

40-
const browser = await puppeteer.launch({
41-
headless: !config.DEBUG_MODE,
42-
ignoreHTTPSErrors: opts.ignoreHttpsErrors,
43-
args: ['--disable-gpu', '--no-sandbox', '--disable-setuid-sandbox'],
44-
sloMo: config.DEBUG_MODE ? 250 : undefined,
45-
});
55+
const browser = await createBrowser(opts);
4656
const page = await browser.newPage();
4757

4858
page.on('console', (...args) => logger.info('PAGE LOG:', ...args));

0 commit comments

Comments
 (0)