Skip to content

getChats() throws ExecutionContext error when calling Client.getChats() #201842

Description

@2556227850

Issue Description

Calling client.getChats() always throws a Puppeteer execution context error.

The issue is 100% reproducible. When the WhatsApp client is ready and getChats() is called, the method fails during Puppeteer's page evaluation and cannot return the chat list.

The client connection remains active, but getChats() cannot be completed successfully.

Reproduction Steps

  1. Create a WhatsApp client instance using whatsapp-web.js.

  2. Initialize the client and wait until the ready event is emitted.

  3. Keep the client running normally for some time.

  4. Call client.getChats() through an API endpoint or background task:

Code example

import { Client } from 'whatsapp-web.js'

const client = new Client({
  puppeteer: {
    headless: true
  }
})

client.on('ready', async () => {
  console.log('Client is ready')

  try {
    const chats = await client.getChats()

    console.log(`Total chats: ${chats.length}`)
  } catch (error) {
    console.error('Failed to get chats:', error)
  }
})
client.on('qr', async (qr) => {
  if (qr) {
    console.log('QR code received, please scan it with your WhatsApp app.', qr)
  }
})
await client.initialize()

Error

 console.error('Failed to get chats:', error)
 r  r, r
error stack:
   ExecutionContext.ts ExecutionContext.#evaluate
        node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:456
   ExecutionContext.ts async ExecutionContext.evaluate
        node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:293
   IsolatedWorld.ts    async IsolatedWorld.evaluate
        node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:196
   Frame.ts    async CdpFrame.evaluate
        node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/api/Frame.ts:488
   Page.ts     async CdpPage.evaluate
        node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/api/Page.ts:2362
   Client.js   async Client.getChats
        node_modules/whatsapp-web.js/src/Client.js:1729
   chat.ts     async GetChats
        src/modules/WWeb/chat.ts:18
   index.ts    async <anonymous>
        src/routes/api/WWeb/chat/index.ts:49
   app.ts      async <anonymous>
        src/app.ts:66
   index.js    async serve
        node_modules/koa-static/index.js:53
   index.js    async logger
        node_modules/koa-logger/index.js:130
   index.js    async cors
        node_modules/koa2-cors/dist/index.js:91

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