Skip to content

Instantly share code, notes, and snippets.

@yask123
Created January 24, 2015 17:08
Show Gist options
  • Save yask123/d085d4b7a486d00dd103 to your computer and use it in GitHub Desktop.
Save yask123/d085d4b7a486d00dd103 to your computer and use it in GitHub Desktop.
Send messages on whatsapp by Javascript
document.getElementsByClassName("input")[1].innerHTML="This message was written via JS script! "; // Fills the text box message
var input = document.getElementsByClassName("icon btn-icon icon-send");//Grabs the send button
input[0].click();// Clicks the send button
@igormuba
Copy link

UPDATE + SPAM SEND EVERY X SECONDS + MORE LEGIBLE CODE (credits to rafaelxavierborges for the skeleton of the code)
Tested on Google Chrome = does not work
Tested on Firefox = works

var t=0;                             //This is the counter, where the counting starts
var messageToSendEveryXTime;  //the is the variable that holds the message to send
messageToSendEveryXTime = t;   //in my case I want to spam counting numbers starting at zero
                                                     //if you want to send something else change here
                                                     //for example you migh want to send "I love you every second" every second

setInterval(function(){
	window.InputEvent = window.Event || window.InputEvent; 
	var d = new Date(); 
	var event = new InputEvent('input', {bubbles: true}); 
	var textbox = $('div._2S1VP'); 
	textbox.textContent = messageToSendEveryXTime;   //inserts the message in the textbox
	textbox.dispatchEvent(event); $("button._35EW6").click(); //sends the message
	t++;         //increments the counter
}, 1000); //interval to send messages, 1000= 1 second
             //choose the delay in seconds times 1000, example, 5 seconds is 5000

@igormuba
Copy link

If you are looking for a whatsapp spammer bot, I have updated it with instructions and working 29 september 2018
https://gist.github.com/igormuba/f37b8630cadbb511c53e7765de34bc6c

@fercomunello
Copy link

/**
 * 1) Open a contact or group on Whatsapp Web;
 * 2) Copy the Javascript code below;
 * 3) Open the developer tools: CTRL + SHIFT + I;
 * 4) Go to the "Console" tab and paste the code;
 * 5) The function was added on the page;
 * 6) Now, still on the console, type: spam ();
 * 7) A pop-up will be displayed requesting the spam message and
 * how many messages you want to send per second (I recommend placing 2 to 5).
 */

function spam() {
    let prompt1 = prompt("Enter the spam message", "");
    const prompt2 = prompt("Send how many messages per second?", 1);

    const input = document.getElementsByClassName("_3FRCZ")[1];
    window.InputEvent = window.Event || window.InputEvent;

    let count = 0;

    if (prompt1 === "") {
        prompt1 = "​";
    }

    console.log("Spam started ...");

    window.setInterval(function() {
        count++;

        input.innerHTML = prompt1;

        input.dispatchEvent(new InputEvent("input", {
            bubbles: true
        }));

        let enviar = document.getElementsByClassName("_1U1xa")[0];
        enviar.click();

        console.log('Messasages sent: ' + count);
    }, 1000 / prompt2);
}

@YogeshSharma01
Copy link

/**
 * 1) Open a contact or group on Whatsapp Web;
 * 2) Copy the Javascript code below;
 * 3) Open the developer tools: CTRL + SHIFT + I;
 * 4) Go to the "Console" tab and paste the code;
 * 5) The function was added on the page;
 * 6) Now, still on the console, type: spam ();
 * 7) A pop-up will be displayed requesting the spam message and
 * how many messages you want to send per second (I recommend placing 2 to 5).
 */

function spam() {
    let prompt1 = prompt("Enter the spam message", "");
    const prompt2 = prompt("Send how many messages per second?", 1);

    const input = document.getElementsByClassName("_3FRCZ")[1];
    window.InputEvent = window.Event || window.InputEvent;

    let count = 0;

    if (prompt1 === "") {
        prompt1 = "​";
    }

    console.log("Spam started ...");

    window.setInterval(function() {
        count++;

        input.innerHTML = prompt1;

        input.dispatchEvent(new InputEvent("input", {
            bubbles: true
        }));

        let enviar = document.getElementsByClassName("_1U1xa")[0];
        enviar.click();

        console.log('Messasages sent: ' + count);
    }, 1000 / prompt2);
}

It shows
Uncaught TypeError: Cannot set property 'innerHTML' of undefined
at :19:25

@a4amin
Copy link

a4amin commented Mar 24, 2021

How to send with media ?

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