@ubaidbinwaris/linkedin 1.0.9 → 1.0.11
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 +49 -4
- package/src/utils/logger.js +1 -0
package/package.json
CHANGED
package/src/login/login.js
CHANGED
|
@@ -160,10 +160,16 @@ async function loginToLinkedIn(options = {}, credentials = null) {
|
|
|
160
160
|
try {
|
|
161
161
|
logger.info("Attempting to resolve simple checkpoint headlessly...");
|
|
162
162
|
const simpleResolved = await page.evaluate(async () => {
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
// Find buttons, links, or elements with button role
|
|
164
|
+
const candidates = Array.from(document.querySelectorAll('button, a, [role="button"], input[type="submit"], input[type="button"]'));
|
|
165
|
+
const targetText = ['Yes', 'Skip', 'Not now', 'Continue', 'Sign in', 'Verify', 'Let’s do it', 'Next'];
|
|
166
|
+
|
|
167
|
+
// Find a candidate with one of these texts
|
|
168
|
+
const btn = candidates.find(b => {
|
|
169
|
+
const text = (b.innerText || b.value || '').trim();
|
|
170
|
+
return targetText.some(t => text.includes(t));
|
|
171
|
+
});
|
|
172
|
+
|
|
167
173
|
if (btn) {
|
|
168
174
|
btn.click();
|
|
169
175
|
return true;
|
|
@@ -298,6 +304,45 @@ async function loginToLinkedIn(options = {}, credentials = null) {
|
|
|
298
304
|
if (launchOptions.headless) {
|
|
299
305
|
logger.warn("Checkpoint detected in headless mode (post-login).");
|
|
300
306
|
|
|
307
|
+
// Attempt to resolve simple checkpoints (e.g. "Yes, it's me", "Skip") automatically
|
|
308
|
+
try {
|
|
309
|
+
logger.info("Attempting to resolve simple checkpoint headlessly (post-login)...");
|
|
310
|
+
const simpleResolved = await page.evaluate(async () => {
|
|
311
|
+
// Find buttons, links, or elements with button role
|
|
312
|
+
const candidates = Array.from(document.querySelectorAll('button, a, [role="button"], input[type="submit"], input[type="button"]'));
|
|
313
|
+
const targetText = ['Yes', 'Skip', 'Not now', 'Continue', 'Sign in', 'Verify', 'Let’s do it', 'Next'];
|
|
314
|
+
|
|
315
|
+
// Find a candidate with one of these texts
|
|
316
|
+
const btn = candidates.find(b => {
|
|
317
|
+
const text = (b.innerText || b.value || '').trim();
|
|
318
|
+
return targetText.some(t => text.includes(t));
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
if (btn) {
|
|
322
|
+
btn.click();
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
return false;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
if (simpleResolved) {
|
|
329
|
+
logger.info("Clicked a resolution button. Waiting to see if it clears...");
|
|
330
|
+
await randomDelay(2000, 4000);
|
|
331
|
+
if (!(await detectCheckpoint(page))) {
|
|
332
|
+
logger.info("Checkpoint resolved headlessly! Proceeding...");
|
|
333
|
+
// Re-verify session
|
|
334
|
+
try {
|
|
335
|
+
await page.waitForURL("**/feed**", { timeout: 10000 });
|
|
336
|
+
return { browser, context, page };
|
|
337
|
+
} catch (e) {
|
|
338
|
+
logger.warn("Resolved checkpoint but feed did not load. Continuing...");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} catch (err) {
|
|
343
|
+
logger.warn(`Failed to auto-resolve post-login checkpoint: ${err.message}`);
|
|
344
|
+
}
|
|
345
|
+
|
|
301
346
|
if (options.onCheckpoint && typeof options.onCheckpoint === 'function') {
|
|
302
347
|
logger.info("Triggering onCheckpoint callback...");
|
|
303
348
|
await options.onCheckpoint();
|
package/src/utils/logger.js
CHANGED
|
@@ -21,6 +21,7 @@ const defaultLogger = winston.createLogger({
|
|
|
21
21
|
transports: [
|
|
22
22
|
new winston.transports.File({ filename: path.join(logDir, "error.log"), level: "error" }),
|
|
23
23
|
new winston.transports.File({ filename: path.join(logDir, "combined.log") }),
|
|
24
|
+
new winston.transports.Console() // Output to console
|
|
24
25
|
],
|
|
25
26
|
});
|
|
26
27
|
|