Skip to content

Remote Session is not getting Saved #201751

@MalikHamzaSaleemi

Description

@MalikHamzaSaleemi

Issue Description

I am using whatsapp-web.js with RemoteAuth and wwebjs-mongo to store WhatsApp sessions in MongoDB. The client connects successfully and WhatsApp becomes ready, but the remote session is not being saved properly in MongoDB.

I added a debug wrapper around store.save() to confirm whether the session upload starts or completes. The upload process starts, but no session files/data are stored in MongoDB, and the remote_session_saved event is never triggered Also when i see Mongo Db there 2 documents got created but noting insde .

Because of this, whenever I restart my server/container, WhatsApp asks me to scan the QR code again instead of restoring the previous session.

Reproduction Steps

Genertae QR code
Scan QR code
Should connect whats aap and save remote session.
Tested on Both Whats aap Business & Standard.
Image

Image Image

Code Sample

let store;
function getStore() {
  if (!store) {
    if (mongoose.connection.readyState === 1) {
      try {
        const dbName = mongoose.connection.name;
        // wwebjs-mongo 1.1.0+ prefers the mongoose instance
        store = new MongoStore({ mongoose: mongoose });
        console.log(`📦 [RemoteAuth] MongoStore connected to DB: "${dbName}"`);
        
        // 🛠️ Debug Wrapper: Catch silent upload failures with a timeout
        const originalSave = store.save.bind(store);
        store.save = async (options) => {
          const sessionName = options.session;
          console.log(`📡 [RemoteAuth] STARTING UPLOAD for ${sessionName}...`);
          console.log(`⏳ Please wait, this can take 2-3 minutes for Atlas...`);
          
          let heartbeat = setInterval(() => {
            console.log(`⏳ [RemoteAuth] Still uploading ${sessionName}... do NOT close the app.`);
          }, 20000);

const uploadPromise = originalSave(options);
          const timeoutPromise = new Promise((_, reject) => 
            setTimeout(() => reject(new Error('Upload timed out after 300s')), 300000)
          );

try {
            await Promise.race([uploadPromise, timeoutPromise]);
            clearInterval(heartbeat);
            console.log(`✅ [RemoteAuth] UPLOAD SUCCESSFUL for ${sessionName}`);
          } catch (err) {
            clearInterval(heartbeat);
            console.error(`❌ [RemoteAuth] UPLOAD FAILED for ${sessionName}:`, err.message);
          }
        };
      } catch (err) {
        console.error("❌ [RemoteAuth] Failed to create MongoStore:", err.message);
      }
    } else {
      console.error("❌ [RemoteAuth] MongoStore FAILED: Mongoose state is " + mongoose.connection.readyState);
    }
  }
  return store;
}

const client = new Client({
    authStrategy: new RemoteAuth({
      clientId: clientId,
      store: getStore(),
      backupSyncIntervalMs: 300000
    }),
    puppeteer: {
      headless: true,
      protocolTimeout: 0,
      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",
      ],
    },
  });

// Listen for remote_session_saved event
client.on('remote_session_saved', () => {
    logger.info('🎉 REMOTE_SESSION_SAVED EVENT RECEIVED!');
});

client.on('ready', () => {
    logger.info('✅ WhatsApp ready');
    logger.info('📡 RemoteAuth active, waiting for remote_session_saved event...');
});

await client.initialize();

User Setup

WhatsApp Type
Account Type WhatsApp Business
Authentication Strategy RemoteAuth
WhatsApp Web Version 2.3000.1038984299
whatsapp-web.js Version github:wwebjs/whatsapp-web.js#main
Environment Version
Browser Type Chromium (Bundled with Puppeteer ^24.23.0)
Browser Version 146.0.7680.31
Phone OS Version Android V15
Running OS Version Windows (win32 x64) Also UBUNTU
Node.js Version v24.13.1

Checklist

  • I use the latest released version of whatsapp-web.js.
  • I have searched existing issues and confirmed this is not a duplicate.
  • I have verified this is a library issue, not a problem with my code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is brokenissued highHigh impact issuesecuritySecurity relatedtypingsType definitions

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions