Skip to content
Related Articles

Related Articles

Send unlimited Whatsapp messages using JavaScript
  • Difficulty Level : Medium
  • Last Updated : 16 Apr, 2020

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);
    }
      
    /*Schedule your message section starts here
    var now = new Date();
      
    // Replace Hours, Mins and secs with your 
    // desired time in 24 hour time format e.g.
    // var rt = new Date(now.getFullYear(), now.getMonth(), 
    // now.getDate(), Hours, Minutes, Sec, 0) - now; 
    // to send message at 2.30PM 
    var rt = new Date(now.getFullYear(), now.getMonth(),
                    now.getDate(), 14, 30, 00, 0) - now; 
      
      
      
    if (rt < 0) {
        rt += 86400000; 
    }
      
    setTimeout(startTimer, rt);
    Schedule your message section ends here*/
      
      
    // Replace My Contact Name with the name 
    // of your WhatsApp contact or group e.g. title="Peter Parker"
    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"; // Replace My Message with your message use   to add spaces to your message
      
        counter = 5; // Replace 5 with the number of times you want to send your message
      
        for (i = 0; i < counter; i++) {
            event = document.createEvent("UIEvents");
            messageBox.innerHTML = message.replace(/ /gm, ''); // test it
            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 πŸ™‚

    geeks-digest-img

    My Personal Notes arrow_drop_up
    Recommended Articles
    Page :