pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
14.95k stars 3.55k forks source link

On 'ready' is not fired #2458

Closed TheMacros closed 8 months ago

TheMacros commented 12 months ago

Is there an existing issue for this?

Describe the bug

I'm trying to create a very basic app that handles incoming messages from WhatsApp.

The code generates a QR code successfully, but when I scan it with WhatsApp (link device) with an iOS or Android app nothing happens. The QR code is scanned successfully and the linked device (browser) appears on my mobile device. However, in the console, I didn't receive 'Client is ready!' message or any other message (like 'Client is authenticated!' or 'Client is auth_failure!') - absolutely nothing. When I disconnect the device I also don't receive the message 'Client is disconnected!'. Also, I have no exceptions.

Expected behavior

I'm expecting the on('ready') should fire when I scan the QR code and on('disconnected') should be fired when device is removed

Steps to Reproduce the Bug or Issue

There are no steps to reproduce.

Relevant Code

import waweb from "whatsapp-web.js";
import qrcode from 'qrcode-terminal';

const { Client, LocalAuth } = waweb;

const client = new Client({
    puppeteer: {
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox'
        ],
    }
});

client.on('qr', qr => {
    qrcode.generate(qr, {small: true});
});

client.on('ready', () => {
    console.log('Client is ready!');
});

client.on('disconnected', () => {
    console.log('Client is disconnected!');
});

client.on('authenticated', () => {
    console.log('Client is authenticated!');
});

client.on('auth_failure', () => {
    console.log('Client is auth_failure!');
});

client.initialize();

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Ubuntu Linux 18.04 Phone: iOS or Android whatsapp-web.js: 1.22.1 WhatsApp Web version: 2.2335.9 Node: 16.15.1

Additional context

I have another app (that uses whatsapp-web) running on the same server. It works fine.

TheMacros commented 12 months ago

Just tested the same script with the same version (1.22.1) on macOS - the same result. If I run it with puppeteer.headless = false on macOS - I see that the authorization process is working in Chromium (so in the Chromium browser I see my account authorized), but still nothing I can see in the script output.

I've also tried the 1.22.2-alpha.0 - this version works fine! So I'll stay on the alpha for now. But the question is how the 1.22.1 is working on my other project.

frnndwrms commented 12 months ago

same here with latest version

El mar, 29 ago 2023 a la(s) 13:21, TheMacros @.***) escribió:

Just tested the same script with the same version (1.22.1) on macOS - the same result. If I run it with puppeteer.headless = false on macOS - I see that the authorization process is working in Chromium (so in the Chromium browser I see my account authorized), but still nothing I can see in the script output.

I've also tried the 1.22.2-alpha.0 - this version works fine! So I'll stay on the alpha for now. But the question is how the 1.22.1 is working on my other project.

— Reply to this email directly, view it on GitHub https://github.com/pedroslopez/whatsapp-web.js/issues/2458#issuecomment-1697769556, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOQBBZJSBX6WN5YXQ3UP7DTXXYJJXANCNFSM6AAAAAA4DESGSE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Fernando Wermus.

Los contenidos de este mensaje, y los archivos adjuntos, son de carácter confidencial. Si ud. no es el legitimo destinatario de este mensaje, avise inmediatamente al remitente y borre este mensaje. Cualquier distribución o divulgación no autorizada de este mensaje y sus archivos asociados está prohibida. Por favor infórmenos inmediatamente y destruya el original o cualquier impresión del mismo.

Important Note: This e-mail (including any attachments) is confidential and intended only for the use of the addressee (s) named herein. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original e-mail and any printouts.

AndersonVale commented 12 months ago

same here. version 1.22.1

MatheusOliveira-dev commented 12 months ago

Did changing this file fix the problem for you? It worked for me: fix

MltrCyber commented 12 months ago

same here i think my vps is broken but not :v

neckell commented 12 months ago

same here. I tried on Linux (WSL) using docker and localhost, worked fine. But on production (azure) somehow it's not working 1.22.1 version. And it started happing just before updating from stable 1.21.0 version

YagoRosa commented 12 months ago

Same here on chrome.

MarlonRibeirodeMelo commented 12 months ago

I have the same problem, using ubuntu 18, it stopped working completely

rogerthedeveloper commented 12 months ago

Me too, the same behavior here, when expecting the ready event to be fired

neckell commented 12 months ago

1.22.2-alpha.0 works fine

yan043 commented 12 months ago

it's working for me in version 1.22.1 image

EpicJosch commented 12 months ago

same error

EpicJosch commented 12 months ago

Did changing this file fix the problem for you? It worked for me: fix

thanks man! this really fixes the issue!

dev-dfBueno commented 12 months ago

Alterar este arquivo resolveu o problema para você? Funcionou para mim: consertar

Pra mim não rolou não :'(

ItzFerr commented 12 months ago

same here, it solved when i changed to 1.22.2-alpha.0

dev-dfBueno commented 12 months ago

mesmo aqui, resolveu quando mudei para 1.22.2-alpha.0

Como que muda? Pode me ajudar?

EdnaldoTaurino commented 12 months ago

tbm quero saber como muda

max-programming commented 12 months ago

Did changing this file fix the problem for you? It worked for me: fix

Thanks! But I got this new error image

max-programming commented 12 months ago

Also @ItzFerr I got this error when switching to the alpha

image

thiagootero commented 12 months ago

Alterar este arquivo resolveu o problema para você? Funcionou para mim: consertar

Pra mim não rolou não :'(

Replace in src/Client.js

const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]';

to

const INTRO_IMG_SELECTOR = "[data-icon='chat']"

thiagootero commented 12 months ago

tbm quero saber como muda

Altere o arquivo package.json, alterando a versão do whatsapp web. Depois, rode o comando npm install

areumtecnologia commented 12 months ago

npm i whatsapp-web.js@1.22.2-alpha.0 --save

YagoRosa commented 11 months ago

Alterar este arquivo resolveu o problema para você? Funcionou para mim: consertar

Pra mim não rolou não :'(

Replace in src/Client.js

const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]';

to

const INTRO_IMG_SELECTOR = "[data-icon='chat']"

I updated to version whatsapp-web.js@1.22.2-alpha.0

I changed the code :

const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light ="true"], [data-asset-intro-image-dark="true"]';

for

const INTRO_IMG_SELECTOR = '[data-icon='chat']';

It still didn't work, and now the QR code doesn't even appear for me to scan with my cell phone.

does anyone have any suggestions?

I'll keep looking to see if I find a solution.

andresmv94 commented 11 months ago

Alterar este arquivo resolveu o problema para você? Funcionou para mim: consertar

Pra mim não rolou não :'(

Replace in src/Client.js const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]'; to const INTRO_IMG_SELECTOR = "[data-icon='chat']"

I updated to version whatsapp-web.js@1.22.2-alpha.0

I changed the code :

const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light ="true"], [data-asset-intro-image-dark="true"]';

for

const INTRO_IMG_SELECTOR = '[data-icon='chat']';

It still didn't work, and now the QR code doesn't even appear for me to scan with my cell phone.

does anyone have any suggestions?

I'll keep looking to see if I find a solution.

same here

YagoRosa commented 11 months ago

Alterar este arquivo resolveu o problema para você? Funcionou para mim: consertar

Pra mim não rolou não :'(

Replace in src/Client.js const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]'; to const INTRO_IMG_SELECTOR = "[data-icon='chat']"

I updated to version whatsapp-web.js@1.22.2-alpha.0

I changed the code :

const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light ="true"], [data-asset-intro-image-dark="true"]';

for

const INTRO_IMG_SELECTOR = '[data-icon='chat']';

It still didn't work, and now the QR code doesn't even appear for me to scan with my cell phone.

does anyone have any suggestions?

I'll keep looking to see if I find a solution.

Alright, in issue #2439 I found a comment from @joulgs about uninstalling whatsapp-web.js

npm unistall whatsapp-web.js -S

and then add it to the package.json file in the dependencies

"whatsapp-web.js": "https://github.com/Julzk/whatsapp-web.js/tarball/jkr_hotfix_8"

After changing just run the code

npm install

the client came back, it shows that whatsapp was connected but it gives an error

Error: Evaluation failed: Error: wid error: invalid wid

/workspaces/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221 throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));

does anyone have any suggestions?

I will keep looking for a solution.

YagoRosa commented 11 months ago

Alterar este arquivo resolveu o problema para você? Funcionou para mim: consertar

Pra mim não rolou não :'(

Replace in src/Client.js const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]'; to const INTRO_IMG_SELECTOR = "[data-icon='chat']"

I updated to version whatsapp-web.js@1.22.2-alpha.0 I changed the code : const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light ="true"], [data-asset-intro-image-dark="true"]'; for const INTRO_IMG_SELECTOR = '[data-icon='chat']'; It still didn't work, and now the QR code doesn't even appear for me to scan with my cell phone. does anyone have any suggestions? I'll keep looking to see if I find a solution.

Alright, in issue #2439 I found a comment from @joulgs about uninstalling whatsapp-web.js

npm unistall whatsapp-web.js -S

and then add it to the package.json file in the dependencies

"whatsapp-web.js": "https://github.com/Julzk/whatsapp-web.js/tarball/jkr_hotfix_8"

After changing just run the code

npm install

the client came back, it shows that whatsapp was connected but it gives an error

Error: Evaluation failed: Error: wid error: invalid wid

/workspaces/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221 throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));

does anyone have any suggestions?

I will keep looking for a solution.

I don't know what could have happened but apparently the authenticator was causing some conflict.

With me I used the following code for authentication :

const { Client, LocalAuth } = require('whatsapp-web.js'); const client = new Client({ authStrategy: new LocalAuth() });

I changed to :

const { Client } = require('whatsapp-web.js'); const client = new Client();

Now it's working perfectly, I don't know what could have caused the bug that was happening to me but when I removed the authenticator it started working normally again, all messages are being sent and the bot responds perfectly.

granaber commented 11 months ago

This soluction is change to version alpha, 1.22.1 Not working ! image

SonuSubhadip commented 11 months ago

1st npm uninstall whatsapp-web.js 2nd npm install whatsapp-web.js 3rd Goto > node_modules > whatsapp-web.js > src > client.js > Replace const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]'; With const INTRO_IMG_SELECTOR = "[data-icon='chat']"; Enjoy ❤️ 262662891-b952aeac-d75b-47f5-94a2-ee8317281b6b

dev-dfBueno commented 11 months ago

Alterar este arquivo resolveu o problema para você? Função para mim: devolver

Pra mim não rolou não :'(

Substitua em src/Client.js

const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light ="true"], [data-asset-intro-image-dark="true"]';

pára

const INTRO_IMG_SELECTOR = "[data-icon='chat']"

Aqui resolveu, alterei dessa forma e alterei também o package pra Alpha.. Obrigado!!

almacres10 commented 11 months ago

i still havent found the solution for this, i have try to change the script in Client.js and still the client ready doesnt show up. I have updated the package to whatsapp-web.js 1.22.2-alpha.0 and still doesnt worked. Any other solution?

almacres10 commented 11 months ago

i still havent found the solution for this, i have try to change the script in Client.js and still the client ready doesnt show up. I have updated the package to whatsapp-web.js 1.22.2-alpha.0 and still doesnt worked. Any other solution?

neckell commented 11 months ago

i still havent found the solution for this, i have try to change the script in Client.js and still the client ready doesnt show up. I have updated the package to whatsapp-web.js 1.22.2-alpha.0 and still doesnt worked. Any other solution?

You should either implement the fix the guys found out on this issue or wait for the release of a new patch version. For implementing the fix, you need to fork the repo and create a new one.

For instance, I will leave here my repo with the corresponding bugfix (working) in case any other want it until stable release come out: https://github.com/neckell/whatsapp-web.js This repo contains whatsapp-web.js@1.22.2-alpha.0 + the ready fix You can temporarily change your package json as follows:

"whatsapp-web.js": "github:neckell/whatsapp-web.js",

leodutra commented 11 months ago

This fix worked for me https://github.com/pedroslopez/whatsapp-web.js/pull/2485

burakerenel commented 11 months ago

This fix worked for me #2485

mine too

fpiantoni commented 11 months ago

The error is still happening, the new fix is: const INTRO_IMG_SELECTOR = '[data-icon='new-chat']';

On the Client.js file from the Package

neckell commented 11 months ago

@fpiantoni did you check on the repo i quoted? I am not quite sure about new-chat, i tested it and didn't work for me

fpiantoni commented 11 months ago

@neckell let me check it. I just found that in another reponse, tested it and worked. Let me pull your package and test it. I will keep you updated

neckell commented 11 months ago

I added a new state "Synced" that's fired when a syncronization between mobile phone and instance is complete. It's not official, it's up for my needs

LucasMonteiroi commented 10 months ago

image

This works for me, just updated the package version, this is my sample code:

const qrcode = require('qrcode-terminal');
const { Client, LocalAuth } = require('whatsapp-web.js');

const client = new Client({
  puppeteer: {
    args: ['--no-sandbox', '--disable-setuid-sandbox'],
  },
});

client.on('qr', (qr) => {
  qrcode.generate(qr, { small: true });
});

client.on('ready', () => {
  console.log('Client is ready!');
});

client.on('disconnected', () => {
  console.log('Client is disconnected!');
});

client.on('authenticated', () => {
  console.log('Client is authenticated!');
});

client.on('auth_failure', () => {
  console.log('Client is auth_failure!');
});

client.on('message', (msg) => {
  if (msg.body == '!ping') {
    msg.reply('pong');
  }
});

client.initialize();
learntheropes commented 8 months ago

@alechkos which is the commit of this fix?

alechkos commented 8 months ago

@learntheropes

npm i github:pedroslopez/whatsapp-web.js#main
learntheropes commented 8 months ago

@alechkos yes, but I can't find how this has been fixed on the repo.