whatsapp-web.js: Protocol error (Runtime.callFunctionOn): Promise was collected Sending Message

Is there an existing issue for this?

  • 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 (<anonymous>) 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

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Comments: 116 (20 by maintainers)

Most upvoted comments

I thought, I solved the problem. After I understood the article from Using Runtime.evaluate with awaitPromise: true I sometimes obtain Error: Promise was collected.

I added await in every before sending message. You can see it at https://github.com/Sansekai/whatsapp-web.js Now, my bot has been running for 7 hours without any Promise was collected issues. Screenshot_20230930_070214_WhatsAppBusiness

If you want to use it you can use it like this:

"whatsapp-web.js": "github:Sansekai/whatsapp-web.js"

Sorry my English is bad

@fernandomondo, I separated the functionalities of linkPreview and sendSeen from the pupPage.Evaluate() call within the client.sendMessage() function in order to prevent the error from being triggered. You can see all the changes I have made in this fork: https://github.com/elhumbertoz/whatsapp-web.js

Right now is working very well.

Review please: https://github.com/elhumbertoz/whatsapp-web.js/blob/main/src/Client.js https://github.com/elhumbertoz/whatsapp-web.js/blob/main/src/util/Injected.js

image

Thank @Sansekai for the solution, it worked for me.

I have 10 applications running for 48 hours without any errors after applying your solution. I left another 2 smaller applications without applying the adjustments, and from time to time, the error still occurs. I’ll apply them to these now.

i’ve changed de node version to 14 and puppeteer version to 13 to test. Lets see how is gonna be tomorrow

@elhumbertoz Didn’t the problem arise again?

it seems that nodejs is unable to wait for any of the await and puppteer throws the Promise was collected error.

🤣

I have this same bug since September. I already opened an issue here but it was closed without a solution.

What improved this a lot was this change I made:

const newMessage = await this.pupPage.evaluate(async (chatId, message, options, sendSeen) => {
                const chatWid = window.Store.WidFactory.createWid(chatId);
                const chat = await window.Store.Chat.find(chatWid);

                if (sendSeen) {
                   await window.WWebJS.sendSeen(chatId);
                }
                
                const msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen);
                //return msg.serialize();  // <<-----HERE
                console.log(`sent msg. msg.id: ${JSON.stringify(msg.id)}`);
                var m = { id: msg.id, t: msg.t };
                console.log(`serialize to m: ${JSON.stringify(m)}`);
                return m;
        }, chatId, content, internalOptions, sendSeen);

looks like they changed that last week too: I haven’t tried this latest version yet.

PR: https://github.com/pedroslopez/whatsapp-web.js/pull/2716 commit: https://github.com/pedroslopez/whatsapp-web.js/commit/bd7cf9b46348122d020f5d62c5cc1b36d3856cb2

Error has returned after updating the new version of WhatsAppWeb.

This error message occurs randomly after sending a message using client.SendMessage(). Does anyone else experience this?

ProtocolError: Protocol error (Runtime.callFunctionOn): Promise was collected (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:86:14) at <instance_members_initializer> at new Callback (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:90:16) (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:22:26) at CallbackRegistry.create at Connection._rawSend (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:80:26) at CdpCDPSession.send (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CDPSession.js:66:33) at #evaluate (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:201:50) (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:116:16) at async ExecutionContext.evaluate (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:123:16) at async IsolatedWorld.evaluate at async CdpFrame.evaluate (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:353:20) at async CdpPage.evaluate (/opt/myws-pool/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:741:20) at async Client.sendMessage (/opt/myws-pool/node_modules/whatsapp-web.js/src/Client.js:916:28)