@ubaidbinwaris/linkedin 1.0.10 → 1.0.12
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 +80 -15
package/package.json
CHANGED
package/src/login/login.js
CHANGED
|
@@ -177,23 +177,49 @@ async function loginToLinkedIn(options = {}, credentials = null) {
|
|
|
177
177
|
return false;
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
if (simpleResolved) {
|
|
181
|
+
logger.info("Clicked a resolution button. Waiting to see if it clears...");
|
|
182
|
+
await randomDelay(2000, 4000);
|
|
183
|
+
if (!(await detectCheckpoint(page))) {
|
|
184
|
+
logger.info("Checkpoint resolved headlessly! Proceeding...");
|
|
185
|
+
try {
|
|
186
|
+
await page.waitForURL("**/feed**", { timeout: 10000 });
|
|
187
|
+
return { browser, context, page };
|
|
188
|
+
} catch (e) {
|
|
189
|
+
logger.warn("Resolved checkpoint but feed did not load. Continuing...");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
// Check for Mobile Verification ("Open your LinkedIn app")
|
|
194
|
+
const isMobileVerif = await page.evaluate(() => {
|
|
195
|
+
const text = document.body.innerText;
|
|
196
|
+
return text.includes("Open your LinkedIn app") ||
|
|
197
|
+
text.includes("Tap Yes on the prompt") ||
|
|
198
|
+
text.includes("verification request to your device");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
if (isMobileVerif) {
|
|
202
|
+
logger.info("Mobile verification detected (Open App / Tap Yes).");
|
|
203
|
+
logger.info("Waiting 2 minutes for you to approve on your device...");
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
// Poll for feed URL for 120 seconds
|
|
207
|
+
await page.waitForFunction(() => {
|
|
208
|
+
return window.location.href.includes("/feed") ||
|
|
209
|
+
document.querySelector('.global-nav__search');
|
|
210
|
+
}, { timeout: 120000 });
|
|
211
|
+
|
|
212
|
+
logger.info("Mobile verification successful! Resuming...");
|
|
213
|
+
return { browser, context, page };
|
|
214
|
+
} catch (err) {
|
|
215
|
+
logger.warn("Mobile verification timed out. Falling back to visible mode.");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
192
218
|
}
|
|
219
|
+
} catch (err) {
|
|
220
|
+
logger.warn(`Failed to auto-resolve checkpoint: ${err.message}`);
|
|
193
221
|
}
|
|
194
|
-
|
|
195
|
-
logger.warn(`Failed to auto-resolve checkpoint: ${err.message}`);
|
|
196
|
-
}
|
|
222
|
+
|
|
197
223
|
|
|
198
224
|
if (options.onCheckpoint && typeof options.onCheckpoint === 'function') {
|
|
199
225
|
logger.info("Triggering onCheckpoint callback...");
|
|
@@ -304,6 +330,45 @@ async function loginToLinkedIn(options = {}, credentials = null) {
|
|
|
304
330
|
if (launchOptions.headless) {
|
|
305
331
|
logger.warn("Checkpoint detected in headless mode (post-login).");
|
|
306
332
|
|
|
333
|
+
// Attempt to resolve simple checkpoints (e.g. "Yes, it's me", "Skip") automatically
|
|
334
|
+
try {
|
|
335
|
+
logger.info("Attempting to resolve simple checkpoint headlessly (post-login)...");
|
|
336
|
+
const simpleResolved = await page.evaluate(async () => {
|
|
337
|
+
// Find buttons, links, or elements with button role
|
|
338
|
+
const candidates = Array.from(document.querySelectorAll('button, a, [role="button"], input[type="submit"], input[type="button"]'));
|
|
339
|
+
const targetText = ['Yes', 'Skip', 'Not now', 'Continue', 'Sign in', 'Verify', 'Let’s do it', 'Next'];
|
|
340
|
+
|
|
341
|
+
// Find a candidate with one of these texts
|
|
342
|
+
const btn = candidates.find(b => {
|
|
343
|
+
const text = (b.innerText || b.value || '').trim();
|
|
344
|
+
return targetText.some(t => text.includes(t));
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
if (btn) {
|
|
348
|
+
btn.click();
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
return false;
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
if (simpleResolved) {
|
|
355
|
+
logger.info("Clicked a resolution button. Waiting to see if it clears...");
|
|
356
|
+
await randomDelay(2000, 4000);
|
|
357
|
+
if (!(await detectCheckpoint(page))) {
|
|
358
|
+
logger.info("Checkpoint resolved headlessly! Proceeding...");
|
|
359
|
+
// Re-verify session
|
|
360
|
+
try {
|
|
361
|
+
await page.waitForURL("**/feed**", { timeout: 10000 });
|
|
362
|
+
return { browser, context, page };
|
|
363
|
+
} catch (e) {
|
|
364
|
+
logger.warn("Resolved checkpoint but feed did not load. Continuing...");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
} catch (err) {
|
|
369
|
+
logger.warn(`Failed to auto-resolve post-login checkpoint: ${err.message}`);
|
|
370
|
+
}
|
|
371
|
+
|
|
307
372
|
if (options.onCheckpoint && typeof options.onCheckpoint === 'function') {
|
|
308
373
|
logger.info("Triggering onCheckpoint callback...");
|
|
309
374
|
await options.onCheckpoint();
|