rohitsangwan01 / whatsapp_bot_flutter

Whatsapp bot for flutter desktop
MIT License
41 stars 27 forks source link

Failed to initialize WPP #32

Closed patricknicolosi closed 1 year ago

patricknicolosi commented 1 year ago
Screenshot 2023-06-26 alle 00 30 25
rohitsangwan01 commented 1 year ago

are you getting this on Web ? have you tried multiple times and getting this issue every time ?

patricknicolosi commented 1 year ago

I'm getting this on web https://rohitsangwan01.github.io/whatsapp_bot_flutter every time

rohitsangwan01 commented 1 year ago

@patricknicolosi can you try to connect with local puppeteer instance like this

arytbk commented 1 year ago

Suddenly I get this exact same exception in Headlesss mode. With headless = false it works fine. I am not on Web, I am running it on MacOS. I tried to delete and clean everything (including local Chromium and data folder) - does not help. I also tried to use Puppeteer 3.1.1 instead of 3.1.0 - same.

What I get:

Exception has occurred.
WhatsappException ([ WhatsappException  type : WhatsappExceptionType.failedToConnect , message : Failed to initialize WPP ])
rohitsangwan01 commented 1 year ago

@arytbk in Macos are you trying to connect with a url ( like web ) by running puppeteer separately , or running with normal connect method ?

arytbk commented 1 year ago

Normal connection method…On 28 Jun 2023, at 11:28, Rohit Sangwan @.***> wrote: @arytbk in Macos are you trying to connect with a url ( like web ) by running puppeteer separately , or running with normal connect method ?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

arytbk commented 1 year ago

I am using the normal Connect method

rohitsangwan01 commented 1 year ago

working fine for me , i just tried running the example app as it is , and its working fine in macos can you check with example app ?

rohitsangwan01 commented 1 year ago

@patricknicolosi seems like this issue is only with Browserless, i tried the Docker image of Browserless and its working fine, probably they changed something in their live version , javascript is not injecting into it

arytbk commented 1 year ago

The example app does not work on my (platform:macOS, arch:arm64) MacOS. It crashes after closing the QR Code dialog as shown in this screenshot:

SCR-20230628-oksl
arytbk commented 1 year ago

My app worked fine in headless mode but suddenly today I get this "Failed to initialize WPP" exception. Here is a screenshot to show exactly when that happens:

SCR-20230628-ommp
rohitsangwan01 commented 1 year ago

@arytbk try to clean the session directory and try again , sometimes session directory created in headless mode cause issue in non headless mode or vice versa or for testing , try without session directory

arytbk commented 1 year ago

Ok I have more details. I removed the session directory and I launched my app. It asked me for the QR code and everything was fine. Then I closed Chromium (using the browser callback I get from connect) and quit my app. When I launch it again I get the exact same error. I'll try without closing Chromium but with my initial tests it created other issues...

arytbk commented 1 year ago

If I don't close Chromium before quitting my app, next time I try to launch it and connect, I get an exception "Login Failed" after a long time in the state "ConnectionEvent.waitingForQrScan" (although WhatsApp was already properly connected the last time).

arytbk commented 1 year ago

So maybe I am just missing the proper way to quit my app and leave Chromium etc in a clean state?

rohitsangwan01 commented 1 year ago

@arytbk there is some bug with the headless mode switch and session directory

session directory for now only works with headlessMode: false

if we use session directory in headless mode then getting some issues when we try to run next time

also if session directory created in headless mode , that will not work with non headless mode either

so yeah these things are yet to debug, these issues are related to puppeteer

arytbk commented 1 year ago

I see! So currently the only way to maintain a session directory (to avoid having to reconnect WhatsApp with QR code at every launch of the app) is to use headless = false... Now I'll try to find a way to hide the Chromium app...

rohitsangwan01 commented 1 year ago

@arytbk well yes atleast for now

arytbk commented 1 year ago

I found a workaround for now, by forcing Puppeteer version to 3.1.0 ("puppeteer: 3.1.0"). Now it works again in headless mode with a session directory to keep WhatsApp logged-in between launches of my app!

rohitsangwan01 commented 1 year ago

@arytbk i think the issue is , when we run puppeteer in headless mode, and stop our program, that headless browser keep running in background ( check in Activity monitor ), and next time we try to run again it causes an issue because that cache is still connected to that old instance , Try to manually close that headless browser instance running in background, and run program again to see if its working fine now, if yes then its puppeteer dart issue

arytbk commented 1 year ago

I was already closing the hidden Chromium browser (I got the browser instance from the callback in connect, then before quitting the app I user browser.close()

rohitsangwan01 commented 1 year ago

if we close the browser , then it should work fine, atleast in my testing

Katekko commented 1 year ago

I was already closing the hidden Chromium browser (I got the browser instance from the callback in connect, then before quitting the app I user browser.close()

What is this callback (before quitting)? Im using pure dart and having some problem to check if the program is finishing

And, how are you getting the browser instance to close it?

arytbk commented 1 year ago
Katekko commented 1 year ago
  • I just added a QUIT button in my app
  • to get the browser instance, there is a callback on the connect method, like this:
onBrowserCreated: (Browser? browser) {
          _browser = browser;

Sad for me, cause Im doing console application with pure dart, without button. So idk how can I close the browser

arytbk commented 1 year ago

If you just want to close the browser use the close() method on the browser instance you got from the callback

rohitsangwan01 commented 1 year ago

Sad for me, cause Im doing console application with pure dart, without button. So idk how can I close the browser

You can try a workaround Save browsers pid locally, and when you run the program again Just call first 'Process.kill(pid)' This will make sure that only single browser instance will be live when working Or if you want to run the process with hot reload Then save browsers wsEndpoint url locally And pass that parameter in connect method So this will first run the browser And second time on hot restart connect with browser using wsUrl If you saved this url locally on first connect

To save locally you can use any library like hive or something

This will not solve the exact issue, which is actually from puppeteer, it's not closing the chrome on stopping program So you can try these workarounds, atleast this will save you from running multiple chrome instances on each launch And also I noticed that auth works fine in headless mode if we make sure only single chrome instance is running I will try to update example with these changes

loic-hamdi commented 1 year ago

Sad for me, cause Im doing console application with pure dart, without button. So idk how can I close the browser

You can try a workaround Save browsers pid locally, and when you run the program again Just call first 'Process.kill(pid)' This will make sure that only single browser instance will be live when working Or if you want to run the process with hot reload Then save browsers wsEndpoint url locally And pass that parameter in connect method So this will first run the browser And second time on hot restart connect with browser using wsUrl If you saved this url locally on first connect

To save locally you can use any library like hive or something

This will not solve the exact issue, which is actually from puppeteer, it's not closing the chrome on stopping program So you can try these workarounds, atleast this will save you from running multiple chrome instances on each launch And also I noticed that auth works fine in headless mode if we make sure only single chrome instance is running I will try to update example with these changes

Getting the same error too. Really a struggle to even being able to reconnect after Error: [ WhatsappException type : WhatsappExceptionType.failedToConnect , message : Failed to initialize WPP ] shows up..!

rohitsangwan01 commented 1 year ago

Getting the same error too.

Really a struggle to even being able to reconnect after Error: [ WhatsappException type : WhatsappExceptionType.failedToConnect , message : Failed to initialize WPP ] shows up..!

On which platform you are trying ? Is it Flutter web, Desktop or pure dart project ?

loic-hamdi commented 1 year ago

Getting the same error too. Really a struggle to even being able to reconnect after Error: [ WhatsappException type : WhatsappExceptionType.failedToConnect , message : Failed to initialize WPP ] shows up..!

On which platform you are trying ? Is it Flutter web, Desktop or pure dart project ?

Pure dart in console

loic-hamdi commented 1 year ago

Impossible to reconnect to the account, after I try to scan the QR code it waits for 1 min and then always give the error:

[...]
ConnectionEvent.authenticated
ConnectionEvent.connecting
Error: Phone not connected
ERROR - 2023-07-06 15:26:24.973291
Asynchronous error
Phone not connected
rohitsangwan01 commented 1 year ago

Impossible to reconnect to the account, after I try to scan the QR code it waits for 1 min and then always give the error:

[...]
ConnectionEvent.authenticated
ConnectionEvent.connecting
Error: Phone not connected
ERROR - 2023-07-06 15:26:24.973291
Asynchronous error
Phone not connected

You can try to run without headless mode to see whats going on in browser Seems like whatsappWeb not connecting with the phone

golontico commented 1 year ago
  • I just added a QUIT button in my app
  • to get the browser instance, there is a callback on the connect method, like this:
onBrowserCreated: (Browser? browser) {
          _browser = browser;

Hello @arytbk how to implement this.... i need close the instance to avoid to do a new request QR

arytbk commented 1 year ago

Like this:static Future terminate() async { print('Terminating WhatsApp'); if (WhatsAppSender.isConnected()) { await _browser?.close(); } print('WhatsApp Terminated'); }On 20 Nov 2023, at 10:41, Jasson Faerron @.***> wrote:

I just added a QUIT button in my app to get the browser instance, there is a callback on the connect method, like this:

onBrowserCreated: (Browser? browser) { _browser = browser;

Hello @arytbk how to implement this.... i need close the instance to avoid to do a new request QR

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

selvam920 commented 7 months ago

same issue occuring in windows now, unable to connect a one time