Skip to content

Commit

Permalink
feat: Added more log for WhatsApp page loading
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Oct 20, 2022
1 parent 5b04994 commit 62c9bf1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/api/layers/host.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
15 changes: 13 additions & 2 deletions src/controllers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 62c9bf1

Please sign in to comment.