Issue Description
I am facing an issue with whatsapp-web.js authentication.
When I use LocalAuth, only one client connects at a time. When another user/client connects, it removes or overwrites the session of the previous user.
To solve this, I tried using RemoteAuth with MongoDB. I am using Mongo Express, and my environment details are:
MongoDB Version: 8.2.2
Node Version: 18.20.3
V8 Version: 10.2.154.26-node.37
On my VPS, RemoteAuth creates the remote auth/session folders, but it does not save the required files inside them. Because of this, whenever I restart the server container, WhatsApp asks me to scan the QR code again.
Also, this event is not being triggered:
client.on("remote_session_saved", () => {
console.log("Remote session saved");
});
I need guidance on why the RemoteAuth session is not being saved properly inside Docker/VPS and how I can persist WhatsApp sessions after container restart.
Reproduction Steps
Set up a Node.js project using whatsapp-web.js.
Configure authentication using RemoteAuth with MongoDB.
Run MongoDB on VPS using Docker/Mongo Express.
Start the WhatsApp client container on the VPS.
Scan the QR code and connect one WhatsApp account.
Wait for the client to become ready.
Restart the server/container.
Start the WhatsApp client again.
WhatsApp asks to scan the QR code again instead of restoring the previous session.
Also, the following event does not trigger:
client.on("remote_session_saved", () => {
console.log("Remote session saved");
});
Here Look when i did use teh Mongo Express
also i see these errors when the 1st connected client got session destroy
⚠️ Unhandled rejection: TargetCloseError: Protocol error (Network.getResponseBody): Target closed
whatsclone | at CallbackRegistry.clear (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:82:36)
whatsclone | at CdpCDPSession.onClosed (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:115:25)
whatsclone | at #onClose (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:190:21)
whatsclone | at WebSocket. (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/NodeWebSocketTransport.js:48:30)
whatsclone | at callListener (/usr/src/app/node_modules/ws/lib/event-target.js:290:14)
whatsclone | at WebSocket.onClose (/usr/src/app/node_modules/ws/lib/event-target.js:220:9)
whatsclone | at WebSocket.emit (node:events:524:28)
whatsclone | at WebSocket.emitClose (/usr/src/app/node_modules/ws/lib/websocket.js:273:10)
whatsclone | at Receiver.receiverOnFinish (/usr/src/app/node_modules/ws/lib/websocket.js:1214:20)
whatsclone | at Receiver.emit (node:events:524:28)
whatsclone | at finish (node:internal/streams/writable:955:10)
whatsclone | at node:internal/streams/writable:936:13
whatsclone | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
whatsclone | cause: ProtocolError
whatsclone | at <instance_members_initializer> (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:103:14)
whatsclone | at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:107:16)
whatsclone | at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
whatsclone | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
whatsclone | cause: ProtocolError
whatsclone | at <instance_members_initializer> (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:103:14)
whatsclone | at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:107:16)
whatsclone | at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
uppeteer/common/CallbackRegistry.js:103:14)
whatsclone | at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:107:16)
whatsclone | at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
r/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
teer/api/HTTPResponse.js:43:25)
whatsclone | at async /usr/src/app/node_modules/whatsapp-web.js/src/Client.js:1267:39
whatsclone | }
Code Sample
initializationTimestamps.set(clientId, Date.now());
sessionStatus.set(clientId, "initializing");
const client = new Client({
authStrategy: new LocalAuth({
clientId: clientId,
dataPath: './.wwebjs_auth'
}),
puppeteer: {
headless: true,
protocolTimeout: 0, // 🔧 Prevent AI send/interaction timeouts
handleSIGINT: false,
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
"--disable-software-rasterizer",
"--no-zygote",
"--no-first-run",
"--disable-extensions",
"--disable-default-apps",
"--disable-notifications",
"--disable-background-networking",
"--disable-sync",
"--hide-scrollbars",
"--mute-audio",
"--safebrowsing-disable-auto-update",
"--disable-blink-features=AutomationControlled",
"--js-flags=\"--max-old-space-size=512\"",
"--disable-web-security",
"--aggressive-cache-discard",
"--disable-cache",
"--disable-application-cache",
"--disable-offline-load-stale-cache",
"--disk-cache-size=0",
],
},
});
client.on('loading_screen', (percent, message) => {
console.log(`⏳ Loading (${clientId}): ${percent}% - ${message}`);
});
client.on("authenticated", async () => {
console.log(`🔐 Authenticated ${clientId}`);
});
User Setup
| WhatsApp |
Type |
| Account Type |
WhatsApp Business |
| Authentication Strategy |
LocalAuth |
| WhatsApp Web Version |
v1.27.1-alpha |
| whatsapp-web.js Version |
github:wwebjs/whatsapp-web.js#main |
| Environment |
Version |
| Browser Type |
Chrominum |
| Browser Version |
v24.23.0 |
| Phone OS Version |
Android |
| Running OS Version |
UNUNTU |
| Node.js Version |
v20.20.2 |
Checklist
Issue Description
I am facing an issue with whatsapp-web.js authentication.
When I use LocalAuth, only one client connects at a time. When another user/client connects, it removes or overwrites the session of the previous user.
To solve this, I tried using RemoteAuth with MongoDB. I am using Mongo Express, and my environment details are:
MongoDB Version: 8.2.2
Node Version: 18.20.3
V8 Version: 10.2.154.26-node.37
On my VPS, RemoteAuth creates the remote auth/session folders, but it does not save the required files inside them. Because of this, whenever I restart the server container, WhatsApp asks me to scan the QR code again.
Also, this event is not being triggered:
client.on("remote_session_saved", () => {
console.log("Remote session saved");
});
I need guidance on why the RemoteAuth session is not being saved properly inside Docker/VPS and how I can persist WhatsApp sessions after container restart.
Reproduction Steps
Set up a Node.js project using whatsapp-web.js.
Configure authentication using RemoteAuth with MongoDB.
Run MongoDB on VPS using Docker/Mongo Express.
Start the WhatsApp client container on the VPS.
Scan the QR code and connect one WhatsApp account.
Wait for the client to become ready.
Restart the server/container.
Start the WhatsApp client again.
WhatsApp asks to scan the QR code again instead of restoring the previous session.
Also, the following event does not trigger:
client.on("remote_session_saved", () => {
console.log("Remote session saved");
});
Here Look when i did use teh Mongo Express
also i see these errors when the 1st connected client got session destroy
⚠️ Unhandled rejection: TargetCloseError: Protocol error (Network.getResponseBody): Target closed
whatsclone | at CallbackRegistry.clear (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:82:36)
whatsclone | at CdpCDPSession.onClosed (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:115:25)
whatsclone | at #onClose (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:190:21)
whatsclone | at WebSocket. (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/NodeWebSocketTransport.js:48:30)
whatsclone | at callListener (/usr/src/app/node_modules/ws/lib/event-target.js:290:14)
whatsclone | at WebSocket.onClose (/usr/src/app/node_modules/ws/lib/event-target.js:220:9)
whatsclone | at WebSocket.emit (node:events:524:28)
whatsclone | at WebSocket.emitClose (/usr/src/app/node_modules/ws/lib/websocket.js:273:10)
whatsclone | at Receiver.receiverOnFinish (/usr/src/app/node_modules/ws/lib/websocket.js:1214:20)
whatsclone | at Receiver.emit (node:events:524:28)
whatsclone | at finish (node:internal/streams/writable:955:10)
whatsclone | at node:internal/streams/writable:936:13
whatsclone | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
whatsclone | cause: ProtocolError
whatsclone | at <instance_members_initializer> (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:103:14)
whatsclone | at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:107:16)
whatsclone | at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
whatsclone | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
whatsclone | cause: ProtocolError
whatsclone | at <instance_members_initializer> (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:103:14)
whatsclone | at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:107:16)
whatsclone | at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
uppeteer/common/CallbackRegistry.js:103:14)
whatsclone | at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:107:16)
whatsclone | at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
r/common/CallbackRegistry.js:25:26)
whatsclone | at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Connection.js:108:26)
whatsclone | at CdpCDPSession.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
/CdpSession.js:74:33)
whatsclone | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/HTTPResponse.js:99:65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
65
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
whatsclone | at async CdpHTTPResponse.text (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/HTTPResponse.js:43:25)
teer/api/HTTPResponse.js:43:25)
whatsclone | at async /usr/src/app/node_modules/whatsapp-web.js/src/Client.js:1267:39
whatsclone | }
Code Sample
User Setup
Checklist