pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.46k stars 3.68k forks source link

login disconnected after few minutes #1428

Closed MinosIE closed 11 months ago

MinosIE commented 2 years ago

Is there an existing issue for this?

Describe the bug

v1.16.6 after a few seconds of successful login, It is change state to OPENING and PAIRING then trigger disconnected with NAVIGATION. By analyzing the source code in Client.js , I found this:

// Disconnect when navigating away when in PAIRING state (detect logout)
  this.pupPage.on('framenavigated', async () => {
      const appState = await this.getState();
      if(!appState || appState === WAState.PAIRING) {
          this.emit(Events.DISCONNECTED, 'NAVIGATION');
          await this.destroy();
      }
  });

when I remove await this.destroy(); It works after disconnected, it trigger change state to CONNECTED


Expected behavior

login success

Steps to Reproduce the Bug or Issue

  1. login account
  2. scan QR code
  3. login success
  4. change state to OPENING
  5. change state to PAIRING
  6. disconnected with NAVIGATION

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Mac, Windows, Phone OS: Android whatsapp-web.js version:2.21.24.22 WhatsApp Web version: 2.2214.12 Node.js Version: v16.7.0

Additional context

No response

tofers commented 2 years ago

I agree, this piece of code was an erroneous revision. I wrote about this earlier.

Since PARING can hang all night and then, as the phone is online, it will connect.

MinosIE commented 2 years ago

@tofers I'm not sure if it will effect the normal logout

tofers commented 2 years ago

If the client has enabled sleep on the phone, then as a result this session will not connect and will fall out in auth_failure

voidpack commented 2 years ago

thx. also have this issue after some client got internet problem or disconnect for awhile then the client on chromium cannot reconnect until chromium get aw snap. using your trick delete await this.destroy(); working for me.

roigreenberg commented 2 years ago

@MinosIE I did this fix, in some cases, it indeed worked and after CONNECTED the bot continue to work properly, but in 1 bot, after CONNECTED it just stuck. Is there anything to do, except resetting the bot?

esteves67 commented 2 years ago

@MinosIE Thank you so much, removing the await this.destroy(); did the trick for me too, btw i was facing the problem with the non multi device, so the problem happens in both versions (multi & non multi).

jonylim commented 2 years ago

Hi, is this issue fixed in the latest release version 1.16.7?

PurpShell commented 1 year ago

I'll be rectifying this entire area soon.

alechkos commented 11 months ago

outdated