Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
luisdbarboza opened this issue Oct 13, 2023 · 15 comments · May be fixed by #2661
Open
1 task done
Labels
bug Something isn't working

Comments

@luisdbarboza
Copy link

luisdbarboza commented Oct 13, 2023

Is there an existing issue for this?

  • 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 luisdbarboza added the bug Something isn't working label Oct 13, 2023
@luisdbarboza luisdbarboza changed the title When i disconnect a client from the whatsapp app, puppeteers throws an error that damages any client i've created When i disconnect a client from the whatsapp app, puppeteer throws an error that damages any client i've created Oct 13, 2023
@a20000110
Copy link

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) => {

})`

@luisdbarboza
Copy link
Author

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

@luisdbarboza
Copy link
Author

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

@luiscuriel
Copy link

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

@luisdbarboza
Copy link
Author

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

@sgbtz
Copy link

sgbtz commented Oct 14, 2023

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.

@luisdbarboza
Copy link
Author

@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

@aldhinya
Copy link

Same issue here.

@venturion
Copy link

any updates?

@alechkos alechkos linked a pull request Dec 3, 2023 that will close this issue
7 tasks
@jpdev01
Copy link

jpdev01 commented Jan 2, 2024

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

@ekapasha17
Copy link

same here, I am facing the same issue

@alechkos
Copy link
Collaborator

@ekapasha17

same here, I am facing the same issue

Check #2661

@ekapasha17
Copy link

@ekapasha17

same here, I am facing the same issue

Check #2661

not solving the problem yet

@AndisKush
Copy link

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?

@DukazzCruz
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.