Power of DOM Manipulation Create a Simple Spam Script for WhatsApp Web

MacTavish
3 min readMay 12, 2020
DOM JS wins

With the growing use of JavaScript framweworks, DOM Manipulation is looked down now a days. But Today, we are gonna do something fun (For us) and Annoying (for the victim) with the DOM Manipulation power of JavaScript. We are going to create a basic Spam Script for WhatsApp Web with some ideas of improvement as a challenge for you guys to try next.

Before we actually dive into code, Let’s walk through the process.

Overview

We are going to insert some JS code in console and send our message as many times as we want using the CODE. Let’s figure out how WhatsApp sends the message.

  1. You see the ``message box``, you type in message and click on send button.
Message box for WhatsApp Web

2. Notice there is no send button until you type in some text. That means send button is generated/becomes visible in response to input event.

3. When you type something, the send button appears. Now is the perfect use case for JS click().

CODE

First thing, we have to select the Message Box and add some text to it. Since there is no ID assigned to it, we will try to access it via Class name.

  1. Accessing it via Class Name gives us following element. We can access it using index 1 of resulting array.
Accessing Message Box via JS

2. Let’s add some text via innerHTML property.

Adding Text to Message Box via JS

3. The Send button is not visible yet. As we discussed above, it appears as result of input event on Message Box. Let’s create and dispatch an input event.

Send button becomes visible after input event on Message Box

4. It’s time to fake a click event on send button. But first, let’ see our Send button in DOM. Note the attached Click event to it.

Send Button DOM view

5. Lastly, Let’s click on button from our code. Notice the message is sent after we emulated a click.

Selecting and emulating click on button to send the Message

Congrats, You just learned how to programmatically send a Message on WhatsApp Web utilizing the Looked down DOM Manipulation power of JavaScript. You didn’t just learn the code but the process of digging through DOM which will also help you in future.

We Said SPAM Script but one message in not a SPAM. Wrap you code inside a loop and turn it into Spam Script

Finally Here is the GitHub Repository which contains the code.

What Next

This is just a basic script. Using the same approach as shown in Article, You can Add

  1. Mention feature to the Script.
  2. Make a form and get the form values to spam. Make the Script easy to use by just pasting in console and filling the form.

--

--

MacTavish

Contributor in Tor Project, Web developer, Gamer. I tend to write article to help beginners.