wppconnect-team / wppconnect

WPPConnect is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination
https://wppconnect.io
Other
1.84k stars 319 forks source link

whatsapp stuck in Current state: SYNCING (OPENING) #2276

Open mszpr opened 1 month ago

mszpr commented 1 month ago

Description

Hello, When i launch new client, whatsapp crash and stop on status SYNCING (OPENING), then I had to delete token folder then everything return in good, then after one, two days this issue returned

Environment

Steps to Reproduce

  1. launch client
  2. whatsapp stuck in Current state: SYNCING (OPENING)
  3. delete token folder
  4. re-launch client
  5. after 1,2 days this issue returned.

Log Output

^[[32minfo^[[39m:     [113877:browser] Using browser folder '/var/www/tokens/113877'
^[[32minfo^[[39m:     [113877:browser] Initializing browser...
^[[32mhttp^[[39m:     [113877:browser] checking headless...
^[[32mhttp^[[39m:     [113877:browser] headless option is active, browser hidden
^[[32minfo^[[39m:     [113877:client] Initializing...
^[[36mverbose^[[39m:  [113877:client] Setting WhatsApp WEB version to 2.3000.10147x
^[[36mverbose^[[39m:  [113877:client] Loading WhatsApp WEB
^[[36mverbose^[[39m:  [113877:page] Page loaded
^[[36mverbose^[[39m:  [113877:client] Injecting wapi.js
^[[36mverbose^[[39m:  [113877:client] WhatsApp WEB loaded
[X] -----------  Client 113877 Has been created ----------- [X]
^[[36mverbose^[[39m:  [113877:client] wapi.js injected
^[[32minfo^[[39m:     [113877:client] WhatsApp WEB version: 2.3000.1014792822
^[[32minfo^[[39m:     [113877:client] WA-JS version: 3.6.0
[x] Client 113877 Status => [loading_screen]
^[[32mhttp^[[39m:     [113877:client] Current state: SYNCING (CONNECTING)
^[[32mhttp^[[39m:     [113877:client] Current state: SYNCING (OPENING)

Your Code

const getDirectories = async source =>
  (await readdir(source, { withFileTypes: true }))
    .filter(dirent => dirent.isDirectory())
    .map(dirent => dirent.name);

class Instance{

constructor(){
    this.restorePreviousSessions();
  }

createInstance(session_id){
 var options = {
        session: session_id,
        browserArgs: [
          '--disable-setuid-sandbox',
          '--no-sandbox',
          '--safebrowsing-disable-auto-update',
          '--disable-features=LeakyPeeker' // Disable the browser's sleep mode when idle, preventing the browser from going into sleep mode, this is useful for WhatsApp not to be in economy mode in the background, avoiding possible crashes
        ],
        puppeteerOptions: {
            userDataDir: `${__dirname}/tokens/${session_id}`,
            args: ['--no-sandbox','--disable-setuid-sandbox'],
            executablePath: process.env.ENV == 'local' ? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' : '/usr/bin/google-chrome',
        },
        disableWelcome:true,
        headless:true,
        onLoadingScreen: (percent, message) => { onLoadingScreen (percent, message)},
        catchQR: (base64Qr, asciiQR, attempt, urlCode) => { onQrCode(base64Qr, asciiQR, attempt, urlCode) },
        statusFind: (statusFind) => { onStatus(statusFind) },
        catchLinkCode: (code) => { onLoginCode(code) },
        logQR:false,
      }

 client = await wppconnect.create(options);
}
}

  async restorePreviousSessions() {

    const directoryNames = await getDirectories(
      __dirname+"/tokens"
    );

    const sessionIds = directoryNames.map(name => name);

    sessionIds.forEach((sessionId,index) => {

      setTimeout(() => {
        console.log(`initialize session id => ${sessionId}`);
        this.createInstance(sessionId);
      }, process.env.RUNTIMEOUT || 20000 * (index + 1));

    });

  }

Additional context / Screenshot

when i set headless:false, the whatsapp web page says that i don't have internet connection, even i have 2024-07-17 19 23 51

Saifallak commented 1 month ago

related https://github.com/wppconnect-team/wppconnect-server/issues/1486 but closed as not-planned.

mszpr commented 1 month ago

@Saifallak i face this issue with some sessions not all, this is weird ! I've tried to debug it with no results. I hope someone find the solution

Saifallak commented 1 month ago

@Saifallak i face this issue with some sessions not all, this is weird ! I've tried to debug it with no results. I hope someone find the solution

Only solution is to delete it, but its hard to identify because it says connected is session status endpoint

tls-jil commented 1 month ago

also i face same issue

Group 79 (1)

devactivity-app[bot] commented 1 month ago

@tls-jil, ⭐3 XP earned, 🏆First Comment Added completed, 💪Level 1 achieved! Contribute more to raise your XP/Level, complete challenges for extra achievements! [Sign up for personal dashboard]

icon
Saifallak commented 4 weeks ago

Any solution so far?

icleitoncosta commented 1 week ago

Hi, the error yet ocurrs with you? I fixed it in previous versions

Saifallak commented 1 week ago

Hi, the error yet ocurrs with you? I fixed it in previous versions

Last time happened 2 weeks ago for me, Not sure if disappeared because of update, because it literally happens randomly, But curious 🤔 which update you did fixed it?.

Any way I'll monitor session for next week and give you feedback

icleitoncosta commented 1 week ago

The updates that were made to improve this, but it has been over 3 weeks since then, that's how I upgraded to version 2.3000, and mainly it's necessary to always keep the WhatsApp version updated or just update the project, which will automatically keep up.

Saifallak commented 1 week ago

The updates that were made to improve this, but it has been over 3 weeks since then, that's how I upgraded to version 2.3000, and mainly it's necessary to always keep the WhatsApp version updated or just update the project, which will automatically keep up.

Yes, usually i stop all sessions and 'git pull' rebuild every two weeks., anyway I'll test and get feedback here