-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Is there an existing issue for this?
- I have searched the existing issues.
Is this a problem caused by your code, or is it specifically because of the library?
- I have double-checked my code carefully.
Describe the bug.
When handling the message_create event and calling msg.getContact(), execution sometimes fails inside the WhatsApp Web runtime with:
Expected Behavior
No Exception.
Steps to Reproduce the Bug or Issue
client.on('message_create', async (msg) => {
try {
const isGroupMsg = (await msg.getChat()).isGroup;
const from = await msg.getContact(); // crashes intermittently here
console.log({ isGroupMsg, from: from?.id?._serialized });
} catch (err) {
console.error('message_create handler error:', err);
}
});Note
-
I mainly use this in group chats, which may be one of the reasons
-
This issue also appears in other variant methods such as 'client.getContactById'
-
This issue usually occurs after the service has been running for some time (once the error appears, sending or receiving messages with the bot’s own account will continuously fail, though messages sent by other members can still be received normally). It cannot be reproduced on the first run.
Restarting the service can temporarily resolve it, but not always.
WhatsApp Account Type
Standard
Browser Type
Google Chrome
Operation System Type
Linux
Phone OS Type
Android
WhatsApp-Web.js Version
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#5438c2042b9b42370c0acef21e511c08bb462983"
WhatsApp Web Version
2.3000.1030467071
Node.js Version
v23.11.0
Authentication Strategy
LocalAuth
Additional Context
/home/www/msg-bot.example.com/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229
throw new Error('Evaluation failed: ' + (0, util_js_1.getExceptionMessage)(exceptionDetails));
^
Error: Evaluation failed: Error: Data passed to getter must include an id property (it's how we memoize) but got undefined
at new Error (<anonymous>:6:31)
at s (https://static.whatsapp.net/rsrc.php/v4/yu/r/4wLJsIo9jix.js:77:180)
at v (https://static.whatsapp.net/rsrc.php/v4/y1/r/c7DeHfEEslf.js:557:4487)
at Object.h [as getIsMe] (https://static.whatsapp.net/rsrc.php/v4/y1/r/c7DeHfEEslf.js:557:2443)
at window.WWebJS.getContactModel (pptr://__puppeteer_evaluation_script__:640:48)
at window.WWebJS.getContact (pptr://__puppeteer_evaluation_script__:666:30)
at ExecutionContext._ExecutionContext_evaluate (/home/www/msg-bot.example.com/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:15)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ExecutionContext.evaluate (/home/www/msg-bot.example.com/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16)
at async Client.getContactById (/home/www/msg-bot.example.com/node_modules/whatsapp-web.js/src/Client.js:1190:23)
at async Client.<anonymous> (/home/www/msg-bot.example.com/index.js:154:22)
This appears to occur on certain message types/sources (e.g., system/broadcast/newsletter/status or self messages) where the underlying contact model does not have a valid id when getIsMe is evaluated.
Additional context 2
- The error occurs at
index.js:154onconst from = await msg.getContact();with code path:message_create→msg.getContact()→Client.getContactById→ WA Web evaluation.
Package version
at Fixing msg.getContact and getContactById (#3978)
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#5438c2042b9b42370c0acef21e511c08bb462983"
Thank you.