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.9k stars 335 forks source link

Error: Failed to launch the browser process! undefined #2341

Open phillipnunes opened 1 month ago

phillipnunes commented 1 month ago

Description

Ao tentar criar duas ou mais sessões usando a biblioteca, acontece o erro postado mais abaixo. A primeirão é criada normalmente, mas ao chamar a mesma API mais de uma vez o erro ocorre. Por algum motivo ele tenta abrir as sessões posteriores usando um nome antigo de sessão (que já existe na pasta tokens).

Note no log abaixo que o nome da sessão printado no terminal (b96f6ea5-8151-48bb-91b2-d13020f3b7f6) não corresponde ao do caminho que ele tentou criar (Failed to create /home/phillip/Documents/Repositories/teste/api/tokens/cc548742-baf3-426e-a9f9-9c06a80feebf/...)

Mesmo passando o parametro folderNameToken explicitamente, o erro acontece.

O estranho é que quando passo essa prop abaixo no create (puppeteerOptions), ai funciona. O puppeteerOptions é obrigatório? Porque preciso passar ele pra dar certo?

puppeteerOptions: {
  userDataDir: `./tokens/${sessionName}`,
},

Environment

Log Output

sessionName b96f6ea5-8151-48bb-91b2-d13020f3b7f6
info:     [b96f6ea5-8151-48bb-91b2-d13020f3b7f6:browser] Using browser folder '/home/phillip/Documents/Repositories/teste/api/tokens/cc548742-baf3-426e-a9f9-9c06a80feebf/cc548742-baf3-426e-a9f9-9c06a80feebf'
info:     [b96f6ea5-8151-48bb-91b2-d13020f3b7f6:browser] Initializing browser...
error:    [b96f6ea5-8151-48bb-91b2-d13020f3b7f6:browser] Error no open browser
error:    [b96f6ea5-8151-48bb-91b2-d13020f3b7f6:browser] Failed to launch the browser process! undefined
[23463:23463:0911/214426.374148:ERROR:process_singleton_posix.cc(335)] Failed to create /home/phillip/Documents/Repositories/teste/api/tokens/cc548742-baf3-426e-a9f9-9c06a80feebf/cc548742-baf3-426e-a9f9-9c06a80feebf/SingletonLock: File exists (17)
[23463:23463:0911/214426.374374:ERROR:chrome_main_delegate.cc(594)] 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: Failed to launch the browser process! undefined
[23463:23463:0911/214426.374148:ERROR:process_singleton_posix.cc(335)] Failed to create /home/phillip/Documents/Repositories/teste/api/tokens/cc548742-baf3-426e-a9f9-9c06a80feebf/cc548742-baf3-426e-a9f9-9c06a80feebf/SingletonLock: File exists (17)
[23463:23463:0911/214426.374374:ERROR:chrome_main_delegate.cc(594)] 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 (/home/phillip/Documents/Repositories/teste/api/node_modules/@puppeteer/browsers/src/launch.ts:486:11)
    at ChildProcess.emit (node:events:531:35)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)

Your Code

export class WhatsappService {
  constructor() {}

  async createSession(data: CreateSession, res: Response) {
    const sessionName = uuidv4();
    console.log('sessionName', sessionName);
    try {
      const client = await create({
        session: sessionName,
        debug: true,
        folderNameToken: `./tokens/${sessionName}`,
        // puppeteerOptions: {
        //   userDataDir: `./tokens/${sessionName}`,
        // },
        catchQR: (base64Qr) => {
          if (res && !res.headersSent) {
            res.status(200).json({
              status: 'QRCODE',
              imageBase64: base64Qr,
            });
          }
        },
        logQR: false,
      });

      this.start(client);
    } catch (error) {
      console.log(error);
    }
  }

  start(client) {
    client.onMessage((message) => {
      if (message.body === 'Hi' && message.isGroupMsg === false) {
        client
          .sendText(message.from, 'Welcome to Wppconnect')
          .then((result) => console.log('Result', result))
          .catch((error) => {
            console.error('Error when sending: ', error); //return error object
          });
      }
    });
  }
}
Saifallak commented 1 month ago

Delete SingletonLock file