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.86k stars 328 forks source link

Failed to launch the browser process! undefined #2259

Closed mszpr closed 2 months ago

mszpr commented 2 months ago

Description

Hi there!, When i want to run multi instances on wppconnect this message appeared to me:

info: [10000000004:browser] Using browser folder '/Users/mahmoud/Desktop/Projects/whatsapp/wa-instance-wppconnect/tokens/10000000004' info: [10000000004:browser] Initializing browser... error: [10000000003:browser] Error no open browser error: [10000000003:browser] Failed to launch the browser process! undefined [98249:259:0712/030811.557031:ERROR:process_singleton_posix.cc(335)] Failed to create /Users/mahmoud/Desktop/Projects/whatsapp/wa-instance-wppconnect/tokens/10000000003/SingletonLock: File exists (17) [98249:259:0712/030811.557323:ERROR:chrome_main_delegate.cc(592)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.

TROUBLESHOOTING: https://pptr.dev/troubleshooting

Environment

Log Output

error:    [10000000003:browser] Error no open browser
error:    [10000000003:browser] Failed to launch the browser process! undefined
[98249:259:0712/030811.557031:ERROR:process_singleton_posix.cc(335)] Failed to create /Users/mahmoud/Desktop/Projects/whatsapp/wa-instance-wppconnect/tokens/10000000003/SingletonLock: File exists (17)
[98249:259:0712/030811.557323:ERROR:chrome_main_delegate.cc(592)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.

TROUBLESHOOTING: https://pptr.dev/troubleshooting

error:    Unhandled Rejection: Error: Failed to launch the browser process! undefined
[98249:259:0712/030811.557031:ERROR:process_singleton_posix.cc(335)] Failed to create /Users/mahmoud/Desktop/Projects/whatsapp/wa-instance-wppconnect/tokens/10000000003/SingletonLock: File exists (17)
[98249:259:0712/030811.557323:ERROR:chrome_main_delegate.cc(592)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.

TROUBLESHOOTING: https://pptr.dev/troubleshooting

    at ChildProcess.onClose (/Users/mahmoud/Desktop/Projects/whatsapp/wa-instance-wppconnect/node_modules/@puppeteer/browsers/lib/cjs/launch.js:310:24)
    at ChildProcess.emit (node:events:526:35)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)

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));

    });

  }

This issue happen when i restore all instances after restart supervisor using restorePreviousSessions() method

thanks in advance.

devactivity-app[bot] commented 2 months ago

@mszpr, ⭐3 XP earned, 🏆First Issue Created completed! Contribute more to raise your XP/Level, complete challenges for extra achievements! [Sign up for personal dashboard]

icon
mszpr commented 2 months ago

i found the issue, the issue was when i close the node js by my self or by any exception , Google Chrome page not closing and still working in background.

so the solution was to set listener to listen if node about to close, close all pages then continue closing the node app.

exmaple:

var softCloseAll = false;
process.stdin.resume();
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `SIGTERM`].forEach((eventType) => {

  if(!softCloseAll){
    process.on(eventType, (e) => {
      softCloseAll = true;
      ws.softCloseAll().then(() => {
        console.log("All clients has been closed!");
          process.exit();
      });
    });
  }

});
devactivity-app[bot] commented 2 months ago

@mszpr, ⭐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
devactivity-app[bot] commented 2 months ago

@mszpr, ⭐3 XP earned, 🏆First Issue Closed completed, 💪Level 1 achieved! Contribute more to raise your XP/Level, complete challenges for extra achievements! [Sign up for personal dashboard]

icon
Saifallak commented 2 months ago

i found the issue, the issue was when i close the node js by my self or by any exception , Google Chrome page not closing and still working in background.

so the solution was to set listener to listen if node about to close, close all pages then continue closing the node app.

exmaple:

var softCloseAll = false;
process.stdin.resume();
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `SIGTERM`].forEach((eventType) => {

  if(!softCloseAll){
    process.on(eventType, (e) => {
      softCloseAll = true;
      ws.softCloseAll().then(() => {
        console.log("All clients has been closed!");
          process.exit();
      });
    });
  }

});

Getting the same even for new sessions ..

devactivity-app[bot] commented 2 months ago

@Saifallak, ⭐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