whatsapp-web.js
whatsapp-web.js copied to clipboard
Protocol error (Runtime.callFunctionOn): Promise was collected Sending Message
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
Sometimes when sending a message I get this error:
Protocol error (Runtime.callFunctionOn): Promise was collected
}
originalMessage: 'Promise was collected'
at DOMWorld.evaluate (/opt/myws-pool/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:97:24) {
at ExecutionContext.evaluate (/opt/myws-pool/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
at ExecutionContext._evaluateInternal (/opt/myws-pool/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
at CDPSession.send (/opt/myws-pool/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226:16)
at new Promise (
Expected behavior
After handling the exception, the library stops working and I have to restart the program.
Steps to Reproduce the Bug or Issue
// // Envía el mensaje por WhatsApp // await client.sendMessage(phone, message, options)
Relevant Code
No response
Browser Type
Google Chrome
WhatsApp Account Type
WhatsApp Business
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
Ubuntu Server 22.04.3 LTS (GNU/Linux 5.15.0-76-generic x86_64) whatsapp-web.js version https://github.com/pedroslopez/whatsapp-web.js#main
Additional context
No response
Hi, I am facing the same issue. Do you have any workaround for now? I tried upgrading Puppeteer to the latest version and is still seeing this error.
This occur randomly when calling the "sendMessage()" function.
Can anyone advice on this? It's been bugging me for a few days and I can't find any related issue on Puppeteer.
Hi, I am facing the same issue.
Same issues
same.
Same here :(
Please tell me how I can catch this error in the code? I at least need the bot to terminate.
Please tell me how I can catch this error in the code? I at least need the bot to terminate.
I am using the chokidar package to analyze the pm2 log file and when this error is detected, the entire system restarts.
Please tell me how I can catch this error in the code? I at least need the bot to terminate.
My program restart automatically because after exception. This code I use to restart the program.
await client.sendMessage(phone, message, options).then((response) => {
// TODO: Message send
}).catch(error => {
if (error.message == 'Protocol error (Runtime.callFunctionOn): Promise was collected') {
setTimeout(async () => {
// Terminate proceess after 1 second
process.exit(0);
}, 1000);
}
});
Same problem here
Please tell me how I can catch this error in the code? I at least need the bot to terminate.
My program restart automatically because after exception. This code I use to restart the program.
await client.sendMessage(phone, message, options).then((response) => {
// TODO: Message send
}).catch(error => {
if (error.message == 'Protocol error (Runtime.callFunctionOn): Promise was collected') {
setTimeout(async () => {
// Terminate proceess after 1 second
process.exit(0);
}, 1000);
}
});
every sendmessage you put this code?
import * as chokidar from 'chokidar';
import * as fs from 'fs/promises';
let linesCount = 0;
const logPath = './logs.log';
const watcher = chokidar.watch(logPath);
function setLastLine(lines: string[]){
if (lines[lines.length - 1] === "") {
linesCount = lines.length - 1;
} else {
linesCount = lines.length;
}
}
async function getFileLines(path: string): Promise<string[]> {
const log = await fs.readFile(path, "utf8");
return log.split('\n');
}
watcher.on('change', async (path) => {
const lines = await getFileLines(path)
const newLines = [];
if (lines.length > linesCount) {
newLines.push(...lines.slice(linesCount));
}
setLastLine(lines);
// console.log(newLines.join("\n"))
if (newLines.join("\n").includes("ProtocolError: Protocol error (Runtime.callFunctionOn): Promise was collected")) {
console.error("Выход из-за ошибки")
throw new Error("Выход.")
}
});
async function main(){
const lines = await getFileLines(logPath)
setLastLine(lines);
}
main().then()
console.log(" > Fix imported")
my crutch :)
@homus32 What does logs.log contain?
@homus32 What does logs.log contain?
This file contains all err stream, or all logs from script
This is the error:
any fix for this issue ?
This is the error:
Please everyone try this suggestion to solve this error:
Yes, when using Puppeteer in Node.js, you can avoid the "STATUS_BREAKPOINT" error when loading a web page. Puppeteer provides configuration options that you can use to prevent execution from stopping at breakpoints.
You can use the
ignoreDefaultArgs
option to prevent default arguments from being passed to the underlying Chromium browser used by Puppeteer. By omitting the arguments related to breakpoints, you can avoid the "STATUS_BREAKPOINT" error.Here's an example of how you can configure Puppeteer to avoid the error:
javascript
const browser = await puppeteer.launch({
ignoreDefaultArgs: ['--enable-automation'],
});
In my code:
Did this solution work for you?
This is the error:
Please everyone try this suggestion to solve this error: Yes, when using Puppeteer in Node.js, you can avoid the "STATUS_BREAKPOINT" error when loading a web page. Puppeteer provides configuration options that you can use to prevent execution from stopping at breakpoints. You can use the
ignoreDefaultArgs
option to prevent default arguments from being passed to the underlying Chromium browser used by Puppeteer. By omitting the arguments related to breakpoints, you can avoid the "STATUS_BREAKPOINT" error. Here's an example of how you can configure Puppeteer to avoid the error: javascriptconst browser = await puppeteer.launch({
ignoreDefaultArgs: ['--enable-automation'],
});
In my code:Did this solution work for you?
Sorry, Did it not work for me. Chatgpt take a new mistake.
One thing I noticed, it starts the pm2 service after chrome uses 100% of the processing of all cores. But I can't figure out what's causing this maximum processing usage.
--disable-gpu-driver-bug-workarounds --disable-accelerated-2d-canvas --no-sandbox
add this args, for me the problem disappear, for now
--disable-gpu-driver-bug-workarounds --disable-accelerated-2d-canvas --no-sandbox
add this args, for me the problem disappear, for now
Didn't work for me
Sorry, Did it not work for me
Sorry, Did it not work for me too
this.engine = new Client({
puppeteer: {
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-web-security',
'--disable-gpu',
'--hide-scrollbars',
'--disable-cache',
'--disable-application-cache',
'--disable-gpu-driver-bug-workarounds',
'--disable-accelerated-2d-canvas',
],
executablePath: chromeExecutablePath,
},
restartOnAuthFail: false,
authStrategy: new LocalAuth({ clientId: phone.number }),
});
I use this for now after 2500 sending message no any error yet. ( Did not solve 🤦🏻)
Maybe you can do some research from this link https://peter.sh/experiments/chromium-command-line-switches/
I'm also trying to find the problem
Hey guys, I faced this issue about a week ago. I found that by updating the WhatsApp web version to 2.2338.12 and above, the error no longer occur.
For those that are still facing the error, can you make sure the WhatsApp version that you are using is the latest?
Hey guys, I faced this issue about a week ago. I found that by updating the WhatsApp web version to 2.2338.12 and above, the error no longer occur.
For those that are still facing the error, can you make sure the WhatsApp version that you are using is the latest?
I'm currently using whatsapp web veri "2.2340.11" but I still have an error
Hello, the solutions above didn't work for me. The Whatsapp Web version is "2.2340.11", and I still receive the "STATUS_BREAKPOINT" error after a few minutes of execution
Erro:
ProtocolError: Protocol error (Runtime.callFunctionOn): Promise was collected at C:\Users\ins005\Desktop\ainbbt\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:230:24 at new Promise (<anonymous>) at CDPSession.send (C:\Users\ins005\Desktop\ainbbt\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:226:16) at ExecutionContext._evaluateInternal (C:\Users\ins005\Desktop\ainbbt\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:204:50) at ExecutionContext.evaluate (C:\Users\ins005\Desktop\ainbbt\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:27) at DOMWorld.evaluate (C:\Users\ins005\Desktop\ainbbt\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:97:24) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5) { originalMessage: 'Promise was collected' }
WhatsApp web version
How I can force update WhatsApp Werb versión?
Problem solved
npm r whatsapp-web.js npm i whatsapp-web.js
Problem solved
npm r whatsapp-web.js npm i whatsapp-web.js
Don't work for me. :(
Problem solved npm r whatsapp-web.js npm i whatsapp-web.js
Don't work for me. :(
specifically this was the problem in my case: https://github.com/pedroslopez/whatsapp-web.js/pull/2314