#Issue: Client stuck on loading screen when reusing LocalAuth session #3712

16 messages · Page 1 of 1 (latest)

desert root
#

Describe the bug.
When creating a WhatsApp Web client with LocalAuth and reusing the same clientId, the client sometimes gets stuck on the loading screen.
This happens after restarting my application and trying to initialize an existing client session.

const { app } = require("electron");
const { v7: uuidv7 } = require("uuid");

let clientId = uuidv7();

const Store = require("electron-store");
const store = new Store();

client[clientId] = new Client({
  puppeteer: {
    pipe: true,
    executablePath: store.get("chromePath"),
  },
  session: clientId,
  authStrategy: new LocalAuth({
    clientId: clientId,
    dataPath: app.getPath("userData") + "/sessions",
  }),
});

try {
  client[clientId].initialize();
  electronLogs.info(`Client ${clientId} is initializing`);
} catch (e) {
  console.log("Error initializing client:", e);
}

client[clientId].on("loading_screen", (percent, message) => {
  console.log("Loading:", percent, message);
});

more on
https://github.com/pedroslopez/whatsapp-web.js/issues/3712

CC: @sterile schooner

GitHub

Is there an existing issue for this? I have searched the existing issues. Is this a problem caused by your code, or is it specifically because of the library? I have double-checked my code carefull...

bold fractal
#

Delete cache?

desert root
#

Yes when its happened, Firstly i remove all my cache and also restarted my system many times but its not work

past mirage
#

Delete folders .wwebjs_auth and .wwebjs_cache, and try to change clientId to something simpler, such as clientId01, clientId02

desert root
#

tried to change clientId but it cant work and also removed .wwebjs_auth and .wwebjs_cache but the client is not persist

meager lotus
#

I’ve run into this issue a few times. I recommend testing different parameters in Puppeteer and trying to change the IP or the machine it’s running on. It could also be due to a lack of resources (CPU and memory) on the machine.

#
 this.Client = new Client({
        authStrategy: new LocalAuth({
          clientId: clientId,
          dataPath:  app.getPath("userData") + "/sessions",
        }),
        takeoverOnConflict: true,
        takeoverTimeoutMs: 10,
        puppeteer: {
          headless: true,
          args: [
            '--autoplay-policy=user-gesture-required',
            '--disable-background-networking',
            '--disable-background-timer-throttling',
            '--disable-backgrounding-occluded-windows',
            '--disable-breakpad',
            '--disable-client-side-phishing-detection',
            '--disable-component-update',
            '--disable-default-apps',
            '--disable-dev-shm-usage',
            '--disable-domain-reliability',
            '--disable-extensions',
            '--disable-features=AudioServiceOutOfProcess',
            '--disable-hang-monitor',
            '--disable-ipc-flooding-protection',
            '--disable-notifications',
            '--disable-offer-store-unmasked-wallet-cards',
            '--disable-popup-blocking',
            '--disable-print-preview',
            '--disable-prompt-on-repost',
            '--disable-renderer-backgrounding',
            '--disable-speech-api',
            '--disable-sync',
            '--disable-gpu',
            '--disable-accelerated-2d-canvas',
            '--hide-scrollbars',
            '--ignore-gpu-blacklist',
            '--metrics-recording-only',
            '--mute-audio',
            '--no-default-browser-check',
            '--no-first-run',
            '--no-pings',
            '--no-zygote',
            '--password-store=basic',
            '--use-gl=swiftshader',
            '--use-mock-keychain',
            '--disable-setuid-sandbox',
            '--no-sandbox',
            '--disable-blink-features=AutomationControlled'
          ],
desert root
#

okay i'll test on it again...

desert root
#

Hello @meager lotus i have tried with the diffent parameter but that does not work but thank you for sharing i am glad for your help

desert root
meager lotus
#

Are you subscribing to the events before calling initialize()?
Please share the full code.

desert root
#

ya sure sharing the code

#

Create connection

const createClientConnection = () => {
        client[clientId] = new Client({
          puppeteer: {
            pipe: true,
            executablePath: chromePath,
            headless: false,
            args: [
              "--no-sandbox",
              "--disable-setuid-sandbox",
              "--disable-gpu",
              "--disable-dev-shm-usage"
            ]
          },
          session: clientId,
          authStrategy: new LocalAuth({
            clientId: clientId,
            dataPath: databasePath,
          }),
        });
        client[clientId].initialize();
      }

createClientConnection();

client[clientId].on("qr", async (generatedQR) => {});

client[clientId].on("loading_screen", async (state: any) => {});

client[clientId].on('authenticated', () => {});

client[clientId].on("ready", async (session: any) => {});

client[clientId].on("disconnected", (reason: any) => {})

#

but some times it will connect proper with the same client and i was testing and check that when the whatsapp web is synced and loaded all the chats in our script the client still initializing but at that time when i manually refresh whatsapp web page which is open during the initializing process then our script is gets proper events

meager lotus
#
const createClientConnection = () => {
        client[clientId] = new Client({
          puppeteer: {
            pipe: true,
            executablePath: chromePath,
            headless: false,
            args: [
              "--no-sandbox",
              "--disable-setuid-sandbox",
              "--disable-gpu",
              "--disable-dev-shm-usage"
            ]
          },
          session: clientId,
          authStrategy: new LocalAuth({
            clientId: clientId,
            dataPath: databasePath,
          }),
        });
       // client[clientId].initialize(); //NOT HERE
      }

createClientConnection();

client[clientId].on("qr", async (generatedQR) => {});

client[clientId].on("loading_screen", async (state: any) => {});

client[clientId].on('authenticated', () => {});

client[clientId].on("ready", async (session: any) => {});

client[clientId].on("disconnected", (reason: any) => {})

client[clientId].initialize();  //AFTER subscribe events

desert root
#

Hello @meager lotus bro Thank you for your response i am tried with this but it can't help it was worked sometimes and sometimes it not goes in loading_screen or ready event but thank you for your support....