Skip to content

getChats is not working #3277

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

client.on('ready', async () => {
console.log('WhatsApp client is ready');
try {
const chats = await client.getChats();
console.log('Chats retrieved:', chats);
} catch (error) {
console.error('Error retrieving chats:', error);
}
});

It throw error:
Error retrieving chats: Evaluation failed: a
Stack trace: Error: Evaluation failed: a
at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ExecutionContext.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16)
at async Client.getChats (/app/node_modules/whatsapp-web.js/src/Client.js:986:21)

Expected behavior

It should return chats

Steps to Reproduce the Bug or Issue

const express = require('express');
const { Client, LocalAuth } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');

// Create a new instance of the WhatsApp client
const client = new Client({
puppeteer: {
headless: true,
args: ['--no-sandbox'],
timeout: 60000 // Increase the timeout
}
});

// Display the QR code in the terminal
client.on('qr', (qr) => {
qrcode.generate(qr, { small: true });
});

// Log in successfully
client.on('ready', () => {
console.log('WhatsApp Web client is ready!');
});

// Initialize the Express server
const app = express();
app.use(express.json());

// API route to send a WhatsApp message
app.post('/send-message', async (req, res) => {
const { number, message } = req.body;

const formattedNumber = `${number}@c.us`;

try {
    // Send message to the number
    const response = await client.sendMessage(formattedNumber, message);
    res.json({ status: 'success', message: 'Message sent!', response });
} catch (error) {
    res.json({ status: 'error', message: 'Failed to send message', error });
}

});

// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(Server running on port ${port});
});

// Start WhatsApp client
client.initialize();

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

Ubuntu 24.04 LTS

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions