Skip to content

Instantly share code, notes, and snippets.

@sayhicoelho
Last active January 5, 2025 10:31
Show Gist options
  • Save sayhicoelho/04b7fa3289e3265c03f58849c914081c to your computer and use it in GitHub Desktop.
Save sayhicoelho/04b7fa3289e3265c03f58849c914081c to your computer and use it in GitHub Desktop.
Send messages to WhatsApp (web version only) programmatically.
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)
}
@sayhicoelho
Copy link
Author

Thanks @semihkeskindev ! I just fixed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment