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
-
Create a WhatsApp client instance using whatsapp-web.js.
-
Initialize the client and wait until the ready event is emitted.
-
Keep the client running normally for some time.
-
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
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
Create a WhatsApp client instance using whatsapp-web.js.
Initialize the client and wait until the
readyevent is emitted.Keep the client running normally for some time.
Call
client.getChats()through an API endpoint or background task:Code example
Error