user296862
user296862

Reputation: 31

Send text messages on WhatsApp Web?

I want to be able to capture a text from my chrome extension and have it automatically go to whatsapp web text box.

Until a month ago I was able to send a message using the following code:

 var input = document.querySelector('[contenteditable~=true]');
        input.innerHTML = message;
        input.dispatchEvent(new Event('input', { bubbles: true }));

Upvotes: 1

Views: 2605

Answers (1)

ammar alkotb
ammar alkotb

Reputation: 334

use this:

function send_text(text) {
const dataTransfer = new DataTransfer();
dataTransfer.setData('text', text);
const event = new ClipboardEvent('paste', {
      clipboardData: dataTransfer,
      bubbles: true
    });
let el = document.querySelector('#main .copyable-area [contenteditable="true"][role="textbox"]')
el.dispatchEvent(event)
}
send_text(your_text)

Or

See Enter data into a custom-handled input field

Upvotes: 3

Related Questions