Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

579
Views
Chrome Console Script broken: Uncaught TypeError: Cannot read properties of undefined (reading 'push')

I'm using the following code on Instagram follow request page to open each user in a new tab and then unfollow it.

https://www.instagram.com/accounts/access_tool/current_follow_requests

 var i=0;  
 var unfollow="global";  
 var final="global";  
 var link=["link","link2"];  
 var proWindow=[""]  
 proWindow.length=0  
 link.length=0;  
 var ids = document.querySelectorAll(".-utLf");  
 for(i=0;i<ids.length;i++){  
   link.push('https://www.instagram.com/'+ids[i].innerText+'/');  
      console.log(link[i]);  
      proWindow[i]=window.open(link[i]);  
 }  

and then the following code to unfollow each user:

for(i=0;i<ids.length;i++){
 unfollow = proWindow[i].document.querySelector("button.sqdOP");
 unfollow.click();
 await new Promise(resolve => setTimeout(resolve, 1000));
 final = proWindow[i].document.querySelector(".aOOlW");
 final.click();}
console.log("Completed");  

however, I'm seeing the following error on the console Uncaught TypeError: Cannot read properties of undefined (reading 'push')

This preivously used to work fine but now is showing this error.

What change needs to be done to fix this code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This error originates from trying to push something undefined to an array. That could happend if the nodelist returned by the queryselector contains something with an undefined innertext for some reason.

This should work better:

if (ids[i].innerText){ // To check if the value is undefined
    link.push('https://www.instagram.com/'+ids[i].innerText+'/');  
    console.log(link[i]);  
    proWindow[i]=window.open(link[i]);    
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!