diff --git a/src/api/layers/host.layer.ts b/src/api/layers/host.layer.ts index 0f42707f4..1de55ff4a 100644 --- a/src/api/layers/host.layer.ts +++ b/src/api/layers/host.layer.ts @@ -136,7 +136,8 @@ export class HostLayer { this.page, sessionToken, clear, - this.options.whatsappVersion + this.options.whatsappVersion, + this.log.bind(this) ); this.page.on('load', () => { diff --git a/src/controllers/browser.ts b/src/controllers/browser.ts index e4c15ce1f..1864d8157 100644 --- a/src/controllers/browser.ts +++ b/src/controllers/browser.ts @@ -32,6 +32,7 @@ import { WebSocketTransport } from './websocket'; import { Logger } from 'winston'; import { SessionToken } from '../token-store'; import { LoadingScreenCallback } from '../api/model'; +import { LogLevel } from '../utils/logger'; export async function unregisterServiceWorker(page: Page) { await page.evaluateOnNewDocument(() => { @@ -83,26 +84,36 @@ export async function initWhatsapp( page: Page, token?: SessionToken, clear = true, - version?: string + version?: string, + log?: (level: LogLevel, message: string, meta?: object) => any ) { await page.setUserAgent(useragentOverride); await unregisterServiceWorker(page); + + if (clear) { + log?.('verbose', 'Cleaning localStorage'); + } // Auth with token await injectSessionToken(page, token, clear); if (version) { + log?.('verbose', `Setting WhatsApp WEB version to ${version}`); await setWhatsappVersion(page, version); } + log?.('verbose', `Loading WhatsApp WEB`); + const timeout = 10 * 1000; - await page + page .goto(puppeteerConfig.whatsappUrl, { timeout, waitUntil: 'domcontentloaded', }) .catch(() => {}); + log?.('verbose', `WhatsApp WEB loaded`); + return page; }