When it comes to web development, JavaScript can do wonders! Let me show you one more wonder of JavaScript.
Wouldn’t it be cool if we can send infinite WhatsApp messages at just one click? be the first one to wish birthday/anniversaries/special events to our loved ones? schedule any message for any contact/group on your WhatsApp? and so much more?
Well yes, we can achieve all these things with the help of JavaScript. The most interesting part is that all you need is a phone with WhatsApp, a laptop/PC and a Web-Browser(Google Chrome, Edge, Mozilla etc.) with Javascript enabled in it (which is usually enabled by default). No need of installing anything else.
Let’s get started.
Open WhatsApp on the phone.
Click on the 3 dots in the top right corner.
Click on WhatsApp Web.

Follow the instructions to open WhatsApp web on your computer.

Assuming that by this time you have WhatsApp Web running on your computer, check if it looks like the image below:-

Now let’s bring our attention to the computer.
- In the browser press Ctrl, Shift and I together to open a developer’s console.
- Find out the “Console” tab there and click on it.
- Now we are almost done.
- Double click the code below to edit it.
- Find and assign values to the following variables: name, message, and counter.
The code works on the principle of simulating send via reproducing send actions, it cannot search for a contact if a conversation is not initiated, as of yet.
Read the comments in the code and you will know what to do 🙂
<script>
function simulateMouseEvents(element, eventName)
{
var mouseEvent = document.createEvent( 'MouseEvents' );
mouseEvent.initEvent(eventName, true , true );
element.dispatchEvent(mouseEvent);
}
name = "My Contact Name"
simulateMouseEvents(document.querySelector( '[title="' + name + '"]' ), 'mousedown' );
function startTimer()
{
setTimeout(myFunc, 3000);
}
startTimer();
var eventFire = (MyElement, ElementType) => {
var MyEvent = document.createEvent( "MouseEvents" );
MyEvent.initMouseEvent
(ElementType, true , true , window, 0, 0, 0, 0, 0, false , false , false , false , 0, null );
MyElement.dispatchEvent(MyEvent);
};
function myFunc()
{
messageBox = document.querySelectorAll( "[contenteditable='true']" )[1];
message = "My Message" ;
counter = 5;
for (i = 0; i < counter; i++) {
event = document.createEvent( "UIEvents" );
messageBox.innerHTML = message.replace(/ /gm, '' );
event.initUIEvent( "input" , true , true , window, 1);
messageBox.dispatchEvent(event);
eventFire(document.querySelector( 'span[data-icon="send"]' ), 'click' );
}
}
</script>
|
Now copy the modified code and paste it in the console windows that you opened before. You are good to go now!
Hit Enter and voila! Your desired numbers of messages are sent, just with a single click.
Extra Fun: To schedule your message, remove the comment from “Schedule your message section” in the code and set the time as per your wish!
Note:- Make sure that the contact/group you are willing to send messages are visible in the browser without the need of scrolling down.
WhatsApp may block your account for excessive use of such scripts. So use at your own risk!
All the information provided on this site are for educational purposes only. The site and author of the article is no way responsible for any misuse of the information.
Feel free to tweak the code as per your need and have fun! Happy Coding 🙂
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
03 Jul, 2022
Like Article
Save Article