waha icon indicating copy to clipboard operation
waha copied to clipboard

[BUG][WEBJS] - TargetCloseError: Unexpected Closure of Puppeteer Browser Session During Contact Check

Open Sabyrzhanuly opened this issue 1 year ago • 11 comments

Describe the Bug

When attempting to check the existence of a contact using the /api/contacts/check-exists endpoint, an error occurs because the browser session unexpectedly closes. The Puppeteer library throws a "Protocol error (Runtime.callFunctionOn): Target closed" exception, which interrupts the WebJS session.


Title

"TargetCloseError: Puppeteer Browser Session Closed Unexpectedly During Contact Check"


Version

{
  "version": "2024.12.1",
  "engine": "WEBJS",
  "tier": "PLUS",
  "browser": "/usr/bin/chromium"
}

Docker logs

TargetCloseError: Protocol error (Runtime.callFunctionOn): Target closed at CallbackRegistry.clear (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:73:36) at CdpCDPSession._onClosed (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CDPSession.js:101:25) at #onClose (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:167:21) at Connection.dispose (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:173:22) at CdpBrowser.disconnect (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Browser.js:230:26) at CdpBrowser.close (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Browser.js:226:20) at async WebjsClient.destroy (/app/node_modules/whatsapp-web.js/src/Client.js:787:9)

patron:PLUS

Sabyrzhanuly avatar Dec 07 '24 14:12 Sabyrzhanuly

Hi! Could you try to switch to chrome based image? https://waha.devlike.pro/docs/how-to/engines/#docker-images

devlikeapro/waha-plus:chrome	

patron:PRO

devlikepro avatar Dec 09 '24 04:12 devlikepro

Is there any error before that in docker logs, could you check?

docker compose logs

patron:PRO

devlikepro avatar Dec 09 '24 04:12 devlikepro

Is there any error before that in docker logs, could you check?

docker compose logs

patron:PRO

I won't be able to view the logs anymore. I've limited the logs by time, and they are being erased.

patron:PLUS

Sabyrzhanuly avatar Dec 09 '24 06:12 Sabyrzhanuly

Hi! Could you try to switch to chrome based image? https://waha.devlike.pro/docs/how-to/engines/#docker-images

devlikeapro/waha-plus:chrome	

patron:PRO

Hi Will anything happen to my current sessions? I already have active working sessions at the moment

patron:PLUS

Sabyrzhanuly avatar Dec 09 '24 06:12 Sabyrzhanuly

I've limited the logs by time, and they are being erased.

Do you mean you got the error only once or time to time, not always? In this case yeah, that's fine, just add a retry logic. It happens when browser got closed due to some internal issues, we restart it automatically, but it takes time (like a few seconds). Probably the request came into those seconds

patron:PRO

devlikepro avatar Dec 10 '24 02:12 devlikepro

I've limited the logs by time, and they are being erased.

Do you mean you got the error only once or time to time, not always? In this case yeah, that's fine, just add a retry logic. It happens when browser got closed due to some internal issues, we restart it automatically, but it takes time (like a few seconds). Probably the request came into those seconds

patron:PRO

It's possible, but such behavior occurred specifically when checking the number for existence. That's why I decided to report it. Thank you for your response!

patron:PLUS

Sabyrzhanuly avatar Dec 10 '24 05:12 Sabyrzhanuly

specifically when checking the number for existence

How often do you request it? It could be because of rate limits on the WA side :(

patron:PRO

devlikepro avatar Dec 14 '24 10:12 devlikepro

specifically when checking the number for existence

How often do you request it? It could be because of rate limits on the WA side :(

patron:PRO

Before sending a message, I check if the number exists. How else can this be done? I need to be sure whether the message was successfully sent or not.

patron:PLUS

Sabyrzhanuly avatar Dec 14 '24 16:12 Sabyrzhanuly

Hi! Could you try to update to 2025.1.4 🙏 We've removed few dubious flags when starting chrome/chromium process, it should give a bit more stabilitiy (but may consume a bit more resources)

patron:PRO

devlikepro avatar Jan 19 '25 09:01 devlikepro

Hi! Could you try to update to 2025.1.4 🙏 We've removed few dubious flags when starting chrome/chromium process, it should give a bit more stabilitiy (but may consume a bit more resources)

patron:PRO

I'm currently using MongoDB to store sessions. If I update to 2025.1.4, will everything continue to work as before? I noticed that you've switched to PostgreSQL.

Is it possible to seamlessly change the engine, or will I need to reauthorize all sessions manually?

patron:PLUS

Sabyrzhanuly avatar Jan 21 '25 16:01 Sabyrzhanuly

I noticed that you've switched to PostgreSQL.

Yes, we added PSQL support, not switched completely to it. It should work with no issue. We'll support MongoDB as long as possible (certainly the whole 2025)

Is it possible to seamlessly change the engine

Nope, as well as changing database type not possible :(

patron:PRO

devlikepro avatar Jan 22 '25 00:01 devlikepro

Hi! We've updated chrome and puppeter in 2025.4.2 and added a global error handler for some common issues (it'll restart browser if it get any errors like ProtocolError)

It won't fix all such errors, but should reduce the amount a lot.

patron:PRO

devlikepro avatar May 05 '25 06:05 devlikepro