How to Auto Accept Facebook Friend Requests in few lines of JavaScript

In this tutorial the presenter explains how he automated the acceptance of a large number of Facebook friend requests using a short JavaScript snippet run directly in the browser console. He begins by describing the problem of manually clicking “Confirm” for hundreds of pending requests, then demonstrates how to inspect the Facebook page’s DOM to locate the specific <span> element that contains the confirm button. He walks through the JavaScript code that collects all span elements, filters those whose text includes the word “confirm”, clicks each matching element, and keeps a counter of accepted requests. The speaker shows how to paste the core part of the script into the console, execute it, and verify the result (e.g., 26 friends auto‑confirmed). He also warns viewers about the risks of running arbitrary console code, advises only developers who understand the script should use it, and notes that the script may need to be re‑run in batches for large request lists. The video ends with a brief recap of the successful automation and an invitation for feedback.
Chapters
All right. Hey guys, how you doing? Hopefully you're doing good. Yeah. So I just wanted to talk about or demonstrate something that I've posted on my Facebook recently. It's about, you know, I recently started receiving a lot of friend requests on Facebook and like in the order of hundreds, and I was having problems just kind of like sitting there all day just tapping confirm, confirm, confirm. Confirm, confirm, and like an ever-ending list of requests. So I was thinking this could be— this should be something already automated somewhere to accept all of it. Maybe, I don't know, maybe Facebook has a feature that you just click accept and accepts everybody, but I haven't seen one yet there. But I figured, you know, since I'm more of like a— I do some coding on the side as well sometimes, or most of the time, you can say that. So why not I guess look up a script that somebody has written already or make one myself or improve one that's already out there. And, you know, just to play around and see what— how we can automate this process instead of sitting there probably taking— you can count maybe a second to click each confirm, you know, that's 100 seconds if you have 100 and you're really good at it and just not even taking a break or anything, just going at it. So I figured, you know, a script could make this easier by just running through it and doing it for you. So I decided to explore that and I'm just here to show you guys what was the outcome of it. So we start with my Facebook friend requests. So I've done a little automation with it already. I'm just kind of playing around with it before I actually show you guys what I did. And this 7 right now, it was way more than this. So just so you know, it was like, I think it was 115 when I started it. So I'm just going to show you guys what I did, how I did it with this remaining ones, and run through the automation process where you guys see what I did. And I'll also show you guys the code. So now you understand the backstory of what I'm trying to do. So let's go to actually see the code that I wrote and maybe I can explain a little bit. So we can go to my Visual Studio Code here. I'll close this terminal. So this is JavaScript code. If you're not familiar with coding, mostly JavaScript is one of the very popular languages. So, and then mostly used to write front-end stuff, whatever you see on the website is mostly coded in JavaScript. So if you look here, this is just a script or a function that, you know, just confirms friend requests, Facebook friend requests. It just goes and finds the friend that I want to accept, which is all of them really, and it just clicks confirm. So this is the code, but let me go back to the page first, the Facebook page, and so you can understand what the code is doing. So you have all this confirm or delete, right? But in my case, I just want to confirm all of this, all of these guys here. I just want to confirm them and make them my friends. So the first thing we're going to do is inspect where, you know, where do you see this confirm? Where did you see this confirm button? And I might actually want to do it on— because this is Brave, I might want to do it on Chrome, but it doesn't matter. We'll do the shout here. It doesn't work out, open it on Chrome. We just want to make sure we find where this confirm button is. So this confirm button is under this span tag. There's so many tags— these div tags, they span, there's so many of them. So you just want to find the one that I guess is in charge of the confirmation so that you can tell your script, hey, go here, go find this div which is host to confirm, and then from there just click. On it, and it does the confirmation for you instead of you clicking on them manually. You send the code to go do the work for you. So there's so many div tags, and you can see all these div tags represent each one of the friends that want to be— or the people that want to be my friends. This last div tag is the last friend request I received, all the way up to the— 10. The recent, I think. Yes. Oh, not that recent. Yeah, that's the recent one. And then so this div tag covers all of them, but these div tags— and if you click on each one of them, it will show you the elements. Like it breaks down from the person to the picture itself. You can, you can grab the picture you want, like just a photo. Uh, yeah, that— this div tag right here grabs the photo. And if you go to this one, it You know, it keeps going down. If you want to be really into it, it kind of breaks it down to the point where until you find confirm. So this one grabs the name and this one grabs both, both the delete and confirm, but we don't want to do delete right now for this sake. So this one, you figure out this one is the one that does the confirm and you keep going. Iterating through it until you find the span class. And this is the one I believe that holds it. Yep, so this is the span class that holds the confirm, and this is the confirm. This is what we're looking for right here, this confirm right here. So this is the one we're looking for. So we've got to tell our code to go find the span class, and if it's the span class— because there's so many of them— but if the span class contains confirm within the spam, then this is the one we're looking for. Then if you find that, just click and boom, we made friends. So that's what we're trying to do with this. We're just sending code to scour through all this and do it for us. And we're gonna— once we have the script that we want to deploy, this is where we'll deploy it. So we'll put it here and run it, and it's going to run it and, you know, give us our new friends. But here's a word of caution out there, um, and this applies to most anything that you're going to put here in the console. You know, this warning is mostly for— and it says clearly there, this browser feature is intended for developers. If you're not a developer, this can be a little scary because you're like, okay, well, I'm about to break something for sure. And you can. And some of the code that you get and, you know, people are like, hey, you might want to put the code there, then it might be malicious code and they might want to maybe hack your account or do stuff like that. So you might You might want to refrain from doing it unless you're a developer, you know what you're doing, you've looked through the code, you're sure this code doesn't do anything malicious, then boom, then you run it, you know, or not. So you understand what to do now. Let's— I guess you understand what I'm trying to do. So let's go back to the code that I want to run. So this is the code. So basically what this code is doing is, you know, it's, it's I've instantiated these variables. This is just going to be a counter. It's going to hold a count of how many friends we have accepted. It's going to count as we accept them as we go. And this spans is this span right here that I was referring to earlier. So this is the span right here that holds the confirm. This is what I'm talking about. So, oops. So in this case, This span, uh, this span, this variable spans is going to go through the entire your Facebook page of friends and it's going to try to find the span. It's going to grab all the spans basically and put it under this span variable. You can think of this variable as just like a container and you're just putting stuff in and closing it, and then you open it when you need to take it out or something like that. I try to think of it that way. But, um, then after that you have all this spans stored there. Then what you tell— what you do here is come and loop through this, basically open the can, and you start going through the can, the contents inside the can, or inside the drum if you want to call it drum, basket, whatever. So you start going through each stuff in there, and you're just trying to make sure that, you know, whatever is, is, is in this, is in this container, the spans here, um, which this code is doing right here. So it's This code is just converting— take each and every span in the container and convert them to lowercase. And it just makes it easier for us to go through the— check the values within the code itself. And then once we make them all of them lowercase, um, we come back and, um, check, you know, if span tag has the word confirm, then this is the target we're looking for. Like, like I said again, if If this span right here, if this span, because there's so many spans, right? Like we saw. But, and that container is going to grab all the spans, but we're looking for the span that has the word confirm in it. And this is the confirm we're looking for. So in this code right here, what it does here is it looks, you know, if, if everything in the container contains, which we've already put in lowercase, even if it contains the word confirm Then this is the action that we need to do. So it will basically— it stores everything that has the word confirm. So it sorts through the spans, and if it has a confirm, it will store it on the i position, which is the i position, the position of the confirm. within the code itself or span. So once we do that, we come here. So if the number that we stored up here within the iPos here, in the iPosition, if it's greater than -1, which means that the word confirm was found. If it has more than 1, it means it was found. So if it's greater than 1, then what it does is it clicks to confirm or accept the friend request. So if we found the confirm, then— Click. Where's that? Just click it and accept all the friends, right? So start accepting each one. But as we accept them, as well as we accept each one of them— so this means this i just means each one of them. So as you accept each one of them from the drum, just it keeps track of how many have we accepted. So it clicks exactly just one, then click the next one. Yeah, you know, increment the counter, which is up here. Increment the counter until we finish all of them. And then once we've finished all of this— I used the friends in there and just let us know how many of the friends you've accepted. And that's really it. Um, but one thing I also noticed when I was doing that, like when it was a lot of them, like hundreds, it was doing by batches. So I had to rerun the code several times to make sure that I capture everybody. So, um, but with this 7 here, I am optimistic that it's gonna do it pretty quick. Uh, I do want you to want it to run through, like, for me to run several times. But we'll see, you know, it's never guaranteed. So what I can do is the, the code that we need is just this right here, the middle part, if you're running it on that console. So you don't need this, the function itself, uh, and this. So you leave the function and the first bracket and the last curly bracket. So all we need is just whatever is inside this code. So you can copy that. And bring it here to the console and just paste that in there. And we'll just run it from here and see what it does. Boom! All right, there you go. It says I've auto-confirmed this many friends, 26. I don't know where it got the rest of them, but it worked. So let's just go back and check how many friends— if we still have any pending friend requests. That's how you know if it's already done it. Friends. Um, it might have kept the count from the previous ones. Friend request. Now we don't have any friend requests. Boom, look at that. That's 7. It could have taken us a long time. Maybe not, but it would have taken us a longer time using, um, just clicking it individually. So it did the work. It will show you some errors here, of course, but this Involves some stuff with Chrome. Um, there's workarounds around this one, but it's, it's good warnings, so you might want to just keep them. Um, but it's, it's a little complicated for a regular, a regular person because you won't really need much of this. But yeah, let me know, let me know what you think. Let me know, you know, there's definitely people that are more experienced than I am, so let me know. If you like this and enjoy this stuff, let me know as well, uh, or not. But that's just how I did it. Um, it worked for me. This is the first time I tried it. It worked. Um, very effective. Probably wouldn't use it every day, but cool. Thank you. See you guys.
More from Tony

Summarize Videos and Research Companies with CrewAI + Gemini Models [Quickstart Guide]

How to Make Your AI Agents More Reliable with CrewAI Task Guardrails (Step-by-Step Tutorial)








