Skip to content

Commit

Permalink
feat: new option to connect browserWSEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosouz4dev committed Oct 6, 2020
1 parent 599c562 commit 2343e1a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/config/create-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface CreateConfig {
devtools?: boolean;
useChrome?: boolean;
debug?: boolean;
browserWS?: string;
browserArgs?: string[];
logQR?: boolean;
disableSpins?: boolean;
Expand All @@ -77,6 +78,7 @@ export const defaultOptions: CreateConfig = {
useChrome: true,
debug: false,
logQR: true,
browserWS: '',
browserArgs: [''],
disableSpins: false,
disableWelcome: false,
Expand Down
36 changes: 21 additions & 15 deletions src/controllers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 2343e1a

Please sign in to comment.