Skip to content

Instantly share code, notes, and snippets.

@EyMaddis
Created November 4, 2016 12:50
Show Gist options
  • Save EyMaddis/379f50e0780b368d2f4487169e970888 to your computer and use it in GitHub Desktop.
Save EyMaddis/379f50e0780b368d2f4487169e970888 to your computer and use it in GitHub Desktop.
Sending messages programmatically on web.whatsapp.com
// this allows to send arbitrary messages. The chat conversation you want to send messages to has to be open.
// just run this in the JS console
// http://stackoverflow.com/a/39165137/1249001
function findReactComponent(dom) {
for (var key in dom)
if (key.startsWith("__reactInternalInstance$")) {
var compInternals = dom[key]._currentElement;
var compWrapper = compInternals._owner;
var comp = compWrapper._instance;
return comp;
}
return null;
};
var inputComponent = findReactComponent(document.getElementsByClassName('block-compose')[0]); // get the react component for the chat input
var chat = inputComponent.props.chat;
chat.sendMessage('this is a hacky message')
Copy link

ghost commented Jan 6, 2018

how should i run this

@sevetseh28
Copy link

sevetseh28 commented Jan 14, 2018

Doesnt work anymore, getting Uncaught TypeError: Cannot read property '_owner' of undefined

@sayhicoelho
Copy link

Does not work anymore. Getting: Uncaught TypeError: Cannot read property 'props' of null

@tinyCoder32
Copy link

Hello, please is there any update for this?

@hamrammi
Copy link

For those looking for the actual code, follow this link https://gist.github.com/nthrnth/940509123b7fe39aebc7c2942ebe227b

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