Last active
January 5, 2025 10:31
-
-
Save sayhicoelho/04b7fa3289e3265c03f58849c914081c to your computer and use it in GitHub Desktop.
Send messages to WhatsApp (web version only) programmatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendMessage(message){ | |
const mainEl = document.querySelector('#main') | |
const textareaEl = mainEl.querySelector('div[contenteditable="true"]') | |
if(!textareaEl) { | |
throw new Error('There is no opened conversation') | |
} | |
textareaEl.focus() | |
document.execCommand('insertText', false, message) | |
textareaEl.dispatchEvent(new Event('change', { bubbles: true })) | |
setTimeout(() => { | |
(mainEl.querySelector('[data-testid="send"]') || mainEl.querySelector('[data-icon="send"]')).click() | |
}, 100) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there are unique values in the function ("div._3u328" and "button._3M-N-"). Whoever wanna use the function, has to update that. I did and I also upgraded that as an independent function from sessions