@ubaidbinwaris/linkedin 1.0.7 → 1.0.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/login/login.js +37 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubaidbinwaris/linkedin",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -156,17 +156,42 @@ async function loginToLinkedIn(options = {}, credentials = null) {
156
156
  if (launchOptions.headless) {
157
157
  logger.warn("Checkpoint detected in headless mode.");
158
158
 
159
+ // Attempt to resolve simple checkpoints (e.g. "Yes, it's me", "Skip") automatically
160
+ try {
161
+ logger.info("Attempting to resolve simple checkpoint headlessly...");
162
+ const simpleResolved = await page.evaluate(async () => {
163
+ const buttons = Array.from(document.querySelectorAll('button'));
164
+ const targetText = ['Yes', 'Skip', 'Not now', 'Continue', 'Sign in'];
165
+ // Find a button with one of these texts
166
+ const btn = buttons.find(b => targetText.some(t => b.innerText.includes(t)));
167
+ if (btn) {
168
+ btn.click();
169
+ return true;
170
+ }
171
+ return false;
172
+ });
173
+
174
+ if (simpleResolved) {
175
+ logger.info("Clicked a resolution button. Waiting to see if it clears...");
176
+ await randomDelay(2000, 4000);
177
+ if (!(await detectCheckpoint(page))) {
178
+ logger.info("Checkpoint resolved headlessly! Proceeding...");
179
+ // Re-verify session
180
+ try {
181
+ await page.waitForURL("**/feed**", { timeout: 10000 });
182
+ return { browser, context, page };
183
+ } catch (e) {
184
+ logger.warn("Resolved checkpoint but feed did not load. Continuing...");
185
+ }
186
+ }
187
+ }
188
+ } catch (err) {
189
+ logger.warn(`Failed to auto-resolve checkpoint: ${err.message}`);
190
+ }
191
+
159
192
  if (options.onCheckpoint && typeof options.onCheckpoint === 'function') {
160
193
  logger.info("Triggering onCheckpoint callback...");
161
194
  await options.onCheckpoint();
162
- // We assume the callback resolves when the user has taken action (e.g. solved via visible browser)
163
- // But here we need to know what to do next.
164
- // If the user solved it in a *different* browser/session, we might need to reload.
165
- // For now, let's assume the callback handles the visible switch logic we implemented before,
166
- // OR validates externally.
167
- // However, to keep it simple and compatible with our previous logic:
168
- // If onCheckpoint is provided, we await it, then close this browser and retry (assuming session saved).
169
-
170
195
  logger.info("onCheckpoint resolved. Retrying login...");
171
196
  await browser.close();
172
197
  return loginToLinkedIn(options, credentials);
@@ -174,7 +199,8 @@ async function loginToLinkedIn(options = {}, credentials = null) {
174
199
 
175
200
  logger.info("Switching to visible mode for manual verification...");
176
201
 
177
- await waitForUserResume("Press ENTER to open a visible browser to verify your account...");
202
+ // await waitForUserResume("Press ENTER to open a visible browser to verify your account...");
203
+ logger.info("Automatically launching visible browser for verification...");
178
204
 
179
205
  logger.info("Closing headless browser...");
180
206
  await browser.close();
@@ -282,7 +308,8 @@ async function loginToLinkedIn(options = {}, credentials = null) {
282
308
 
283
309
  logger.info("Switching to visible mode for manual verification...");
284
310
 
285
- await waitForUserResume("Press ENTER to open a visible browser to verify your account...");
311
+ // await waitForUserResume("Press ENTER to open a visible browser to verify your account...");
312
+ logger.info("Automatically launching visible browser for verification...");
286
313
 
287
314
  logger.info("Closing headless browser...");
288
315
  await browser.close();