@ubaidbinwaris/linkedin 1.1.5 → 1.1.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubaidbinwaris/linkedin",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -54,6 +54,8 @@ async function handleMobileVerification(page) {
54
54
 
55
55
  try {
56
56
  // Poll for feed URL for 120 seconds
57
+ // Note: If navigation happens (user approves), this might throw "Execution context was destroyed"
58
+ // We handle that in the catch block by checking the URL.
57
59
  await page.waitForFunction(() => {
58
60
  return window.location.href.includes("/feed") ||
59
61
  document.querySelector('.global-nav__search');
@@ -61,8 +63,16 @@ async function handleMobileVerification(page) {
61
63
 
62
64
  logger.info("Mobile verification successful! Resuming...");
63
65
  return true; // Resolved
64
- } catch (timeoutErr) {
65
- logger.warn("Mobile verification timed out (No approval detected).");
66
+ } catch (err) {
67
+ // Check if we actually succeeded via navigation
68
+ try {
69
+ if (page.url().includes("/feed")) {
70
+ logger.info("Mobile verification successful (detected via navigation)! Resuming...");
71
+ return true;
72
+ }
73
+ } catch(e) {}
74
+
75
+ logger.warn(`Mobile verification wait ended: ${err.message}`);
66
76
  return false;
67
77
  }
68
78
 
@@ -72,6 +72,15 @@ async function loginToLinkedIn(options = {}, credentials = null) {
72
72
  // If it returns true, it means we are now on the feed (resolved)
73
73
  if (await handleMobileVerification(page)) {
74
74
  // success, assume logged in
75
+ // Wait a moment for page to settle
76
+ await page.waitForTimeout(3000);
77
+
78
+ // Double check if we are really on feed
79
+ if (page.url().includes("/feed") || await isLoggedIn(page)) {
80
+ logger.info(`[${email}] Mobile Verification Successful ✅`);
81
+ await saveSession(context, email, true);
82
+ return { browser, context, page };
83
+ }
75
84
  } else {
76
85
  // Failed mobile verification.
77
86
  // User Request: "otherwise after some delay using browser opens the browser and fill the form"
@@ -92,9 +101,20 @@ async function loginToLinkedIn(options = {}, credentials = null) {
92
101
 
93
102
  // Now wait for success (Feed)
94
103
  logger.info("[Fallback] Waiting for user to complete login manually...");
95
- await visiblePage.waitForSelector(".global-nav__search", { timeout: 120000 });
96
104
 
97
- if (await isLoggedIn(visiblePage)) {
105
+ // Wait for URL OR Selector
106
+ // We loop to check both condition
107
+ try {
108
+ await visiblePage.waitForFunction(() => {
109
+ return window.location.href.includes("/feed") ||
110
+ document.querySelector(".global-nav__search");
111
+ }, { timeout: 120000 });
112
+ } catch(e) {
113
+ logger.warn(`[Fallback] Wait finished with error: ${e.message}`);
114
+ }
115
+
116
+ // Double check status
117
+ if (visiblePage.url().includes("/feed") || await isLoggedIn(visiblePage)) {
98
118
  logger.info(`[${email}] Manual Fallback Successful ✅`);
99
119
  await saveSession(visibleContext, email, true);
100
120
  return { browser: visibleBrowser, context: visibleContext, page: visiblePage };