whatsapp-web.js icon indicating copy to clipboard operation
whatsapp-web.js copied to clipboard

Protocol error (Runtime.callFunctionOn): Promise was collected Sending Message

Open elhumbertoz opened this issue 9 months ago • 118 comments

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 () at /opt/myws-pool/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230:24 ProtocolError: Protocol error (Runtime.callFunctionOn): Promise was collected

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

elhumbertoz avatar Sep 14 '23 22:09 elhumbertoz

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.

seowzhenjun0126 avatar Sep 15 '23 02:09 seowzhenjun0126

Hi, I am facing the same issue.

videjunior avatar Sep 15 '23 16:09 videjunior

Same issues

Sansekai avatar Sep 17 '23 01:09 Sansekai

same.

homus32 avatar Sep 17 '23 07:09 homus32

Same here :(

abdullahalkis avatar Sep 17 '23 22:09 abdullahalkis

Please tell me how I can catch this error in the code? I at least need the bot to terminate.

homus32 avatar Sep 18 '23 14:09 homus32

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.

videjunior avatar Sep 18 '23 17:09 videjunior

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); } });

elhumbertoz avatar Sep 19 '23 15:09 elhumbertoz

Same problem here

wilsinho8 avatar Sep 20 '23 12:09 wilsinho8

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?

wilsinho8 avatar Sep 20 '23 12:09 wilsinho8

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 avatar Sep 21 '23 06:09 homus32

@homus32 What does logs.log contain?

Sansekai avatar Sep 21 '23 11:09 Sansekai

@homus32 What does logs.log contain?

This file contains all err stream, or all logs from script

homus32 avatar Sep 21 '23 11:09 homus32

This is the error:

image

elhumbertoz avatar Sep 22 '23 02:09 elhumbertoz

any fix for this issue ?

abdallah0x01 avatar Sep 22 '23 02:09 abdallah0x01

This is the error: image

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:

image

Did this solution work for you?

wilsinho8 avatar Sep 22 '23 19:09 wilsinho8

This is the error: image

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: image

Did this solution work for you?

Sorry, Did it not work for me. Chatgpt take a new mistake.

elhumbertoz avatar Sep 22 '23 19:09 elhumbertoz

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.

wilsinho8 avatar Sep 22 '23 19:09 wilsinho8

--disable-gpu-driver-bug-workarounds --disable-accelerated-2d-canvas --no-sandbox

add this args, for me the problem disappear, for now

wilsinho8 avatar Sep 22 '23 19:09 wilsinho8

--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

Sansekai avatar Sep 23 '23 13:09 Sansekai

Sorry, Did it not work for me

Sorry, Did it not work for me too

wilsinho8 avatar Sep 23 '23 13:09 wilsinho8

  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 🤦🏻)

abdullahalkis avatar Sep 23 '23 23:09 abdullahalkis

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

Sansekai avatar Sep 24 '23 14:09 Sansekai

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?

seowzhenjun0126 avatar Sep 24 '23 15:09 seowzhenjun0126

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

Sansekai avatar Sep 24 '23 15:09 Sansekai

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' }

havockdev avatar Sep 24 '23 19:09 havockdev

WhatsApp web version

How I can force update WhatsApp Werb versión?

image

elhumbertoz avatar Sep 25 '23 01:09 elhumbertoz

Problem solved

npm r whatsapp-web.js npm i whatsapp-web.js

wilsinho8 avatar Sep 25 '23 13:09 wilsinho8

Problem solved

npm r whatsapp-web.js npm i whatsapp-web.js

Don't work for me. :(

elhumbertoz avatar Sep 25 '23 14:09 elhumbertoz

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

wilsinho8 avatar Sep 25 '23 14:09 wilsinho8