From 32e47d818a8846389181c41996456e7e80f83965 Mon Sep 17 00:00:00 2001 From: "Pedro S. Lopez" Date: Sat, 5 Feb 2022 18:19:02 -0400 Subject: [PATCH] fix: only emit `disconnected` event on navigation when state is `PAIRING` (#1169) --- src/Client.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Client.js b/src/Client.js index 643844a..dd9b819 100644 --- a/src/Client.js +++ b/src/Client.js @@ -430,11 +430,13 @@ class Client extends EventEmitter { */ this.emit(Events.READY); - // Disconnect when navigating away - // Because WhatsApp Web now reloads when logging out from the device, this also covers that case + // Disconnect when navigating away when in PAIRING state (detect logout) this.pupPage.on('framenavigated', async () => { - this.emit(Events.DISCONNECTED, 'NAVIGATION'); - await this.destroy(); + const appState = await this.getState(); + if(appState === WAState.PAIRING) { + this.emit(Events.DISCONNECTED, 'NAVIGATION'); + await this.destroy(); + } }); }