N
N
Nadim Zakirov2020-09-18 13:50:50
JavaScript
Nadim Zakirov, 2020-09-18 13:50:50

How to simulate typing a message in WhatsApp Web?

Simply entering a message and sending it to the user is no problem:

document.querySelector('div#main div[contenteditable="true"]').innerHTML = 'Проверка...';
document.querySelector('div#main div[contenteditable="true"]').dispatchEvent(new Event('input', { bubbles: true }));
document.querySelector('span[data-icon="send"]').click();

However, how do I get the input event to fire? So that the interlocutor sees the inscription prints ... ?

5f6490bb583d6403635817.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2020-09-18
@zkrvndm

Add delays between keystrokes. Now it looks like it is instantly pressed.
Average words per minute = 40, which is about 200 characters. 60 / 200 = 0.3 seconds per button.
Try 0.2-0.3 second delay between events. Also, the list of events for pressing a key should be like this:
- keydown
- keypress
- input
- keyup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question