MobCode100 / whatsapp-web.js

whatsapp-web.js + link with phone number. See https://t.ly/KWR4p.
https://wwebjs.dev
Apache License 2.0
2 stars 4 forks source link

Can't receive generated code #1

Closed pfnh26 closed 4 months ago

pfnh26 commented 4 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

After an update, LinkingMethod.js never worked again the code I'm using is: npm install https://github.com/MobCode100/whatsapp-web.js.git

const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
    {
        linkingMethod:  new LinkingMethod({
            phone: {
                number: "<+556292286543>"
            }
        }),
        puppeteer: {
            args: ['--no-sandbox'],
        },
    }
);
client.on('code', (code) => {
    console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
    console.log('Client is ready!');
});
client.initialize();

Describe the solution you'd like.

I would like you to solve the error while maintaining the same code structure

Describe an alternate solution.

No response

Additional context

No response

MobCode100 commented 4 months ago

Hi, I see that the phone number has the '<' '>'. You should remove these characters, they're meant to be a placeholder when I'm giving an example code.

pfnh26 commented 4 months ago

Hi, I see that the phone number has the '<' '>'. You should remove these characters, they're meant to be a placeholder when I'm giving an example code.

Yes, I already removed '<' '>' but the code is still not generated even for the number +556292286543 nor the number +5562992286543 (including the addition of the extra number 9 that exists in my country) I updated the library, but even so the code doesn't even give an error, and it doesn't generate the code numbers. Is there a log that I should put to locate the error?

MobCode100 commented 4 months ago

Yes, I already removed '<' '>' but the code is still not generated even for the number +556292286543 nor the number +5562992286543 (including the addition of the extra number 9 that exists in my country) I updated the library, but even so the code doesn't even give an error, and it doesn't generate the code numbers. Is there a log that I should put to locate the error?

I'm away from my pc now, but could you add configuration headless: false under puppeteer ? And see which part it stuck.

pfnh26 commented 4 months ago

I'm away from my pc now, but could you add configuration headless: false under puppeteer ? And see which part it stuck.

this error is reported, and actually in the puppeteer window it just opens whatsapp-web but does not select anything

`C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\Connection.js:329 error: new Errors_js_1.ProtocolError(), ^

ProtocolError: Waiting for selector .//span[text() = "Link with phone number"] failed: Protocol error (Runtime.callFunctionOn): Destination closed. in C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\Connection.js:329:24 in the new promise () in CDPSessionImpl.send (C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\Connection.js:325:16) in ExecutionContext._ExecutionContext_evaluate (C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ExecutionContext.js:211:46) in process.processTicksAndRejections(node:internal/process/task_queues:95:5) in async JSHandle.evaluateHandle (C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\JSHandle.js:97:16) in async WaitTask.rerun (C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\WaitTask.js:114:28) in async Promise.all (index 1) in async TaskManager.rerunAll (C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\WaitTask.js:197:9) { original message: '' }`

Rasket commented 4 months ago

All work very well:

npm uninstall whatsapp-web.js
npm install https://github.com/MobCode100/whatsapp-web.js.git
const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
{
linkingMethod: new LinkingMethod({
phone: {
    number: "+447721734626"
}
}),
puppeteer: {
args: ['--no-sandbox'],
headless: false
},
}
);
client.on('code', (code) => {
console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();

Works well even with headless: true. But sometimes get this error (no matter of headless value):


            throw new Error('Node is either not clickable or not an HTMLElement');
                  ^

Error: Node is either not clickable or not an HTMLElemen

I think it cause of too fast page loading.

pfnh26 commented 4 months ago

All work very well:

npm uninstall whatsapp-web.js
npm install https://github.com/MobCode100/whatsapp-web.js.git
const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
{
linkingMethod: new LinkingMethod({
phone: {
    number: "+447721734626"
}
}),
puppeteer: {
args: ['--no-sandbox'],
headless: false
},
}
);
client.on('code', (code) => {
console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();

I think it cause of too fast page loading.

I must have something wrong with my PC, I tried countless times and the code is not passed, and in the puppeteer window, it just stays on the QRcode authentication screen

MobCode100 commented 4 months ago

I think it cause of too fast page loading

I think so too, but it's hard for me to reproduce the error consistently. I'll look for it later, thanks for the logs & the error messages 👍🏻.

MobCode100 commented 4 months ago

I must have something wrong with my PC, I tried countless times and the code is not passed, and in the puppeteer window, it just stays on the QRcode authentication screen

I think your problem is related to the error above. I'll try to take a look, must be a problem with the selector.

Rasket commented 4 months ago

All work very well:

npm uninstall whatsapp-web.js
npm install https://github.com/MobCode100/whatsapp-web.js.git
const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
{
linkingMethod: new LinkingMethod({
phone: {
    number: "+447721734626"
}
}),
puppeteer: {
args: ['--no-sandbox'],
headless: false
},
}
);
client.on('code', (code) => {
console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();

I think it cause of too fast page loading.

I must have something wrong with my PC, I tried countless times and the code is not passed, and in the puppeteer window, it just stays on the QRcode authentication screen

Additional info about env: node: v21.6.1 npm: 10.2.4 And this might seem strange, but you might try creating it in a new folder, because sometimes it crashes (wwebjs) even if I don't change anything, but if I copy it to a new folder, everything works fine.

MobCode100 commented 4 months ago

Hi @Rasket, I think the problem 'Node is either not clickable or not an HTMLElement' should have been fixed with the new update. The problem is because the link with phone button was clicked too fast, so I added a delay to prevent that.

@pfnh26 Hopefully your problem was fixed with the new update.

Just npm update or reinstall, and can you guys please retry that again?

pfnh26 commented 4 months ago

Hi @Rasket, I think the problem 'Node is either not clickable or not an HTMLElement' should have been fixed with the new update. The problem is because the link with phone button was clicked too fast, so I added a delay to prevent that.

@pfnh26 Hopefully your problem was fixed with the new update.

Just npm update or reinstall, and can you guys please retry that again?

Still nothing happens in the puppeteer window, not generating the code, in this case the option to generate the code by number is not clicked.

I updated via npm, reinstalled but it didn't work

MobCode100 commented 4 months ago

I updated via npm, reinstalled but it didn't work

Is the WhatsApp web not in English? Can you inspect element the button and show me the html code?

pfnh26 commented 4 months ago

I updated via npm, reinstalled but it didn't work

Is the WhatsApp web not in English? Can you inspect element the button and show me the html code?

Sorry for the delay, I believe this is why, would there be any way to force the page to open in English?

<div class="_2rQUO" style="transform: scale(1); opacity: 1;"><span role="button" tabindex="0" class="_3iLTh">Conectar com número de telefone</span></div>

MobCode100 commented 4 months ago

Sorry late, I didn't expect another language other than English. I even used VPN to test that but the page stays in English. Turns out it's because of cookies. Sorry, my bad 😅.

I've done a little programming on my phone and have made some changes to support multiple languages but I can't test them now as I'm away from my PC.

Can you try and see if it'll work now?

pfnh26 commented 4 months ago

Sorry late, I didn't expect another language other than English. I even used VPN to test that but the page stays in English. Turns out it's because of cookies.

I've done a little programming on my phone and have made some changes to support multiple languages but I can't test them now as I'm away from my PC.

Can you try and see if it'll work now?

the button was clicked, but the code was not generated due to this error: `C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ElementHandle.js:781 throw new error (error); ^

Error: node is not of type HTMLElement in ElementHandle._ElementHandle_scrollIntoViewIfNeeded (C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ElementHandle.js:781:15) in process.processTicksAndRejections(node:internal/process/task_queues:95:5) in async ElementHandle.click (C:\Users\Phelipe\node_modules\whatsapp-web.js\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ElementHandle.js:444:9) in async handleLinkWithPhoneNumber (C:\Users\Phelipe\node_modules\whatsapp-web.js\src\Client.js:338:17) in async Client.initialize (C:\Users\Phelipe\node_modules\whatsapp-web.js\src\Client.js:423:17)

Node.js v18.17.0`

If there was some way to force the link to open in English, it wouldn't be a problem, it would make the code easier

MobCode100 commented 4 months ago

but the code was not generated due to this error:

Fixed, try again. Sorry for the trouble I've caused.

If there was some way to force the link to open in English, it wouldn't be a problem, it would make the code easier

Not in the documentation as far as I can see. Plus, require more code to modify cookies for every page refresh.

pfnh26 commented 4 months ago

but the code was not generated due to this error:

Fixed, try again. Sorry for the trouble I've caused.

Thank you very much, it worked perfectly, I hope to complete my project as quickly as possible so that I can learn and help update your repository. But for now, thank you very much!!

MobCode100 commented 4 months ago

Thank you very much, it worked perfectly, I hope to complete my project as quickly as possible so that I can learn and help update your repository. But for now, thank you very much!!

Thank you so much too! For reporting the problem. Now, this feature can be used by non-English countries which greatly improve this library. I wish you luck for your endeavors.

I will close this issue, feel free to open it back if the problem recurs. Who knows when will WhatsApp Web change its code.