Learn how to unfollow easily a lot of users injecting a simple script in the console of the browser.

How to unfollow masively users on Instagram using a little trick with JavaScript in the Browser

Although this article breaks the standards of Our Code World as usually our articles are very technical, it seems to be a good example to learn how to write a very simple automatization script. Many users apply the follow x follow to get a lot of followers, bought follows on websites to buy likes instagram, however when you let your account to a "social network manager" and this end up doing the mentioned follow x follow, many users will be angry 'cause of obvious reasons.

The other day, trying to undo such thing on a friend's account decided to write a simple bot script in JS that automatically clicks the unfollow button of the users that the account follows, however wasn't too surprised when i discovered that Instagram has a request limit between every "Unfollow" action. You can't, even with a mobile device and doing it manually, unfollow more than 60 users/hour (trying to do this will end up in 403 responses in the action to unfollow):

Note

Even with the script, you will see someday this error in the console. You will need to wait 10-15 minutes (or less) before running the script again.

Instagram Unfollow 403 error

That's why the script needed to be modified in order to unfollow an user every minute, so it won't be blocked (sometimes it gets blocked as well and you need to wait 10 minutes to run the script again) and i want to share with you this simple script.

Advantages of this approach

  • Instead of unfollow every user manually, you can run the script in the background and let it running for an entire day in the office.
  • The computer unfollows for you, you will only need to inject the script in the browser and that's it.

Limitations

  • Instagram has a known protection algorithm against "bots" and other automatization scripts, like the one that we're writing (even with humans, if you try to unfollow more than 15 users manually from your app or desktop immediately, instagram will impose its limitation). To skip and prevent any error on the script, the logic is to click every Unfollow button every 60 seconds. This will allow you to unfollow so many users as the dialog can list.
  • It is pretty time consuming as you will need a minute for every user that you want to unfollow.

Unfollow script

The following script is the one that does the trick and works as follows:

var jqueryScript = document.createElement('script');
jqueryScript.src = "//code.jquery.com/jquery-3.3.1.min.js";
jqueryScript.onload = function(){
    
    // Important: change those text according to the text of the following button in your language
    // e.g in Spanish it would be "Seguido"
    let unfollowButtonText = "Following";
    // Recently, a new confirmation dialog appears asking if you really want to unfollow the user
    // change this text as well
    // e.g in Spanish it would be "Dejar de seguir"
    let unfollowConfirmationText = "Unfollow";

    // Prepare jQuery Selector for buttons that contain "Following"
    let selector = `button:contains('${unfollowButtonText}')`;

    // You need to wait 60 seconds after every unfollow, otherwise you will
    // be blocked temporary by the Instagram API and you'll see a 403 error in the network !
    let currentTime = 0;
    let step = 60 * 1000;

    // Query the button
    let unfollowButtons = $(selector);
    // Total of buttons found
    let totalUnfollowButtons = unfollowButtons.length;

    if(!totalUnfollowButtons){
        alert("Error: no Following buttons found, maybe change the text of the button?");
    }

    // Iterate on every button
    unfollowButtons.each(function(index){
        let button = $(this);

        setTimeout(function(){
            (function(i){
                console.log(`Unfollowing ${i} of ${totalUnfollowButtons}`);

                if(i == totalUnfollowButtons){
                    console.log("Script finished succesfully !");
                }

                button.trigger("click");

                // Important: recently, a confirmation dialog was added when  you click
                // on unfollow, so simply click the confirmation button as well to unfollow the user
                setTimeout(function(){
                    var btn = $(`button:contains('${unfollowConfirmationText}')`);

                    if(btn){
                        btn.trigger("click");
                    }
                }, 100);
            })(index + 1);
        }, currentTime);

        currentTime += step;
    });
};

// Inject Script !
document.getElementsByTagName('head')[0].appendChild(jqueryScript);

How to use it

The execution of the previous script can be done within seconds by only pasting it in the JS console of the browser. If you aren't a developer, we'll guide you through the process:

1. Open Instagram in your desktop/laptop with Google Chrome

As first step you need to open your instagram account in the official website on your desktop computer, where you can open the desktop version of Chrome. After logging in, proceed with the next step.

2. Open Browser Devtools

Open Google Chrome and open the Developer Tools either pressing CTRL + Shift + I or doing right click in the Instagram webpage and selecting from the context menu the Inspect Element Option to open the dev tools. Once it appears, go to the Console tab. Let this window open as we'll inject the script here in the step #4.

3. Open Following List Dialog

As mentioned, the logic of the script is that the script will automatically click every "Unfollow" button of the users on the list of users that you're following. This list is a dialog that can be shown by simply clicking on the Following xx button of your profile:

Following List Dialog Button

This should open a dialog from users that you're currently following:

Open Following List Dialog

Now that you have the dialog of users that you're following, you need to scroll and display all the users that you want to unfollow during the execution of the script. All the buttons with "Following" will be clicked, so the dialog needs to be always opened (recently a new confirmation dialog was added in Instagram, so the script will click that button as well). As next, you will only need to inject the script. It can be stated that you might need a different kind of script for Instagram Reels. You can buy Instagram reels likes from authorized places.

4. Inject Script

Copy the code at the beginning of the article and paste it into the console, then press enter to execute the code and the unfollow process will start:

Unfollow Massive Instagram

The script automatically shows in the console the progress and says when the process finishes or if there's any error (read initial warning).

Happy unfollowing !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors