I am trying to send text- messages on WhatsApp with javascript?

后端 未结 8 789
粉色の甜心
粉色の甜心 2020-12-30 16:54

I am trying to send text messages on whatsapp web version on chrome. (www.web.whatsapp.com)

This is the code:

8条回答
  •  轮回少年
    2020-12-30 17:30

    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.

提交回复
热议问题