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
14.62k stars 3.48k forks source link

Session closes after 1 month #2005

Closed unish7 closed 7 months ago

unish7 commented 1 year ago

Is there an existing issue for this?

Describe the bug

Hello people

I am having this problem for a long time. First it was closed after 7~10 days. Then I changed authStrategy to RemoteAuth and now it closed after 30 days.

Expected behavior

I expected the session to remain open indefinitely. The cell phone that was used to scan the QR and link the account is off, but I understand that shouldn't matter.

Steps to Reproduce the Bug or Issue

In this case and in all the tests that I have been carrying out, the session closes sooner or later.

Relevant Code

Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed. at CDPSession.send (C:\bots\8350\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:218:35) at ExecutionContext._evaluateInternal (C:\bots\8350\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:204:50) at ExecutionContext.evaluate (C:\bots\8350\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:27) at DOMWorld.evaluate (C:\bots\8350\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:97:24) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5)

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Windows Server 2016 whatsapp-web-js v1.18.3 Node.js v16.18.0

Additional context

const { Client, Location, List, Buttons,MessageMedia, RemoteAuth } = require('./index');

// Require database const { MongoStore } = require('wwebjs-mongo'); const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017').then(() => { const store = new MongoStore({ mongoose: mongoose }); const client = new Client({ authStrategy: new RemoteAuth({ store: store, clientId: port, backupSyncIntervalMs: 300000 }) });

client.initialize();

............

LaboratorySales commented 1 year ago

Страшно перезапускать сервер, почти каждый раз 17-10 сессий слетают. Тоже использую RemoteAuth и LocalAuth

Google Translate: It's scary to restart the server, almost every time 17-10 sessions crash. I also use RemoteAuth and LocalAuth

diazzaid commented 1 year ago

same case image

CSFelix commented 1 year ago

Same issue here

andresrodriguezsantos44 commented 1 year ago

Esta es mi clase whatsappClient y no he tenido problemas. import { Service, Inject } from 'typedi'; import qrcode from 'qrcode-terminal'; import { Client, LocalAuth } from 'whatsapp-web.js'; import { ClientStatus } from './client-status'; import { handleMessage } from './messageHandler'; @Service() export class WhatsAppClient { client: Client; clientStatus: ClientStatus;

constructor(@Inject() clientStatus: ClientStatus) {
    this.client = new Client({
        authStrategy: new LocalAuth(),
    });
    this.clientStatus = clientStatus;
}

initialize() {
    console.log('Initializing whatsapp client...');
    this.client.initialize().then();
}

listenToMessages() {
    this.client.on('qr', (qr) => {
        qrcode.generate(qr, { small: true });
    });

    this.client.on('authenticated', () => {
        console.log('Client is authenticated!');
    });

    this.client.on('ready', () => {
        console.log('Client is ready!');
    });

    this.client.on('disconnected', (reason) => {
        console.log('Client is disconnected: ', reason);
        this.client.initialize().then();
    });

    this.client.on('message', async (msg) => {
        await handleMessage(msg, this.clientStatus);
    });

    process.on('unhandledRejection', (error) => {
        console.error('Unhandled Promise Rejection:', error);
    });
}

}