From f5081802eafd2a015c0596bae7654fa8b22b1082 Mon Sep 17 00:00:00 2001 From: Cap <48036034+CapOliveiraBr@users.noreply.github.com> Date: Tue, 7 Apr 2020 04:00:49 -0300 Subject: [PATCH 1/4] Debug URL in initializer --- src/controllers/initializer.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controllers/initializer.ts b/src/controllers/initializer.ts index ff168179..5d94d627 100644 --- a/src/controllers/initializer.ts +++ b/src/controllers/initializer.ts @@ -1,4 +1,5 @@ import * as ora from 'ora'; +import { readFileSync } from 'fs'; import { Whatsapp } from '../api/whatsapp'; import { CreateConfig } from '../config/create-config'; import { isAuthenticated, isInsideChat, retrieveQR } from './auth'; @@ -38,6 +39,9 @@ export async function create( spinner.start('Injecting api'); waPage = await injectApi(waPage); spinner.succeed('Whatsapp is ready'); + + const debugURL = `http://localhost:${readFileSync('./session/DevToolsActivePort').slice(0, -54)}`; + console.log(`\nDebug ➜ \x1b[34m${debugURL}\x1b[0m`); return new Whatsapp(waPage); } From e255f3af596091209cf29134afe56dceb8d53dd9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Apr 2020 07:12:41 +0000 Subject: [PATCH 2/4] Restyled by whitespace --- src/controllers/initializer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/initializer.ts b/src/controllers/initializer.ts index 5d94d627..58083abb 100644 --- a/src/controllers/initializer.ts +++ b/src/controllers/initializer.ts @@ -39,7 +39,7 @@ export async function create( spinner.start('Injecting api'); waPage = await injectApi(waPage); spinner.succeed('Whatsapp is ready'); - + const debugURL = `http://localhost:${readFileSync('./session/DevToolsActivePort').slice(0, -54)}`; console.log(`\nDebug ➜ \x1b[34m${debugURL}\x1b[0m`); From 530391484d4284a33c230c37fa6d93ea23b6fd10 Mon Sep 17 00:00:00 2001 From: "danielcardeenas@gmail.com" Date: Tue, 7 Apr 2020 10:06:36 -0500 Subject: [PATCH 3/4] Exclude test file from dist --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index f22deea4..15922e4e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -57,5 +57,5 @@ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ }, "include": ["src/**/*"], - "exclude": ["src/middleware/middleware.ts"] + "exclude": ["src/middleware/middleware.ts", "src/api/app.ts"] } From c3883e27b4200674674f2d52b7d9ba91ede3f69e Mon Sep 17 00:00:00 2001 From: "danielcardeenas@gmail.com" Date: Tue, 7 Apr 2020 10:55:22 -0500 Subject: [PATCH 4/4] Change UA, add useChrome option, add debug option --- package.json | 4 ++-- src/config/create-config.ts | 2 ++ src/controllers/browser.ts | 18 ++++++++++-------- src/controllers/initializer.ts | 15 ++++++++++++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 1f72efbf..25bb53a2 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "sulla", - "version": "2.3.2", + "version": "2.3.3", "description": "Javascript whatsapp framework", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { - "start": "tsc && node dist/index.js", + "start": "tsc && node dist/app.js", "build": "npm run build:wapi && npm run build:middleware && npm run build:jsQR && tsc", "build:sulla": "tsc", "build:wapi": "cd src/lib/wapi/ && webpack", diff --git a/src/config/create-config.ts b/src/config/create-config.ts index 1cfbda83..8b96e6e9 100644 --- a/src/config/create-config.ts +++ b/src/config/create-config.ts @@ -1,4 +1,6 @@ export interface CreateConfig { headless?: boolean; devtools?: boolean; + useChrome?: boolean; + debug?: boolean; } diff --git a/src/controllers/browser.ts b/src/controllers/browser.ts index b9361174..6ea8f4f1 100644 --- a/src/controllers/browser.ts +++ b/src/controllers/browser.ts @@ -10,7 +10,7 @@ export async function initWhatsapp(session: string, options: CreateConfig) { const browser = await initBrowser(session, options); const waPage = await getWhatsappPage(browser); await waPage.setUserAgent( - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36' + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36' ); await waPage.goto(puppeteerConfig.whatsappUrl); @@ -44,14 +44,16 @@ async function initBrowser( options: CreateConfig, extras = {} ) { - try { - const chromeInstalations = ChromeLauncher.Launcher.getInstallations(); - if (chromeInstalations.length) { - extras = { ...extras, executablePath: chromeInstalations[0] }; + if (options.useChrome) { + try { + const chromeInstalations = ChromeLauncher.Launcher.getInstallations(); + if (chromeInstalations.length) { + extras = { ...extras, executablePath: chromeInstalations[0] }; + } + } catch (error) { + console.log('Chrome not found, using chromium'); + extras = {}; } - } catch (error) { - console.log('Chrome not found, using chromium'); - extras = {}; } // Use stealth plugin to avoid being detected as a bot diff --git a/src/controllers/initializer.ts b/src/controllers/initializer.ts index 58083abb..168074ff 100644 --- a/src/controllers/initializer.ts +++ b/src/controllers/initializer.ts @@ -12,7 +12,12 @@ const spinner = ora(); export async function create( session = 'session', catchQR?: (qrCode: string) => void, - options: CreateConfig = { headless: true, devtools: false } + options: CreateConfig = { + headless: true, + devtools: false, + useChrome: true, + debug: false, + } ) { spinner.start('Initializing whatsapp'); let waPage = await initWhatsapp(session, options); @@ -40,8 +45,12 @@ export async function create( waPage = await injectApi(waPage); spinner.succeed('Whatsapp is ready'); - const debugURL = `http://localhost:${readFileSync('./session/DevToolsActivePort').slice(0, -54)}`; - console.log(`\nDebug ➜ \x1b[34m${debugURL}\x1b[0m`); + if (options.debug) { + const debugURL = `http://localhost:${readFileSync( + `./${session}/DevToolsActivePort` + ).slice(0, -54)}`; + console.log(`\nDebug: \x1b[34m${debugURL}\x1b[0m`); + } return new Whatsapp(waPage); }