Add option to use a remote chromium instance

main
DrosoCode 3 years ago
parent ac3973bf7c
commit c980a31f3c

@ -13,8 +13,12 @@ function next() {
return new Promise((resolve) => setImmediate(resolve)) return new Promise((resolve) => setImmediate(resolve))
} }
const { AWS_LAMBDA_FUNCTION_NAME, CHROMIUM_BIN, CHROMIUM_DATA_DIR } = const {
process.env AWS_LAMBDA_FUNCTION_NAME,
CHROMIUM_BIN,
CHROMIUM_DATA_DIR,
CHROMIUM_WEBSOCKET,
} = process.env
let puppeteer let puppeteer
let chromiumArgs = [ let chromiumArgs = [
@ -342,12 +346,20 @@ class Driver {
this.log('Launching browser...') this.log('Launching browser...')
try { try {
if (CHROMIUM_WEBSOCKET) {
this.browser = await puppeteer.connect({
ignoreHTTPSErrors: true,
acceptInsecureCerts: true,
browserWSEndpoint: CHROMIUM_WEBSOCKET,
})
} else {
this.browser = await puppeteer.launch({ this.browser = await puppeteer.launch({
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
acceptInsecureCerts: true, acceptInsecureCerts: true,
args: chromiumArgs, args: chromiumArgs,
executablePath: await chromiumBin, executablePath: await chromiumBin,
}) })
}
this.browser.on('disconnected', async () => { this.browser.on('disconnected', async () => {
this.log('Browser disconnected') this.log('Browser disconnected')