Skip to content

Instantly share code, notes, and snippets.

@chaodonghu
Last active May 8, 2024 17:13
Show Gist options
  • Save chaodonghu/c25c7ee3e3eb85c0a0de051892e596a4 to your computer and use it in GitHub Desktop.
Save chaodonghu/c25c7ee3e3eb85c0a0de051892e596a4 to your computer and use it in GitHub Desktop.
Google Chrome script that allows user to mass follow instagram users on another's profile
// Run GOOGLE CHROME - WORKING AS OF DEC 26 2023
// Please @ me in the comments if this stops working, I will try to get it working again within the month
// INSTRUCTIONS
// 1. Open Instagram in Chrome
// 2. Click on "FOLLOWERS" OR "FOLLOWING" on your Instagram profile or a desired user's Instagram profile
// 3. Open developer tools by right clicking on the page and clicking "INSPECT"
// 4. Copy the code below and paste in the developer tools console and press enter to run
// 5. Script will not run if tab is navigated away from, minimized of unfocused (It is recommended to open a new chrome window or push tab to the side and let script run in background)
// Script will follow everyone on the page until it reaches the follow limit or the time limit
// Script will take a break after the follow limit is reached to avoid rate limiting
const followEveryone = (async () => {
// Modify these variables to your liking
const FOLLOW_LIMIT = 800;
const BREAK_DURATION = 5 * 60 * 1000; // 5 minutes break
const TOTAL_DURATION = 10 * 60 * 1000; // 10 minutes duration - Timeout after 10 minutes
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// Find target button
const findButton = (txt) =>
[...document.querySelectorAll("button").entries()]
.map(([pos, btn]) => btn)
.filter((btn) => btn.innerText === txt)[0];
console.log("Start following script...");
let startTime = new Date().getTime();
while (new Date().getTime() - startTime < TOTAL_DURATION) {
for (let i = 0; i < FOLLOW_LIMIT; i++) {
const followButton = findButton("Follow");
if (!followButton) {
continue;
}
followButton.scrollIntoViewIfNeeded();
followButton.click();
await delay(100);
const confirmFollowButton = findButton("follow");
if (confirmFollowButton) {
await confirmFollowButton.click(); // Wait for the follow to complete
}
// Increase FOLLOW_INTERVAL if you are getting rate limited
// Set this to 0 follow as quickly as possible - not recommended
// Random follow interval for each follow to avoid rate limiting
const FOLLOW_INTERVAL = Math.floor(Math.random() * 10 + 1) * 1000;
console.log(`Wait ${FOLLOW_INTERVAL} milliseconds`);
await delay(FOLLOW_INTERVAL);
console.log(`Followed #${i + 1}`);
}
console.log(`Taking a break for ${BREAK_DURATION / 1000} seconds...`);
await delay(BREAK_DURATION); // Take a break to avoid rate limiting
startTime = new Date().getTime(); // Reset start time for the next cycle
}
console.log("Follow script complete!");
})();
@hymandco
Copy link

why my console get this .. "Uncaught SyntaxError: Identifier 'FOLLOW_BUTTON_TEXT' . anyone can help me to solve this problem ? i try clear but still same

@chaodonghu
Copy link
Author

why my console get this .. "Uncaught SyntaxError: Identifier 'FOLLOW_BUTTON_TEXT' . anyone can help me to solve this problem ? i try clear but still same

As per my comment above, it might have been the case where you copy and pasted the code twice where the FOLLOW_BUTTON_TEXT is already declared. Can you refresh your tab and clear the console and try to run the script again.

If not can you paste a screenshot or gif of the error?

@chaodonghu
Copy link
Author

https://drive.google.com/file/d/14J7NfQyXlFCt258C15cgSSipCqznQj6Y/view?usp=sharing
https://drive.google.com/file/d/1HoOnutzdzKYiKBiVWPPG_ahs35lj5n4d/view?usp=sharing

this can u check for me ?

You have the right modal open and everything, would you be able to make sure you copy and pasted the above code correctly?

The unexpected identifier in chrome's javascript console is an indication of a syntax error. I've pasted in the above code and it seems to be working for for me.

Screen Shot 2020-11-15 at 2 11 13 PM

@hymandco
Copy link

https://drive.google.com/file/d/14J7NfQyXlFCt258C15cgSSipCqznQj6Y/view?usp=sharing
https://drive.google.com/file/d/1HoOnutzdzKYiKBiVWPPG_ahs35lj5n4d/view?usp=sharing
this can u check for me ?

You have the right modal open and everything, would you be able to make sure you copy and pasted the above code correctly?

The unexpected identifier in chrome's javascript console is an indication of a syntax error. I've pasted in the above code and it seems to be working for for me.

Screen Shot 2020-11-15 at 2 11 13 PM

i will try again .

@chaodonghu
Copy link
Author

If this helped you, please leave a comment below or support me at:

@ahmedfourati
Copy link

Hello, the script is working fine but instead of following the profiles in the pop up, the script is following the suggestions profiles.
Thank you.

@chaodonghu
Copy link
Author

Hello, the script is working fine but instead of following the profiles in the pop up, the script is following the suggestions profiles.
Thank you.

@ahmedfourati Are you on a profile's page? eg. https://www.instagram.com/chaoarchive, then press "followers" or "following"

@nkre
Copy link

nkre commented Feb 27, 2021

I wanna use this script for other website but I am not sure that how can I change right things?
indir (6)
I tried to use this code with a few changes but ı saw this message. May u help me
gardrops2
gardrops1

@chaodonghu
Copy link
Author

I wanna use this script for other website but I am not sure that how can I change right things?
indir (6)
I tried to use this code with a few changes but ı saw this message. May u help me
gardrops2
gardrops1

Sorry this is only going to work for instagram, you'll have to change the element selectors and if you want it to adapt to other sites.

@wainaze
Copy link

wainaze commented Apr 25, 2021

Hey! I have a 400 status response on /follow... Any chance I can fix this?
Selection_496

@wainaze
Copy link

wainaze commented May 1, 2021

Hey! I have a 400 status response on /follow... Any chance I can fix this?
Selection_496

@wainaze A 400 error is a OAuthException, did you log out accidentally. I just tested it and it seems to be working fine. You can refresh the page and try again.

No, tried again. Worked like maybe 10 follows, then produced same error. I'm still logged script does error 400 and when I click the follow button manually it doesn't do anything.

@zeal123-cyper
Copy link

can you make to cancel sent requests on Instagram

@chaodonghu
Copy link
Author

can you make to cancel sent requests on Instagram

If you change line 11

const FOLLOW_BUTTON_TEXT = 'Follow' // CHANGE "FOLLOW" TO LOCALIZED LANGUAGE AS DISPLAYED ON INSTAGRAM

to

const FOLLOW_BUTTON_TEXT = 'Requested' then it should work for your use case, to remove the requested follow request for private users.

@SpotAndrew2021
Copy link

SpotAndrew2021 commented Sep 16, 2021

It looks pretty interesting if you take into account the fact that now created a lot of different resources for viewing statistics on instagram and other social networks. I think you can use one of them. If you do not know where to look, I can advise you the resource that I myself use almost every day and with great success. You can find the site for Instagram stats without too much trouble, and it is an excellent tool for you. I am one hundred percent sure about that.

@kevindrummond1
Copy link

kevindrummond1 commented Oct 13, 2021

Hi @chaodonghu

Great code! Anyway, I have a question. How do I modify the script so it follows 40 accounts at a two-second interval and then it waits for 10 minutes before following another 40 accounts again? I'd like the loop to repeat three times. So it goes:

  1. Follow an account and wait for 2 seconds X40
  2. Wait for 10 minutes
  3. Follow an account and wait for 2 seconds X40
  4. Wait for 10 minutes
  5. Follow an account and wait for two seconds X40
  6. ---LOOP ENDS---

Thank you very much.

@chaodonghu
Copy link
Author

Hi @chaodonghu

Great code! Anyway, I have a question. How do I modify the script so it follows 40 accounts at a two-second interval and then it waits for 10 minutes before following another 40 accounts again? I'd like the loop to repeat three times. So it goes:

  1. Follow an account and wait for 2 seconds X40
  2. Wait for 10 minutes
  3. Follow an account and wait for 2 seconds X40
  4. Wait for 10 minutes
  5. Follow an account and wait for two seconds X40
  6. ---LOOP ENDS---

Thank you very much.

Hey @kevindrummond1,

The code is designed so there is only a single timeout, I think following 80 accounts within 80 seconds will probably get you rate-limit blocked by instagram.

But you can probably do something like this

// RUN WITH GOOGLE CHROME
// 1. OPEN INSTAGRAM
// 2. CLICK ON "FOLLOWERS" OR "FOLLOWING" ON A DESIRED USER'S PROFILE
// 3. OPEN DEVELOPER TOOLS BY RIGHT CLICKING ON PAGE AND CLICKING "INSPECT"
// 4. COPY FOLLOWING CODE AND PASTE IN DEVELOPER TOOLS CONSOLE AND RUN
// 5. SCRIPT WILL NOT RUN IF TAB IS NAVIGATED AWAY FROM, MINIMIZED OR UNFOCUSED
// IT IS RECOMMENDED TO OPEN A NEW CHROME WINDOW OR PUSH TAB TO THE SIDE AND LET SCRIPT RUN IN BACKGROUND

// SCRIPT WILL CLICK ON "FOLLOW" BUTTON AND THEN SCROLL THE NEXT "FOLLOW" BUTTON INTO VIEW

const FOLLOW_BUTTON_TEXT = 'Follow' // CHANGE "FOLLOW" TO LOCALIZED LANGUAGE AS DISPLAYED ON INSTAGRAM
const MAX_ATTEMPTS_PER_FOLLOW = 3 // MAXIMUM # OF ATTEMPTS

const followSomebody = () => {
    const followButton = document
        .evaluate(`//button[text()="${FOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
        .singleNodeValue
    if (followButton) {
        let attempts = 1
        while (attempts < MAX_ATTEMPTS_PER_FOLLOW && !followButton) {
            console.log(`Attempted to find followButton but could not. Retry #${attempts++}`)
            followButton = document.evaluate(`//button[text()="${FOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
        }
        if (attempts < MAX_ATTEMPTS_PER_FOLLOW) {
            console.log('Found follow button. Scrolling and clicking ...')
            followButton.scrollIntoView(true)
            followButton.click()
        } else {
            console.log(`Retried ${MAX_ATTEMPTS_PER_FOLLOW} times and didn't succeed`)
        }
        return false
    }
    return true
}

const timeout = (ms) => new Promise(resolve => setTimeout(resolve, ms))

// INCREASE TIMEOUT IF NECESSARY TO AVOID RESTRICTIONS/LIMITS PER DAY
// 2 second intervals
const randomTimeout = () => (Math.floor((Math.random() * 10) + 1) * 2000)

const followEveryone = async () => {
    let shouldStop = false
    while (!shouldStop) {
        shouldStop = followSomebody()
        const followTimeout = randomTimeout()
        console.log(`Waiting ${followTimeout} seconds. Should stop: ${shouldStop}.`)
        await timeout(followTimeout)
    }
    console.log('You cannot follow anymore.')
}

// Run 3 times
for (let i = 0; i <= 3; i++) {
   // Wait 10 minutes between each loop
   timeout(600000)
   for (let i = 0; i <= 40; i++) {
      followEveryone()
   }
}

Just wrapping the followEveryone() function in several for loops

@kevindrummond1
Copy link

Hi @chaodonghu
Great code! Anyway, I have a question. How do I modify the script so it follows 40 accounts at a two-second interval and then it waits for 10 minutes before following another 40 accounts again? I'd like the loop to repeat three times. So it goes:

  1. Follow an account and wait for 2 seconds X40
  2. Wait for 10 minutes
  3. Follow an account and wait for 2 seconds X40
  4. Wait for 10 minutes
  5. Follow an account and wait for two seconds X40
  6. ---LOOP ENDS---

Thank you very much.

Hey @kevindrummond1,

The code is designed so there is only a single timeout, I think following 80 accounts within 80 seconds will probably get you rate-limit blocked by instagram.

But you can probably do something like this

// RUN WITH GOOGLE CHROME
// 1. OPEN INSTAGRAM
// 2. CLICK ON "FOLLOWERS" OR "FOLLOWING" ON A DESIRED USER'S PROFILE
// 3. OPEN DEVELOPER TOOLS BY RIGHT CLICKING ON PAGE AND CLICKING "INSPECT"
// 4. COPY FOLLOWING CODE AND PASTE IN DEVELOPER TOOLS CONSOLE AND RUN
// 5. SCRIPT WILL NOT RUN IF TAB IS NAVIGATED AWAY FROM, MINIMIZED OR UNFOCUSED
// IT IS RECOMMENDED TO OPEN A NEW CHROME WINDOW OR PUSH TAB TO THE SIDE AND LET SCRIPT RUN IN BACKGROUND

// SCRIPT WILL CLICK ON "FOLLOW" BUTTON AND THEN SCROLL THE NEXT "FOLLOW" BUTTON INTO VIEW

const FOLLOW_BUTTON_TEXT = 'Follow' // CHANGE "FOLLOW" TO LOCALIZED LANGUAGE AS DISPLAYED ON INSTAGRAM
const MAX_ATTEMPTS_PER_FOLLOW = 3 // MAXIMUM # OF ATTEMPTS

const followSomebody = () => {
    const followButton = document
        .evaluate(`//button[text()="${FOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
        .singleNodeValue
    if (followButton) {
        let attempts = 1
        while (attempts < MAX_ATTEMPTS_PER_FOLLOW && !followButton) {
            console.log(`Attempted to find followButton but could not. Retry #${attempts++}`)
            followButton = document.evaluate(`//button[text()="${FOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
        }
        if (attempts < MAX_ATTEMPTS_PER_FOLLOW) {
            console.log('Found follow button. Scrolling and clicking ...')
            followButton.scrollIntoView(true)
            followButton.click()
        } else {
            console.log(`Retried ${MAX_ATTEMPTS_PER_FOLLOW} times and didn't succeed`)
        }
        return false
    }
    return true
}

const timeout = (ms) => new Promise(resolve => setTimeout(resolve, ms))

// INCREASE TIMEOUT IF NECESSARY TO AVOID RESTRICTIONS/LIMITS PER DAY
// 2 second intervals
const randomTimeout = () => (Math.floor((Math.random() * 10) + 1) * 2000)

const followEveryone = async () => {
    let shouldStop = false
    while (!shouldStop) {
        shouldStop = followSomebody()
        const followTimeout = randomTimeout()
        console.log(`Waiting ${followTimeout} seconds. Should stop: ${shouldStop}.`)
        await timeout(followTimeout)
    }
    console.log('You cannot follow anymore.')
}

// Run 3 times
for (let i = 0; i <= 3; i++) {
   // Wait 10 minutes between each loop
   timeout(600000)
   for (let i = 0; i <= 40; i++) {
      followEveryone()
   }
}

Just wrapping the followEveryone() function in several for loops

Thank you @chaodonghu . I'm wondering at what condition the script stops following. Because every time it initiates a new loop, it writes 'You cannot follow anymore.'

@chaodonghu
Copy link
Author

Hi @chaodonghu
Great code! Anyway, I have a question. How do I modify the script so it follows 40 accounts at a two-second interval and then it waits for 10 minutes before following another 40 accounts again? I'd like the loop to repeat three times. So it goes:

  1. Follow an account and wait for 2 seconds X40
  2. Wait for 10 minutes
  3. Follow an account and wait for 2 seconds X40
  4. Wait for 10 minutes
  5. Follow an account and wait for two seconds X40
  6. ---LOOP ENDS---

Thank you very much.

Hey @kevindrummond1,
The code is designed so there is only a single timeout, I think following 80 accounts within 80 seconds will probably get you rate-limit blocked by instagram.
But you can probably do something like this

// RUN WITH GOOGLE CHROME
// 1. OPEN INSTAGRAM
// 2. CLICK ON "FOLLOWERS" OR "FOLLOWING" ON A DESIRED USER'S PROFILE
// 3. OPEN DEVELOPER TOOLS BY RIGHT CLICKING ON PAGE AND CLICKING "INSPECT"
// 4. COPY FOLLOWING CODE AND PASTE IN DEVELOPER TOOLS CONSOLE AND RUN
// 5. SCRIPT WILL NOT RUN IF TAB IS NAVIGATED AWAY FROM, MINIMIZED OR UNFOCUSED
// IT IS RECOMMENDED TO OPEN A NEW CHROME WINDOW OR PUSH TAB TO THE SIDE AND LET SCRIPT RUN IN BACKGROUND

// SCRIPT WILL CLICK ON "FOLLOW" BUTTON AND THEN SCROLL THE NEXT "FOLLOW" BUTTON INTO VIEW

const FOLLOW_BUTTON_TEXT = 'Follow' // CHANGE "FOLLOW" TO LOCALIZED LANGUAGE AS DISPLAYED ON INSTAGRAM
const MAX_ATTEMPTS_PER_FOLLOW = 3 // MAXIMUM # OF ATTEMPTS

const followSomebody = () => {
    const followButton = document
        .evaluate(`//button[text()="${FOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
        .singleNodeValue
    if (followButton) {
        let attempts = 1
        while (attempts < MAX_ATTEMPTS_PER_FOLLOW && !followButton) {
            console.log(`Attempted to find followButton but could not. Retry #${attempts++}`)
            followButton = document.evaluate(`//button[text()="${FOLLOW_BUTTON_TEXT}"]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
        }
        if (attempts < MAX_ATTEMPTS_PER_FOLLOW) {
            console.log('Found follow button. Scrolling and clicking ...')
            followButton.scrollIntoView(true)
            followButton.click()
        } else {
            console.log(`Retried ${MAX_ATTEMPTS_PER_FOLLOW} times and didn't succeed`)
        }
        return false
    }
    return true
}

const timeout = (ms) => new Promise(resolve => setTimeout(resolve, ms))

// INCREASE TIMEOUT IF NECESSARY TO AVOID RESTRICTIONS/LIMITS PER DAY
// 2 second intervals
const randomTimeout = () => (Math.floor((Math.random() * 10) + 1) * 2000)

const followEveryone = async () => {
    let shouldStop = false
    while (!shouldStop) {
        shouldStop = followSomebody()
        const followTimeout = randomTimeout()
        console.log(`Waiting ${followTimeout} seconds. Should stop: ${shouldStop}.`)
        await timeout(followTimeout)
    }
    console.log('You cannot follow anymore.')
}

// Run 3 times
for (let i = 0; i <= 3; i++) {
   // Wait 10 minutes between each loop
   timeout(600000)
   for (let i = 0; i <= 40; i++) {
      followEveryone()
   }
}

Just wrapping the followEveryone() function in several for loops

Thank you @chaodonghu . I'm wondering at what condition the script stops following. Because every time it initiates a new loop, it writes 'You cannot follow anymore.'

If you follow the function within shouldStop it will stop if it can't find a "Follow" button or if the # of max attempts is reached which is 3.

@Kynv94
Copy link

Kynv94 commented Mar 1, 2022

Hi @chaodonghu,
Sorry for disturbing you but can you take a look at my case?
capture
There are still many follow buttons but the script stopped at the beginning.
I don't know if google chrome have had any updates lately, because the last time I used the script, it had still worked great.
Thank you so much

@chaodonghu
Copy link
Author

@Kynv94 Would you be able to post it as a gif or video here by dragging and dropping the capture, i'm unable to access that google drive link.

@Kynv94
Copy link

Kynv94 commented Mar 1, 2022

@Kynv94 Would you be able to post it as a gif or video here by dragging and dropping the capture, i'm unable to access that google drive link.

here is the picture
image

@chaodonghu
Copy link
Author

@Kynv94 Yeah it looks like the script is unable to obtain the "Follow" button anymore, i've replicated your error. I'll try to have a fix by this weekend I'm a bit busy with work this week but will post once I can get a fix.

@Kynv94
Copy link

Kynv94 commented Mar 1, 2022

@chaodonghu thank you so much
pls tag me when you're done <3 <3 <3 xoxo
have a nice week

@chaodonghu
Copy link
Author

Hey @Kynv94,

Sorry for the delay. Just modified the code to grab the follow buttons and tested it out. It should be working again.

Screen Shot 2022-03-13 at 10 34 46 PM

@Kynv94
Copy link

Kynv94 commented Mar 20, 2022

Thank you @chaodonghu so much (y) (y) (y)

@D1rtyC0de
Copy link

Hi is this code still working ?!

@chaodonghu
Copy link
Author

Hi is this code still working ?!

Hi @D1rtyC0de, sorry for the late reply, the code should be working as of Dec 26 2023. I just updated the code.

@alpsn
Copy link

alpsn commented May 2, 2024

Hi @chaodonghu, I just can't get my settings right... it would be very cool if you could help me :)

The above script setting follows me too quickly and in my opinion there is a risk of being banned.

How I would like it:
One follower per minute > 60 in one hour (limit) > break of 10 minutes > and this until a maximum of 300 followers are reached per day.

How should I move forward? Can you please help me?

peace

@chaodonghu
Copy link
Author

@alpsn You would have to change the variables

const FOLLOW_LIMIT = 300;
const BREAK_DURATION = 10 * 60 * 1000; // 5 minutes break

const TOTAL_DURATION = 60 * 60 * 1000; // 60 minutes duration

...

const FOLLOW_INTERVAL = Math.floor(Math.random() * 10 + 1) * 60000; // Runs once every minute

The above script setting follows me too quickly and in my opinion there is a risk of being banned.

You won't get banned, instagram will usually detect that theres some scripting going on in your account and you might get locked but you will just be required to reset your password.

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