Skip to content

Instantly share code, notes, and snippets.

@EyMaddis
Created November 4, 2016 12:50
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
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')
@Sigurd922
Copy link

THANKS! Perfect!

@Vibe6
Copy link

Vibe6 commented Aug 8, 2017

How I will run this code?

@sevetseh28
Copy link

Hey thanks! Btw, how can you mark the messages as seen?

@Bonke2017
Copy link

How can i open a new chat box?

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