whatsapp-web.js icon indicating copy to clipboard operation
whatsapp-web.js copied to clipboard

Exception when client disconnects

Open TheMacros opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

If the client removes the connection from Linked devices (on the phone) I get this exception:

/var/www/wa/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230
                error: new Errors_js_1.ProtocolError(),
                       ^

ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed.
    at /var/www/wa/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230:24
    at new Promise (<anonymous>)
    at CDPSession.send (/var/www/wa/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226:16)
    at ExecutionContext._evaluateInternal (/var/www/wa/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
    at ExecutionContext.evaluateHandle (/var/www/wa/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:155:21)
    at WaitTask.rerun (/var/www/wa/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:551:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  originalMessage: ''
} 

Also, this exception appears in I'm trying to disconnect the client with Client.destroy() Just so you know, this exception appears from time to time.

Expected behavior

Disconnect without exception.

Steps to Reproduce the Bug or Issue

  1. Connect with your device
  2. Disconnect the device (with WhatsApp settings)

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

  • Ubuntu 18.04
  • iOS
  • whatsapp-web.js version 1.21.0
  • WhatsApp Web version 2.2326.10
  • Node.js version 16.13.1

Additional context

I'm using LocalAuth. Client created like this

waClient = new Client({
    puppeteer: {
        args: ['--no-sandbox'],
    },
    authStrategy: new LocalAuth({
        clientId: this.id
    })
});

TheMacros avatar Jun 23 '23 20:06 TheMacros

global.client.on('disconnected', (reason) => { // destroy session here // re init client });

// before any action : you must test if session existe

HajAbdel avatar Jun 24 '23 11:06 HajAbdel

I'm get same error this error it come when return loading screen or "whatsapp" word by Arabic language, I check on return it close and reruning and I change language of the Whatsapp to EN and get the last version update of whatsapp app

Alnuimi avatar Jun 24 '23 14:06 Alnuimi

global.client.on('disconnected', (reason) => { // destroy session here // re init client });

// before any action : you must test if session existe

I got

this.client.on('disconnected', () => {
    this.client.destroy();
});

but it doesn't work. I'm getting exception anyway. I'm not trying to do anything on a closed session. I got this exception immediately when click disconnect on my phone.

TheMacros avatar Jun 24 '23 15:06 TheMacros