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.39k stars 3.67k forks source link

The session suddenly not valid after unexpected close of the browser #1595

Closed roysG closed 11 months ago

roysG commented 2 years ago

Is there an existing issue for this?

Describe the bug

The session is gone/stack after unexpected times when the browser suddenly close. I also using in pm2.

I also added the code:

console.log("(SIGINT) Shutting down..."); await client.destroy(); process.exit(0);

As mentioned in one of the posts here. But still the problem happens.

most of the time, this is the error i get:

reason unhandledRejection:Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.

I also tried to add these options in puppeter: puppeteer: { handleSIGINT: false, handleSIGTERM: false, .....

Expected behavior

The sessions suppose to be exists after crash or suddenly close

Steps to Reproduce the Bug or Issue

  1. run the service
  2. wait for unexpected closing browser
  3. Hope that this time it will stack the session, until you manually delete the folder, and then you will see scan qr code.

Relevant Code

No response

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.3 LTS Release: 18.04 Codename: bionic

Additional context

No response

luiscuriel commented 2 years ago

I am having the same issue... very often. can you help? Thanks!

elihaidv commented 2 years ago

Hi, Same problem here After few days/hours got an error:

node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:218
            return Promise.reject(new Error(`Protocol error (${method}): Session closed. Most likely the ${this._targetType} has been closed.`));
                                  ^

Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
    at CDPSession.send (/root/statuses-tracker/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:218:35)
    at ExecutionContext._evaluateInternal (/root/statuses-tracker/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
    at ExecutionContext.evaluate (/root/statuses-tracker/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
    at DOMWorld.evaluate (/root/statuses-tracker/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:97:24)
    at runNextTicks (node:internal/process/task_queues:61:5)
    at listOnTimeout (node:internal/timers:528:9)
    at processTimers (node:internal/timers:502:7)

I also tried to add the flag --disable-dev-shm-usage And tried to extend the RAM of my server, But nothing helps

luiscuriel commented 2 years ago

They are searching for the problem, see this: https://github.com/pedroslopez/whatsapp-web.js/issues/1567