I'm trying to send a message on Whatsapp Web (https://web.whatsapp.com/) only using Javascript, for study purposes.
Here is the DIV that has the message box :
<div class="fd365im1 to2l77zo bbv8nyr4 mwp4sxku gfz4du6o ag5g9lrv" contenteditable="true" role="textbox" spellcheck="true" title="Type a message" data-tab="10" data-lexical-editor="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;"><p class="selectable-text copyable-text"><br></p></div>
And here is my code :
document.getElementsByClassName('fd365im1 to2l77zo bbv8nyr4 mwp4sxku gfz4du6o ag5g9lrv')[0].innerText = 'My message content';
The code runs without errors, but the message field is not filled, nothing happens on the interface. This code used to run before, but not anymore.
What am i missing ? You can try your self accessing the whatsapp web and using Chrome devtools.
you can use
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("yourText")