From 2343e1a39059dced4a13dc6b41fc4055ac55ddcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Souza?= Date: Tue, 6 Oct 2020 09:36:14 -0300 Subject: [PATCH] feat: new option to connect browserWSEndpoint --- README.md | 1 + src/config/create-config.ts | 2 ++ src/controllers/browser.ts | 36 +++++++++++++++++++++--------------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 40428acdd..9f48f119e 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ venom useChrome: true, // If false will use Chromium instance debug: false, // Opens a debug session logQR: true, // Logs QR automatically in terminal + browserWS: '', // If u want to use browserWSEndpoint browserArgs: [''], // Parameters to be added into the chrome browser instance disableSpins: true, // Will disable Spinnies animation, useful for containers (docker) for a better log disableWelcome: true, // Will disable the welcoming message which appears in the beginning diff --git a/src/config/create-config.ts b/src/config/create-config.ts index af4165bac..7b7afdfaf 100644 --- a/src/config/create-config.ts +++ b/src/config/create-config.ts @@ -61,6 +61,7 @@ export interface CreateConfig { devtools?: boolean; useChrome?: boolean; debug?: boolean; + browserWS?: string; browserArgs?: string[]; logQR?: boolean; disableSpins?: boolean; @@ -77,6 +78,7 @@ export const defaultOptions: CreateConfig = { useChrome: true, debug: false, logQR: true, + browserWS: '', browserArgs: [''], disableSpins: false, disableWelcome: false, diff --git a/src/controllers/browser.ts b/src/controllers/browser.ts index ad9677fe5..533ee76ec 100644 --- a/src/controllers/browser.ts +++ b/src/controllers/browser.ts @@ -133,22 +133,28 @@ export async function initBrowser( // Use stealth plugin to avoid being detected as a bot puppeteer.use(StealthPlugin()); + puppeteer.defaultArgs({ + headless: options.headless, + devtools: options.devtools, + args: options.browserArgs + ? options.browserArgs + : [...puppeteerConfig.chromiumArgs], + ...extras, + }); + let browser = null; - await puppeteer - .launch({ - // headless: true, - headless: options.headless, - devtools: options.devtools, - //userDataDir: path.join(process.cwd(), session), - args: options.browserArgs - ? options.browserArgs - : [...puppeteerConfig.chromiumArgs], - ...extras, - }) - .then((e) => { - browser = e; - }) - .catch(() => {}); + if (options.browserWS && options.browserWS != '') { + browser = await puppeteer.connect({ + browserWSEndpoint: options.browserWS, + }); + } else { + await puppeteer + .launch() + .then((e) => { + browser = e; + }) + .catch(() => {}); + } return browser; }