Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to accept all pending connection requests on LinkedIn using JavaScript?
To accept all pending connection requests on LinkedIn using JavaScript, you would need to use the LinkedIn API and an automation tool. The script would need to navigate to the connection request page and loop through each request, clicking the accept button for each one.
This is a very common issue for people who are moderately to highly active on LinkedIn. They get many connection requests every day and must manually click on accept against each request to actually accept them.
You can, however make use of JavaScript and the window console to automate this whole process and we will be covering the same today in this article.
Steps to Access Browser Console
The idea here is:
Log into your LinkedIn account in any modern web browser like Chrome, Firefox on a computer.
Navigate to your pending connection requests page.
Right click anywhere on the screen and click on the inspect button.
The Developer tools window will open, now look for the console tab and click on it.
Now at the very bottom in this console tab, we can write our own JS code that will get executed for the current window.
JavaScript Code to Accept All Requests
Here is the code snippet that you will need to execute in order to accept all pending connection requests:
const acceptButtonClassName = '.invitation-card__action-btn.artdeco-button--secondary';
const pendingConnections = document.querySelectorAll(acceptButtonClassName);
console.log(`Total requests: ${pendingConnections.length}`);
for (let currentIndex = 0; currentIndex < pendingConnections.length; currentIndex++) {
console.log(`Now accepting request ${currentIndex + 1}/${pendingConnections.length}`);
pendingConnections[currentIndex].click();
}
Understanding the Code
What this code essentially does is:
It defines a variable acceptButtonClassName which holds the CSS selector for the accept buttons that is common to all accept buttons and is not shared by any other element inside the DOM.
Then our code selects all the DOM elements (essentially all the accept buttons) using the document.querySelectorAll function.
And at the very end, we loop over each accept button, trigger the click function for each accept button and therefore accept each request.
Example Output
When you run this script, you'll see output in the console showing the progress:
Total requests: 5 Now accepting request 1/5 Now accepting request 2/5 Now accepting request 3/5 Now accepting request 4/5 Now accepting request 5/5
Note: The output might vary for everyone based on the number of pending connection requests they have.
Important Considerations
LinkedIn's Terms of Service: Be aware that automating actions on LinkedIn may violate their terms of service.
Rate Limiting: LinkedIn may detect and block rapid automated actions.
Class Names: LinkedIn may change their CSS class names, which could break this script.
Use Responsibly: Only accept requests from people you genuinely want to connect with.
Alternative Approach with Delay
To make the automation less detectable, you can add delays between clicks:
const acceptButtonClassName = '.invitation-card__action-btn.artdeco-button--secondary';
const pendingConnections = document.querySelectorAll(acceptButtonClassName);
console.log(`Total requests: ${pendingConnections.length}`);
let currentIndex = 0;
const acceptWithDelay = () => {
if (currentIndex < pendingConnections.length) {
console.log(`Now accepting request ${currentIndex + 1}/${pendingConnections.length}`);
pendingConnections[currentIndex].click();
currentIndex++;
setTimeout(acceptWithDelay, 1000); // 1 second delay
}
};
acceptWithDelay();
Conclusion
This JavaScript automation can save time when managing multiple LinkedIn connection requests. However, use it responsibly and be aware of LinkedIn's terms of service and potential rate limiting measures.
