Status: Confirmed fully working on June 2025.
Terms of Service disclaimer: Automating Instagram interactions violates Instagram’s Terms of Use. These scripts are provided strictly for educational or internal‑testing purposes. Use at your own risk; the author assumes no liability for account suspension, data loss, or any other consequences.
Script | Auth method | Persistent data |
---|---|---|
logincreds.js |
Logs in with username + password the first time, then re‑uses the cookie jar saved to cookies.json . |
cookies.json |
csrfsession.js |
Uses a pre‑exported sessionid + csrftoken cookie pair taken directly from a logged‑in browser session (no 2‑factor). |
None |
Choose whichever flow best matches your threat model and Instagram account settings.
- Node.js
- A (preferably throw‑away) Instagram account with two‑factor authentication disabled
# Clone & install dependencies
$ git clone https://github.com/duongddinh/InstagramAutoComment.git
$ cd InstagramAutoComment
$ node [file].js
logincreds.js
(username/password method)IG_USERNAME=your_username
IG_PASSWORD=your_password
TARGET_POST_URL=https://www.instagram.com/p/POST_ID/
COMMENT_TEXT=Great post!
csrfsession.js
(cookie method)SESSIONID=123456789%3Aabcdef...
CSRFTOKEN=a1b2c3d4e5f6g7h8i9j0
TARGET_POST_URL=https://www.instagram.com/p/POST_ID/
COMMENT_TEXT=Great post!
# Username/password flow
$ node logincreds.js
# Cookie/session flow
$ node csrfsession.js
Both scripts will:
- Launch headless Chromium with safe flags.
- Validate or establish a logged‑in session.
- Open
TARGET_POST_URL
. - Locate the comment field, type
COMMENT_TEXT
with human‑like delays, press Enter, and wait.
A successful run prints:
Comment posted successfully!
Only needed for
csrfsession.js
. Skip if you are using the username/password script.
- Disable 2FA first: Instagram invalidates the session cookie whenever a 2‑factor challenge is triggered, so temporarily switch it Off: Instagram app -> Settings & Privacy -> Accounts Center -> Password and Security -> Two‑factor authentication.
- Log in to instagram.com in a desktop browser (Chrome is assumed below).
- Press F12 to open DevTools -> Application tab -> left sidebar Storage -> Cookies -> https://www.instagram.com.
- Locate the rows named
sessionid
andcsrftoken
. Double‑click the Value column -> Copy the entire string for each cookie. - Paste both values into
.env
exactly as shown above. Save the file. - Keep the browser session alive while testing. If you log out or the cookies expire (typically 1 month or any time you re-authenticate), grab fresh values.
It is used to reduce repeated logins
On future runs, it loads those cookies to restore the logged-in session without needing to type credentials again.
This saves time and reduces the risk of triggering Instagram's security systems (like 2FA, captchas, or ratelimiting).
Engagement bot
Can be modified with GraphAPI to automate looking for hashtags and comment on it using LLM