pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.05k stars 3.58k forks source link

"Protocol error (Runtime.callFunctionOn): Target closed." when run as a service #2428

Closed mmaeffert closed 1 year ago

mmaeffert commented 1 year ago

Is there an existing issue for this?

Describe the bug

I migrated servers and got the same code running with the same dependencies. When I start the bot via the CLI, everything works fine. However when I start the program via a service file, I get the following error:

/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230
Aug 22 14:27:37 4cpu8gbStickem nohup[56994]:                 error: new Errors_js_1.ProtocolError(),
Aug 22 14:27:37 4cpu8gbStickem nohup[56994]:                        ^
Aug 22 14:27:37 4cpu8gbStickem nohup[56994]: ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed.

Expected behavior

Read the local auth files and start as usual

Steps to Reproduce the Bug or Issue

systemctl start whatsappbot.service

Relevant Code

Service file:

[Unit]
Description=Whatsapp Bot for retreiving stickers that users can manage on stickem.shop

[Service]
Restart=always
RestartSec=2s
User=root
ExecStart=nohup node [path]/index.js > [path]/systemd_output.log

Init properties:

const client = new Client({
    puppeteer: {
      headless: true,
        args: [
          '--no-sandbox',
          '--disable-site-isolation-trials',
          '--disable-setuid-sandbox',
        ],
        executablePath: '/usr/bin/chromium-browser',
    },
        executablePath: '/usr/bin/chromium-browser',
        authStrategy: new LocalAuth()
});

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

No, I am not using Multi Device

Environment

OS: Ubuntu 22.04 "whatsapp-web.js": "^1.21.1-alpha.1" Node Version: 20.3.0

Additional context

No response

NissiusRibas commented 1 year ago

mesmo erro aqui!

same error here

/whats/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230
                error: new Errors_js_1.ProtocolError(),
                       ^

ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed.
    at /whats/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230:24
    at new Promise (<anonymous>)
    at CDPSession.send (/whats/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226:16)
    at ExecutionContext._evaluateInternal (/whats/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
    at ExecutionContext.evaluateHandle (/whats/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:155:21)
    at WaitTask.rerun (/whats/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:551:37)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  originalMessage: ''
}
NissiusRibas commented 1 year ago

@mmaeffert managed to solve?

Does anyone know how to resolve?

mmaeffert commented 1 year ago

@NissiusRibas No and it has been driving me insane. I figured that deleting the .wwebjs_cache and .wwebjs_auth, it sometimes works. I also get another error message when running the programm with a non root user …is not a snap cgroup

(node:8587) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/user.slice/user-0.slice/session-1.scope is not a snap cgroup

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/home/wa/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
    at Interface.<anonymous> (/home/wa/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:231:68)
    at Interface.emit (events.js:326:22)
    at Interface.close (readline.js:416:8)
    at Socket.onend (readline.js:194:10)
    at Socket.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:8587) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8587) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Now my old installation is not working either, without doing ANY changes. It ran for almost 12 month

mmaeffert commented 1 year ago

When I do the following, I get it running:

Then I get it running, but only if I do not use LocalAuth, which kind of defeats the purpose of using a service, but that suggests that authentication seems to trigger the issue

mmaeffert commented 1 year ago

Fixed. I tried to safe money and chose ARM64 architecture. Went back to x86 and everything is running smooth now

hippies67 commented 1 year ago

When I do the following, I get it running:

Then I get it running, but only if I do not use LocalAuth, which kind of defeats the purpose of using a service, but that suggests that authentication seems to trigger the issue

thanks man you really help me.