-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Exception when calling fetchMessages method #2056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Getting the same bug. Any update on this. How you solved this @agstrc |
Same problem |
@agstrc @ankit-pn @ZhymabekRoman I made a bit of a hack, it's not pretty, but it solved the problem. Apparently, this error happens because Puppeteer is trying to access a resource from a screen that no longer exists. This makes sense, since there are several asynchronous calls in the initialize method, right when the login screen transitions to the app screen. function main() {
// 1. Hack at the process level to ignore the error -- DESPERATION
process.on('unhandledRejection', async (reason, promise) => {
console.log('Unhandled Error:', reason);
// Errors that the program should ignore
const whiteListError = [
'Execution context was destroyed',
];
const errorMessage = reason instanceof Error ? reason.message : String(reason);
if (!whiteListError.includes(errorMessage)) {
// Code to stop your bot
// Example:
// console.log('KILL BOT');
// setTimeout(() => process.exit(0), 3000);
}
});
// 2. CODE TO START WEBJS BOT
//....
client.initialize();
} Browser Type WhatsApp Account Type Does your WhatsApp account have multidevice enabled? Environment |
Would it be feasible to add a coercion argument to handle this error at the process level? const client = new Client({
// custom configs
coerce: ['Execution context was destroyed'] // ignore exception at process level
}) Otherwise, could you help us solve this issue? |
Is there an existing issue for this?
Describe the bug
Occasionally, the
fetchMessages
method will throw the following exception:I have observed the issue when, after initializing the client, loading all chat instances and attempting to fetch the messages on each of them.
It does not happen everytime, but often enough to be observed, as I have multiple clients (in separate containers) that will often restart the wwebjs client and attemp to fetch the messages.
Expected behavior
As a user, I expected the messages to be returned, instead of getting an exception.
Steps to Reproduce the Bug or Issue
Relevant Code
Browser Type
Chromium
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
OS: Docker (with image node:18)
WhatsApp Web version: 2.2311.5
Node.js version: v18.15.0
Additional context
This happens mainly on accounts that receive a large number of messages.
These accounts tend to load in older messages after the account has initialized. That is to say, new messages show up after initialization, but these messages were sent before the client started up.
The text was updated successfully, but these errors were encountered: