Skip to content

Client.getState() and Client.getChats() throws r: r despite client being CONNECTED and WhatsApp Web fully loaded #201845

Description

@infoshahnn

Issue Description

  • I am using latest version of whatsapp-web.js library and when start application it getting logs below

0|whatsapp-reader | ⏳ 100% WhatsApp
0|whatsapp-reader | ✅ AUTHENTICATED
0|whatsapp-reader | ======================================
0|whatsapp-reader | ✅ WhatsApp READY
0|whatsapp-reader | ======================================
0|whatsapp-reader | WhatsApp Web Version: 2.3000.1043270046
0|whatsapp-reader | 🌐 URL: https://web.whatsapp.com/
0|whatsapp-reader | 📄 Title: (53) WhatsApp Business
0|whatsapp-reader | {
0|whatsapp-reader | body: '53\n' +
0|whatsapp-reader | 'All\n' +
0|whatsapp-reader | 'Unread\n' +
0|whatsapp-reader | '53\n' +
0|whatsapp-reader | 'Favourites\n' +
0|whatsapp-reader | 'Groups\n' +
0|whatsapp-reader | '28\n' +
0|whatsapp-reader | 'Rice\n' +
0|whatsapp-reader | 'यशस्वी कमोडिटी(Aivaग्रुप)\n' +
0|whatsapp-reader | '15:17\n' +
0|whatsapp-reader | "Don't Msg Yashasvi\n" +
0|whatsapp-reader | ': \n' +
0|whatsapp-reader | 'Photo\n' +
0|whatsapp-reader | 'IPGA Market Update,,,,,\n' +
0|whatsapp-reader | '15:22\n' +
0|whatsapp-reader | 'Ipga market update\n' +
0|whatsapp-reader | ': \n' +
0|whatsapp-reader | 'IPGA MARKET UPDATE 16 JULY 2026 JAIPUR MARKET (ALL PAID) CHANA:6100-75 CHANA DAL(DESI):6950-75 Free Pulses Market Update Join WhatsApp Group - https://chat.whatsapp.com/E5SmPW9LEuL0oJP7Ub9UEm?s=cl&p=a&ilr=1&amv=2 Follow our IPGA MARKET UPDATE channel- https://whatsapp.com/channel/0029VaA8scvKmCPGJoa02T1l Pls subscribe to our IPGA’s YouTube cha',
0|whatsapp-reader | readyState: 'complete',
0|whatsapp-reader | chatItems: 0,
0|whatsapp-reader | hasWWebJS: true
0|whatsapp-reader | }
0|whatsapp-reader | 📸 Screenshot saved: debug-ready.png
0|whatsapp-reader | State: CONNECTED
0|whatsapp-reader | ❌ getChats failed: r: r
0|whatsapp-reader | at ExecutionContext.#evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:456:34)
0|whatsapp-reader | at async ExecutionContext.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:293:12)
0|whatsapp-reader | at async IsolatedWorld.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:196:12)
0|whatsapp-reader | at async CdpFrame.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/api/Frame.ts:488:12)
0|whatsapp-reader | at async CdpPage.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/api/Page.ts:2362:12)
0|whatsapp-reader | at async Client.getChats (/root/whatsAppReader/node_modules/whatsapp-web.js/src/Client.js:1669:23)
0|whatsapp-reader | at async Client. (/root/whatsAppReader/src/whatsapp-reader.ts:1090:23)
0|whatsapp-reader | 🔄 Cycle 1/13
0|whatsapp-reader | 🌐 Fetching latest chats from WhatsApp...
0|whatsapp-reader | Attempt 1 failed r: r
0|whatsapp-reader | at ExecutionContext.#evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:456:34)
0|whatsapp-reader | at async ExecutionContext.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:293:12)
0|whatsapp-reader | at async IsolatedWorld.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:196:12)
0|whatsapp-reader | at async CdpFrame.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/api/Frame.ts:488:12)
0|whatsapp-reader | at async CdpPage.evaluate (/root/whatsAppReader/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/api/Page.ts:2362:12)
0|whatsapp-reader | at async Client.getChats (/root/whatsAppReader/node_modules/whatsapp-web.js/src/Client.js:1669:23)
0|whatsapp-reader | at async getChatsWithRetry (/root/whatsAppReader/src/whatsapp-reader.ts:212:27)
0|whatsapp-reader | at async getChatsCached (/root/whatsAppReader/src/whatsapp-reader.ts:503:19)
0|whatsapp-reader | at async processChats (/root/whatsAppReader/src/whatsapp-reader.ts:1518:22)
0|whatsapp-reader | at async scheduler (/root/whatsAppReader/src/whatsapp-reader.ts:1807:19)

  • It getting number of total chats and some other details but when calling client.getChats() function it throw error
  • waClient.getState() is library function and we are trying to getting whatsapp state
  • waClient.getChats() is library function and we are reading whatsapp messages
  • but due to this error we are unable to read messages from whatsapp

Need to look on it to resolve this issue. I think most of the developers face this issue

Thanks & Regards

Reproduction Steps

  1. Getting number of chats those are unread
  2. Trying to read each chat using client.getChats() library function it throw error

Code Sample

client.on("ready", async () => {
    const waClient = client!;

console.log("======================================");
    console.log("✅ WhatsApp READY");
    console.log("======================================");

const page = (waClient as any).pupPage;

const waVersion = await page.evaluate(() => {
        return (window as any).Debug?.VERSION ??
              (window as any).Debug?.VERSION_BASE ??
              "Unknown";
    });

console.log("WhatsApp Web Version:", waVersion);

try {
        console.log("🌐 URL:", await page.url());
        console.log("📄 Title:", await page.title());

const debug = await page.evaluate(() => ({
            body: document.body.innerText.substring(0, 500),
            readyState: document.readyState,
            chatItems: document.querySelectorAll('[role="listitem"]').length,
            hasWWebJS: typeof (window as any).WWebJS !== "undefined",
        }));

console.log(debug);

// Save screenshot for debugging if needed
        await page.screenshot({
            path: "debug-ready.png",
            fullPage: true,
        });

console.log("📸 Screenshot saved: debug-ready.png");

} catch (err) {
        console.error("Debug failed:", err);
    }

// Wait a few seconds after READY
    await sleep(5000);

try {
        console.log("State:", await waClient.getState());

// Test getChats only once
        const chats = await waClient.getChats();

console.log(`✅ getChats success: ${chats.length} chats`);

} catch (err) {
        console.error("❌ getChats failed:", err);

// Don't return; continue so the rest of the app can still start if desired.
    }

// First run initialization
    if (Object.keys(state).length === 0) {
        await initializeState(waClient);
    }

// Start scheduler
    scheduler();
  });

User Setup

WhatsApp Type
Account Type WhatsApp Business
Authentication Strategy LocalAuth
WhatsApp Web Version 2.3000.1043270046
whatsapp-web.js Version 1.34.7
Environment Version
Browser Type Google Chrome
Browser Version 149.0.7827.155
Phone OS Version Android 16
Running OS Version 24.04
Node.js Version 22.22.3

Checklist

  • I use the latest released version of whatsapp-web.js.
  • I have searched existing issues and confirmed this is not a duplicate.
  • I have verified this is a library issue, not a problem with my code.

@Adi1231234 please check this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is brokenissued highHigh impact issuetypingsType definitions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions