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

When i disconnect a client from the whatsapp app, puppeteer throws an error that damages any client i've created

Open luisdbarboza opened this issue 1 year ago • 16 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

Well, like the title says, if i unlink the whatsapp client using my phone's whatsapp app, the expected behaviour is for the client to emit the disconnected event, just 1 client, the one that got disconnected, but instead, what happens is that i get a log like this on my console: uncaughtException: Protocol error (Network.getResponseBody): Session closed. Most likely the page has been closed.

Now, this exception damages any other client i may have open...

Meaning, if i use the localAuth strategy, and use multiple clients in my app, if only 1 of let's say, 10 clients disconnects from their phone, 10 clients are affected, because of the puppeteer exception that gets thrown.

I'm using manjaro os for testing, an arch linux distro btw.

Expected behavior

I guess just 1 client should get disconnected and every other one should work normally.

Steps to Reproduce the Bug or Issue

Use the localAuth strategy, and connect multiple clients.

Connect a client scanning the qr code.

Disconnect the client from the whatsapp mobile app.

An error gets thrown.

Now my webserver throws 500 internal server error on any occasion.

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

Manjaro os, an arch linux distro. Whatsapp web version https://github.com/Julzk/whatsapp-web.js/tarball/jkr_hotfix_7

nodejs version v18.18.0

Additional context

No response

luisdbarboza avatar Oct 13 '23 04:10 luisdbarboza

You can use the following code in your entry file, which will catch exceptions and will not cause your application to crash. `process.on('uncaughtException', (err) => {

})`

a20000110 avatar Oct 13 '23 07:10 a20000110

@a20000110 do you mean attaching an event handler to the Client object?

luisdbarboza avatar Oct 14 '23 02:10 luisdbarboza

For additional info, i created a client with the localAuth strategy, i sent a message with the client, and after i closed the session from the whatsapp app, the library throws this error:

uncaughtException: Protocol error (Networ.getResponseBody): Session closed. Most likely the page has been closed at CDPSession.send (...restOfThePath/node_modules/puppeteer/lib/cjs/puppeteer/common/HTTPResponse.js:128:57

luisdbarboza avatar Oct 14 '23 03:10 luisdbarboza

How are you closing the app? You need to call client.destroy()

luiscuriel avatar Oct 14 '23 07:10 luiscuriel

Hmm, yes, i'm destroying the client every time, but you see, even if i delete the .wwebjs_auth, or even if i don't do anything in the client.on('disconnected'. (callback)) event handler, it stills throws the error i described above

luisdbarboza avatar Oct 14 '23 11:10 luisdbarboza

Same issue here. I tried to add a try catch in the entire Cliente intializing function but puppeteer error is still crashing the server. @a20000110 solution is a workaround for ANY not handled exception so be careful using it. The best solution is to handle the exception directly.

sgbtz avatar Oct 14 '23 11:10 sgbtz

@a20000110 solution isn't working for me, because well, the app itself is not crashing completely, if i put an event handler for the uncaughtException i can log the error in the console, the process doesn't stop, but, i get the uncaughtException error logged in the console, and also my endpoints start sending responses with status 500 internal sever error

luisdbarboza avatar Oct 14 '23 13:10 luisdbarboza

Same issue here.

aldhinya avatar Oct 18 '23 06:10 aldhinya

any updates?

venturion avatar Nov 19 '23 16:11 venturion

Same issue here: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.

jpdev01 avatar Jan 02 '24 17:01 jpdev01

same here, I am facing the same issue

ekapasha17 avatar Jan 19 '24 02:01 ekapasha17

@ekapasha17

same here, I am facing the same issue

Check #2661

alechkos avatar Jan 19 '24 02:01 alechkos

@ekapasha17

same here, I am facing the same issue

Check #2661

not solving the problem yet

ekapasha17 avatar Jan 22 '24 04:01 ekapasha17

I've noticed that when Chromium is closed (can test in task manager), the event client.on('disconected'... is not fired And when try to send any message the error occurs: Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.

Anyone facing this issue?

AndisKush avatar Jan 24 '24 21:01 AndisKush

Work for me install independent "puppeteer": "^22.6.4". Try it.

DukazzCruz avatar Apr 12 '24 20:04 DukazzCruz