From 9b66878fe728e36ee70d1b2e4e425c7e0ee54814 Mon Sep 17 00:00:00 2001 From: Edgard Date: Thu, 17 Nov 2022 22:12:55 -0300 Subject: [PATCH] fix: Fixed qrCode loading (fix #1422) --- src/controllers/browser.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controllers/browser.ts b/src/controllers/browser.ts index 03a8e0e76..07f594d87 100644 --- a/src/controllers/browser.ts +++ b/src/controllers/browser.ts @@ -33,6 +33,7 @@ import { Logger } from 'winston'; import { SessionToken } from '../token-store'; import { LoadingScreenCallback } from '../api/model'; import { LogLevel } from '../utils/logger'; +import { sleep } from '../utils/sleep'; export async function unregisterServiceWorker(page: Page) { await page.evaluateOnNewDocument(() => { @@ -49,6 +50,11 @@ export async function unregisterServiceWorker(page: Page) { // Disable service worker registration // @ts-ignore navigator.serviceWorker.register = new Promise(() => {}); + + setInterval(() => { + window.onerror = console.error; + window.onunhandledrejection = console.error; + }, 500); }); } @@ -196,6 +202,15 @@ export async function injectApi( return; } + // Wait for some loaded modules + await page + .waitForFunction( + () => ((window as any)?.webpackChunkwhatsapp_web_client?.length || 0) > 3 + ) + .catch(() => null); + + await sleep(100); + await page.addScriptTag({ path: require.resolve('@wppconnect/wa-js'), });