@ubaidbinwaris/linkedin 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/login/login.js +83 -7
package/package.json
CHANGED
package/src/login/login.js
CHANGED
|
@@ -101,17 +101,92 @@ async function performCredentialLogin(page, email, password) {
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
async function handleCheckpoint(page, options) {
|
|
104
|
+
// Initial check
|
|
104
105
|
if (!(await detectCheckpoint(page))) return;
|
|
105
106
|
|
|
107
|
+
logger.warn("Checkpoint detected.");
|
|
108
|
+
|
|
106
109
|
if (options.headless) {
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
logger.info("Headless mode detected. Attempting auto-resolution...");
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------
|
|
113
|
+
// STRATEGY 1: Click Simple Buttons (Yes, Skip, Continue)
|
|
114
|
+
// ---------------------------------------------------------
|
|
115
|
+
try {
|
|
116
|
+
const clicked = await page.evaluate(() => {
|
|
117
|
+
const candidates = Array.from(document.querySelectorAll('button, a, [role="button"], input[type="submit"], input[type="button"]'));
|
|
118
|
+
const targetText = ['Yes', 'Skip', 'Not now', 'Continue', 'Sign in', 'Verify', 'Let’s do it', 'Next'];
|
|
119
|
+
|
|
120
|
+
const btn = candidates.find(b => {
|
|
121
|
+
const text = (b.innerText || b.value || '').trim();
|
|
122
|
+
return targetText.some(t => text.includes(t));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (btn) {
|
|
126
|
+
btn.click();
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (clicked) {
|
|
133
|
+
logger.info("Clicked a resolution button. Waiting for navigation...");
|
|
134
|
+
await page.waitForTimeout(3000);
|
|
135
|
+
|
|
136
|
+
// Check if resolved
|
|
137
|
+
if (!(await detectCheckpoint(page))) {
|
|
138
|
+
logger.info("Checkpoint resolved via button click!");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} catch (e) {
|
|
143
|
+
logger.warn(`Auto-resolve button click failed: ${e.message}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ---------------------------------------------------------
|
|
147
|
+
// STRATEGY 2: Mobile App Verification (Wait & Poll)
|
|
148
|
+
// ---------------------------------------------------------
|
|
149
|
+
try {
|
|
150
|
+
const isMobileVerif = await page.evaluate(() => {
|
|
151
|
+
const text = document.body.innerText;
|
|
152
|
+
return text.includes("Open your LinkedIn app") ||
|
|
153
|
+
text.includes("Tap Yes on the prompt") ||
|
|
154
|
+
text.includes("verification request to your device");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (isMobileVerif) {
|
|
158
|
+
logger.info("Mobile verification detected. Waiting 2 minutes for manual approval on device...");
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
// Poll for feed URL for 120 seconds
|
|
162
|
+
// We use a loop or waitForFunction
|
|
163
|
+
await page.waitForFunction(() => {
|
|
164
|
+
return window.location.href.includes("/feed") ||
|
|
165
|
+
document.querySelector('.global-nav__search');
|
|
166
|
+
}, { timeout: 120000 });
|
|
167
|
+
|
|
168
|
+
logger.info("Mobile verification successful! Resuming...");
|
|
169
|
+
return;
|
|
170
|
+
} catch (timeoutErr) {
|
|
171
|
+
logger.warn("Mobile verification timed out.");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} catch (e) {
|
|
175
|
+
logger.warn(`Mobile verification check failed: ${e.message}`);
|
|
176
|
+
}
|
|
109
177
|
|
|
110
|
-
|
|
178
|
+
// Re-check after attempts
|
|
179
|
+
if (await detectCheckpoint(page)) {
|
|
180
|
+
throw new Error("Checkpoint detected in headless mode and auto-resolution failed.");
|
|
181
|
+
}
|
|
111
182
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
183
|
+
} else {
|
|
184
|
+
// Visible mode
|
|
185
|
+
logger.warn("Verification required. Please complete manually.");
|
|
186
|
+
await waitForUserResume(
|
|
187
|
+
"Complete verification in browser, then press ENTER..."
|
|
188
|
+
);
|
|
189
|
+
}
|
|
115
190
|
}
|
|
116
191
|
|
|
117
192
|
async function detectCheckpoint(page) {
|
|
@@ -120,7 +195,8 @@ async function detectCheckpoint(page) {
|
|
|
120
195
|
return (
|
|
121
196
|
url.includes("checkpoint") ||
|
|
122
197
|
url.includes("challenge") ||
|
|
123
|
-
url.includes("verification")
|
|
198
|
+
url.includes("verification") ||
|
|
199
|
+
url.includes("consumer-login/error")
|
|
124
200
|
);
|
|
125
201
|
}
|
|
126
202
|
|