Skip to content

Commit

Permalink
connection request error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranork committed Jun 19, 2024
1 parent 4e0af93 commit 45e1d1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-linkedin",
"version": "1.1.3",
"version": "1.1.4",
"description": "Auto LinkedIn is a project that provides automation for LinkedIn using Node.js and Puppeteer. This project helps you save time by automating various tasks on LinkedIn.",
"main": "src/main.js",
"scripts": {
Expand Down
20 changes: 10 additions & 10 deletions src/controllers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class LinkedinProfile {
* @param {boolean} scrollPage - Scroll page to bottom to be sure (default: true)
*/
async visitProfile(linkedinClient, waitMs, scrollPage = true) {
if (!waitMs) waitMs = randomNumber(linkedinClient.linkedinSettings.COOLDOWN_MIN, linkedinClient.linkedinSettings.COOLDOWN_MAX)
if (!waitMs) waitMs = randomNumber(linkedinClient.linkedinSettings.COOLDOWN_MIN * 1000, linkedinClient.linkedinSettings.COOLDOWN_MAX * 1000)

console.log('[TASK] LinkedinProfile Visit: ' + this.details.name + ' (waitMs: ' + waitMs.toFixed(2) + ', scrollPage: ' + scrollPage + ')');
console.log('[TASK] LinkedinProfile Visit: ' + this.details.name + ' (waitMs: ' + waitMs.toFixed(0) + ', scrollPage: ' + scrollPage + ')');
const browser = await linkedinClient.getBrowser()
const page = await browser.newPage()
await page.goto(linkedinClient.linkedinSettings.MAIN_ADDRESS + 'in/' + this.details.id)
Expand Down Expand Up @@ -61,14 +61,14 @@ class LinkedinProfile {
* @param {string} connectionMessage - Message that will send with connection request
*/
async connectionRequest(linkedinClient, connectionMessage, waitMs) {
if (!waitMs) waitMs = randomNumber(linkedinClient.linkedinSettings.COOLDOWN_MIN, linkedinClient.linkedinSettings.COOLDOWN_MAX)
console.log('[TASK] Conection request: ' + this.details.name + ' (waitMs: ' + waitMs.toFixed(2) + ')');
if (!waitMs) waitMs = randomNumber(linkedinClient.linkedinSettings.COOLDOWN_MIN * 1000, linkedinClient.linkedinSettings.COOLDOWN_MAX * 1000)
console.log('[TASK] Conection request: ' + this.details.name + ' (waitMs: ' + waitMs.toFixed(0) + ')');

const browser = await linkedinClient.getBrowser()
const page = await browser.newPage()
await page.goto(linkedinClient.linkedinSettings.MAIN_ADDRESS + 'in/' + this.details.id)

await page.waitForSelector('.scaffold-layout__main > section > div:nth-child(2) > div:last-child > div > button')
await page.waitForSelector('.scaffold-layout__main > section > div:nth-child(2) > div > div > button')

let buttonText = await page.evaluate(async () => {
await new Promise(r => setTimeout(r, 500));
Expand All @@ -83,7 +83,7 @@ class LinkedinProfile {
const firstButtonisMessage = (buttonText === linkedinClient.linkedinSettings.PROFILEBUTTON_MESSAGE)
if (firstButtonisMessage) {
await page.close()
return console.log(' Already connected to ' + this.details.name + ' (' + this.details.id + ')')
throw new Error(' Already connected or connection already sent.')
}

const firstButtonisConnect = (buttonText === linkedinClient.linkedinSettings.PROFILEBUTTON_CONNECT)
Expand All @@ -110,18 +110,18 @@ class LinkedinProfile {

await new Promise(r => setTimeout(r, waitMs));
await page.close()
return console.log(' Connection request send to ' + this.details.name + ' (' + this.details.id + ')')
return console.log(' Connection request sent.')
}

const firstButtonisFollow = (buttonText === linkedinClient.linkedinSettings.PROFILEBUTTON_FOLLOW)
if (firstButtonisFollow) {
let moreButtonQuery = '.scaffold-layout__main > section > div:nth-child(2) > div:last-child > div > div:last-child > button'
let moreButtonQuery = '.scaffold-layout__main > section > div:nth-child(2) > div > div > .artdeco-dropdown'
await page.waitForSelector(moreButtonQuery)
await page.click(moreButtonQuery)

await new Promise(r => setTimeout(r, 500));

let connectButtonQuery = '.scaffold-layout__main > section > div:nth-child(2) > div:last-child > div > div:last-child > div > div > ul > li:nth-child(3) > div'
let connectButtonQuery = '.scaffold-layout__main > section > div:nth-child(2) > div > div > div:last-child > div > div > ul > li:nth-child(3) > div'
await page.waitForSelector(connectButtonQuery);
await page.click(connectButtonQuery);

Expand All @@ -142,7 +142,7 @@ class LinkedinProfile {

await new Promise(r => setTimeout(r, waitMs));
await page.close()
return console.log(' Connection request send to ' + this.details.name + ' (' + this.details.id + ')')
return console.log(' Connection request sent.')
}

}
Expand Down

0 comments on commit 45e1d1b

Please sign in to comment.