I am trying to send text messages on whatsapp web version on chrome. (www.web.whatsapp.com)
This is the code:
As Khalid Lafi said, this is the correct script. His code does will return an error when executing
dispatch(document.querySelector("#compose-input div"), "textInput", "hello!");
This is because you should use "input.div" instead of "#compose-input div". The following script is working for me.
function dispatch(target, eventType, char) {
var evt = document.createEvent("TextEvent");
evt.initTextEvent (eventType, true, true, window, char, 0, "en-US");
target.focus();
target.dispatchEvent(evt);
}
dispatch(document.querySelector("div.input"), "textInput", "hello!");
function triggerClick() {
var event = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
document.querySelector(".icon.btn-icon.icon-send").dispatchEvent(event);
}
triggerClick();
Hope this helps.