ilml-plugin-linkedin 1.14.4 → 1.14.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.14.5
4
+ - **`connect run` no longer counts people you're already connected to as failed sends.** It now recognises them and skips them cleanly, so a run isn't stopped early by false failures.
5
+
3
6
  ## 1.14.4
4
7
  - **`connect run` now recognises people you're already connected to (or already have a pending request with) and skips them cleanly — instead of logging a false failure.** When a queued person is already a 1st-degree connection, their profile shows "Message" and no "Connect" — but the "More profiles for you" sidebar has its own Connect controls, which made connect think a Connect button was still present, miss that you're already connected, and record a `button_not_found` "failure". The already-connected / already-pending check now ignores that sidebar and reads only the open profile, so such entries are marked **skipped (already connected)** instead of failed: they don't count toward the "3 failures in a row" safety stop and don't burn quota. It stays conservative about writing anything back to your contacts — a real send is recorded, but a merely-inferred "already connected" only refreshes a person you already have, it won't invent a connection for an unknown profile (the source of truth for who you're connected to remains `sync`). Net effect — the failure list holds only real problems. Same root cause as 1.14.3 (recommendation-sidebar bleed), applied to status detection. No schema change.
5
8
 
package/dist/connect.mjs CHANGED
@@ -236,7 +236,7 @@ function findEntryContainer(root) {
236
236
  return candidates[0]?.el;
237
237
  }
238
238
  `});var kn={};de(kn,{clickConnectButton:()=>_t,default:()=>Er,detectConnectionStatus:()=>Ae,findConnectButton:()=>Ye,runFunnel:()=>Sn,sendConnectionRequest:()=>It,shouldExcludeLocation:()=>it,viewProfile:()=>Et});async function bn(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}function it(e,t=[]){if(!e||!t||t.length===0)return!1;let n=e.toLowerCase();return t.some(o=>n.includes(o.toLowerCase()))}async function Et(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:i=!1,extractSkills:c=!1,extractRecommendations:u=!1,extractCertifications:s=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3),await ye(e)&&(console.log(" Dismissed Premium overlay"),await w(1500),await bn(e,t));let l=0;for(let v=0;v<2;v++){let C=await e.evaluate(()=>document.body.scrollHeight);for(let g=1;g<=6;g++)await e.evaluate(E=>window.scrollTo(0,E),C*g/6),await w(900);let $=await e.evaluate(()=>document.body.scrollHeight);if($===l)break;l=$}await w(800);let d=await e.evaluate(()=>{let v=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),C=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),$=A=>{let _=(A||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(_)},g={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},E=document.querySelector("main");if(!E)return g;let L=[...Array.from(E.querySelectorAll("h1")),...Array.from(E.querySelectorAll("h2"))],x=Array.from(E.querySelectorAll("h2")),j=L.find(A=>{let _=A.textContent&&A.textContent.trim(),I=(_||"").replace(/\s*\(\d+\)$/,"").trim();return _&&_.length>1&&_.length<100&&!v.has(I)&&!C.has(I)}),J=j?j.textContent.trim():null,R=j?j.parentElement:null;for(;R&&R!==E&&!Array.from(R.children).filter(_=>_.tagName==="P").some(_=>{let I=_.textContent&&_.textContent.trim();return I&&I.length>5&&!$(I)});)R=R.parentElement;let O=null,H=null,N=null,V=null;if(R&&R!==E){let A=Array.from(R.children).filter(I=>I.tagName==="P").filter(I=>{let ue=I.textContent&&I.textContent.trim();return ue&&ue.length>5&&!$(ue)});if(A[0]&&(O=A[0].textContent.trim()),A[1]){let I=A[1].textContent.trim().split(/\s*[·•]\s*/);H=I[0]||null,I.length>1&&(N=I.slice(1).join(" \xB7 "))}let _=Array.from(R.children).filter(I=>I.tagName==="DIV");for(let I=_.length-1;I>=0;I--){let ue=_[I].textContent&&_[I].textContent.trim();if(ue&&!(J&&ue.startsWith(J))&&(V=ue.split(/[·•]/)[0].trim(),V))break}}let be=null;if(R){let A=R.querySelectorAll("p, span, div");for(let _ of A){let I=(_.textContent||"").trim().replace(/^[·•]\s*/,"");if(I==="1st"||I==="2nd"||I==="3rd"){be=I;break}}}let W=!!E.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),D=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),P=D&&D.src||null,q=E.textContent||"",U=null,te=q.match(/(\d+\+?)\s+connections\b/i);te&&(U=te[1]+" connections");let Ke=null,Nt=q.match(/(\d+)\s+mutual connection/i),jt=q.match(/and\s+(\d+)\s+other mutual/i),qn=q.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Nt?Ke=parseInt(Nt[1],10):jt?Ke=2+parseInt(jt[1],10):qn&&(Ke=2);let Ot=null,Mt=null,Ft=x.find(A=>A.textContent&&A.textContent.trim()==="About");if(Ft){let A=Ft.parentElement;for(;A&&A.tagName!=="SECTION";)A=A.parentElement;if(A){let _=(A.textContent||"").trim();_=_.replace(/^About\s*/,"").trim();let I=_.match(/Top skills\s*(.+?)$/i);if(I){let dt=I[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Vn=>Vn.trim()).filter(Boolean);dt.length>0&&dt.length<10&&(Mt=dt)}_=_.split(/\n?…\s*more/i)[0].trim(),_=_.split(/\n?\.\.\.\s*more/i)[0].trim(),_=_.split(/\bTop skills\b/i)[0].trim(),_=_.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Ot=_||null}}let Lt=null,Pt=x.find(A=>A.textContent&&A.textContent.trim()==="Activity");if(Pt){let A=Pt.parentElement;for(;A&&A.tagName!=="SECTION";)A=A.parentElement;if(A){let _=(A.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);_&&(Lt=parseInt(_[1].replace(/,/g,""),10))}}let Un=[...new Set(x.map(A=>(A.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(A=>A&&A.length>1&&A.length<60&&A!==J).filter(A=>v.has(A)))],je=document.body.textContent||"",Bn=/#OpenToWork\b/i.test(je)||/\bOpen to work\b/.test(je),Jn=/#Hiring\b/i.test(je)||/\bI'?m hiring\b/i.test(je)||/\bWe are hiring\b/i.test(je);return{name:J,title:O,location:V,currentCompany:H,currentSchool:N,connectionDegree:be,hasVerifiedBadge:W,photoUrl:P,connectionsLevel:U,mutualConnectionsCount:Ke,followers:Lt,openToWork:Bn,hiring:Jn,about:Ot,topSkills:Mt,availableSections:Un}});console.log(`Viewed: ${d.name} - ${d.title}`);let f=null,p=null,h=null,m=null,S=null,y=null;if(o||r||i||c||u||s){let v=await Promise.resolve().then(()=>(wn(),yn));o&&(f=await v.extractExperienceFromDetails(e,t),console.log(` + Experience: ${f.length} entries`)),r&&(p=await v.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${p.length} entries`)),i&&(h=await v.extractEducationFromDetails(e,t),console.log(` + Education: ${h.length} entries`)),c&&(m=await v.extractSkillsFromDetails(e,t),console.log(` + Skills: ${m.length} entries`)),u&&(S=await v.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${S.length} entries`)),s&&(y=await v.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${y.length} entries`))}return{...d,profileUrl:t,...f!==null&&{experience:f},...p!==null&&{featured:p},...h!==null&&{education:h},...m!==null&&{skillsFull:m},...S!==null&&{recommendations:S},...y!==null&&{certifications:y}}}catch(a){console.error(`Error viewing profile ${t}:`,a.message);try{await e.goto("about:blank",{timeout:1e4}),await w(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(a.message||""))throw a;return null}}async function Ae(e){let t=await e.evaluate(()=>{let n='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside',o=a=>a&&!a.closest(n),r=a=>Array.from(document.querySelectorAll(a)).filter(o),i=r('button[aria-label*="Pending"], a[aria-label*="Pending"]'),c=r('button[aria-label*="Message"], a[aria-label*="Message"]')[0]||null,u=r('button[aria-label*="Invite"][aria-label*="connect"], button[aria-label="Connect"], a[href*="custom-invite"]')[0]||null,s={pendingCount:i.length,pendingLabels:i.map(a=>a.getAttribute("aria-label")),hasMessageBtn:!!c,hasConnectBtn:!!u};return i.length>0?{status:"pending",debug:s}:c&&!u?{status:"connected",debug:s}:document.body.innerText.includes("1st degree connection")?{status:"connected",debug:s}:{status:"not_connected",debug:s}});return console.log(" DEBUG connection status:",JSON.stringify(t.debug)),t.status}async function Ye(e){let t=null,n=await e.evaluate(()=>{let s=document.querySelector("h1")?.textContent?.trim();if(s&&!s.includes("notification"))return s;let a=document.querySelector('main h2, [class*="profile"] h2, [class*="top-card"] h2');if(a&&(s=a.textContent?.trim(),s&&!s.includes("notification")))return s;let l=document.querySelector('[class*="text-heading-xlarge"]')||document.querySelector('[class*="profile-card-title"]')||document.querySelector(".pv-text-details__left-panel h1");if(l)return l.textContent?.trim()||"";let d=document.title;return d&&d.includes("|")?d.split("|")[0].trim():""});if(console.log(` Profile name: "${n}"`),n){let s=await e.evaluate(()=>{let l=document.querySelectorAll('a[href*="custom-invite"]');return{count:l.length,labels:Array.from(l).map(d=>d.getAttribute("aria-label")?.slice(0,50))}});s.count>0&&console.log(` S0: ${s.count} custom-invite links: ${JSON.stringify(s.labels)}`),t=await e.evaluateHandle(l=>{let d=document.querySelectorAll('a[href*="custom-invite"]'),f=l.toLowerCase().split(" ")[0],p='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside';for(let h of d){let m=h.getBoundingClientRect();if(m.width===0||m.height===0||h.closest(p))continue;if((h.getAttribute("aria-label")||"").toLowerCase().includes(f))return h}return null},n);let a=t?.asElement?.()||null;if(a||await t?.dispose?.().catch(()=>{}),a)return console.log(" Found: Connect link (new LinkedIn 2025)"),{button:a,method:"connect_link"}}if(n){let s=n.split(" ")[0].toLowerCase();console.log(` Looking for button with name: "${s}"`);let a=await e.evaluate(d=>{let f=new RegExp("\\b"+d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i"),p=document.querySelectorAll("button[aria-label]");return Array.from(p).filter(m=>{let S=m.getAttribute("aria-label")||"";return(S.toLowerCase().includes("invite")||S.toLowerCase().includes("connect"))&&f.test(S)}).map(m=>m.getAttribute("aria-label")?.slice(0,50))},s);a.length>0&&console.log(` S1: matched buttons: ${JSON.stringify(a)}`),t=await e.evaluateHandle(d=>{let f=document.querySelectorAll("button[aria-label]"),p=new RegExp("\\b"+d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i");for(let h of f){let m=h.getAttribute("aria-label")||"";if((m.toLowerCase().includes("invite")||m.toLowerCase().includes("connect"))&&p.test(m))return h}return null},s);let l=t?.asElement?.()||null;if(l||await t?.dispose?.().catch(()=>{}),l)return console.log(" Found: button matching profile name"),{button:l,method:"name_matched_button"}}if(t=await e.$('button.artdeco-button--primary[aria-label*="Invite"]:not([class*="sticky-header"]):not([class*="muted"])'),t&&n){let s=await e.evaluate(l=>(l.getAttribute("aria-label")||"").toLowerCase(),t),a=n.split(" ")[0].toLowerCase();s.includes("invite")&&!s.includes(a)&&(console.log(` Skipping primary button: wrong person (${s})`),t=null)}if(t||(t=await e.$('button.artdeco-button--primary[aria-label="Connect"]:not([class*="sticky-header"]):not([class*="muted"])')),t)return console.log(" Found: primary button"),{button:t,method:"primary_button"};let o=await e.$$('button[aria-label*="Invite"][aria-label*="connect"]');o.length===0&&(o=await e.$$('button[aria-label="Connect"]'));let r=n?n.split(" ")[0].toLowerCase():"",i=null;for(let s of o){let a=await e.evaluate((l,d)=>{let f=l.className.includes("muted"),p=l.className.includes("sticky-header")||l.className.includes("sticky"),h=l.closest('[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"]')!==null,m=(l.getAttribute("aria-label")||"").toLowerCase(),S=m.includes("invite"),y=d?m.includes(d):!0;return{isMuted:f,isStickyHeader:p,inRecommendations:h,hasInvite:S,matchesName:y,ariaLabel:m}},s,r);if(!a.isMuted&&!a.isStickyHeader&&!a.inRecommendations){if(a.hasInvite&&!a.matchesName){console.log(` Skipping secondary button: wrong person (${a.ariaLabel})`);continue}i=s;break}}for(let s of o)s!==i&&await s.dispose().catch(()=>{});if(i)return console.log(" Found: secondary button"),{button:i,method:"secondary_button"};if(t=await e.$('section.pv-supplementary-action button[aria-label*="Invite"]'),t||(t=await e.$('section.pv-supplementary-action button[aria-label="Connect"]')),t)return console.log(" Found: supplementary section"),{button:t,method:"supplementary_section"};console.log(" Trying More actions dropdown...");let c=null,u=await e.$$('button[id*="profile-overflow-action"]');for(let s of u){let a=await e.evaluate(l=>{let d=l.getBoundingClientRect(),f=d.width>0&&d.height>0,p=l.closest('.sticky-header, [class*="sticky"]')!==null;return{isVisible:f,isInStickyHeader:p,top:d.top}},s);if(a.isVisible&&!a.isInStickyHeader){c=s,console.log(" Found More button by ID pattern (main)");break}}for(let s of u)s!==c&&await s.dispose().catch(()=>{});if(!c&&u.length>0&&(c=u[u.length-1],console.log(" Found More button by ID pattern (last)")),c||(c=await e.$('button[aria-label="More actions"]'),c&&console.log(" Found More button by aria-label")),!c){let s=await e.evaluateHandle(()=>{let l=Array.from(document.querySelectorAll("button, a")).find(f=>{let p=f.innerText?.trim(),h=f.getAttribute("aria-label")||"",m=f.getBoundingClientRect();return m.top<100||m.top>600||m.width===0?!1:p==="Follow"||p==="Message"||p==="Connect"||h.includes("Follow")||h.includes("Message")||h.includes("Invite")});if(!l)return null;let d=l.parentElement;for(let f=0;f<8&&d;f++){for(let p of d.querySelectorAll("button"))if(p.innerText?.trim()==="More"&&p!==l)return p;d=d.parentElement}return null});c=s?.asElement?.()||null,c||await s?.dispose?.().catch(()=>{}),c&&console.log(" Found More button by text (near profile actions)")}if(c)try{if(await e.evaluate(l=>l.scrollIntoView({behavior:"smooth",block:"center"}),c),await w(500),await e.evaluate(l=>l.click(),c),await w(2e3),!e.url().includes("/in/"))return console.log(" Redirect detected after More click, aborting"),null;let a=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]');if(a||(a=await e.$('.artdeco-dropdown__item[aria-label*="connect"]')),a||(a=await e.$('.artdeco-dropdown__item[aria-label="Connect"]')),a||(a=await e.$('div[role="button"][aria-label*="Invite"]')),a||(a=await e.$('div[role="button"][aria-label*="connect"]')),!a){let l=await e.evaluateHandle(()=>{let d=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content');for(let f of d){let p=f.querySelector('a[href*="custom-invite"]');if(p)return p;for(let h of f.querySelectorAll('a, div[role="menuitem"], div[role="button"]'))if(h.innerText?.trim()==="Connect")return h}return null});a=l?.asElement?.()||null,a||await l?.dispose?.().catch(()=>{})}if(!a){let l=await e.evaluate(()=>{let d=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content'),f=[];for(let p of d)for(let h of p.querySelectorAll('[role="menuitem"], a, div')){let m=h.innerText?.trim();m&&m.length<40&&f.push(m)}return[...new Set(f)].slice(0,10)});console.log(` More dropdown items: ${JSON.stringify(l)}`)}if(a)return console.log(" Found: More dropdown"),{button:a,method:"more_dropdown"};await e.keyboard.press("Escape")}catch(s){console.log(" More dropdown click failed:",s.message),await e.keyboard.press("Escape")}if(t=await e.$('button[aria-label*="Invite"]'),t&&n){let s=await e.evaluate(l=>(l.getAttribute("aria-label")||"").toLowerCase(),t),a=n.split(" ")[0].toLowerCase();s.includes("invite")&&!s.includes(a)&&(console.log(` Skipping generic button: wrong person (${s})`),t=null)}return t||(t=await e.$('button[aria-label="Connect"]')),t?(console.log(" Found: generic button"),{button:t,method:"generic_button"}):null}async function _t(e,t){await e.evaluate(l=>l.scrollIntoView({behavior:"smooth",block:"center"}),t),await w(500);let n=await e.evaluate(l=>({tag:l.tagName,ariaLabel:l.getAttribute("aria-label"),href:l.getAttribute("href")}),t),r=n.tag==="A"&&n.href&&n.href.includes("custom-invite"),i=n.tag==="DIV",c=(n.ariaLabel||"").toLowerCase();if(c.includes("invite")){let l=await e.evaluate(()=>((document.querySelector("main h1")||document.querySelector("h1")||document.querySelector("main h2"))?.textContent?.trim()||"").split(" ")[0].toLowerCase());if(l&&!c.includes(l))return console.log(` \u2717 Identity guard: control is for someone else ("${n.ariaLabel}") \u2014 refusing to click (target: ${l})`),"wrong_target"}if(r){console.log(" Clicking custom-invite link (will navigate)..."),await Promise.all([e.waitForNavigation({waitUntil:"domcontentloaded",timeout:3e4}).catch(()=>{}),e.evaluate(d=>d.click(),t)]),await w(2e3);let l=e.url();if(l.includes("premium")||l.includes("redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium page - connection limit reached?"),await e.goBack(),await w(2e3),"premium_redirect"}else i?(await e.evaluate(l=>l.click(),t),await w(3e3)):(await e.evaluate(l=>l.click(),t),await w(3e3));let u=e.url();if(u.includes("/premium/")||u.includes("/redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium upsell page"),"premium_redirect";let s=await e.evaluate(()=>!!document.querySelector('[role="dialog"], .artdeco-modal, .send-invite')),a=e.url();return console.log(s?` \u2713 Connect sent \u2014 ${a}`:` \u26A0 No modal after connect click \u2014 ${a}`),"success"}async function xr(e){console.log(" Upsell: Premium required for notes");let t=await e.$('button[aria-label="Dismiss"]')||await e.$("button.artdeco-modal__dismiss");t?await t.click():await e.keyboard.press("Escape"),await w(1500);let n=await Ye(e);if(n){await e.evaluate(r=>r.click(),n),await w(2e3);let o=await e.$('button[aria-label="Send without a note"]');if(o){try{await o.evaluate(r=>r.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (without note)"),!0}}return!1}async function It(e,t,n={}){let{source:o="unknown",skipQuotaGate:r=!1,skipQuotaRecord:i=!1}=n;if(!r){let u=qe();if(!u.allowed)return console.log(` \u26A0 Connection quota reached \u2014 not sending: ${u.reason}`),{success:!1,reason:"quota_exhausted",connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:u.reason,profileInfo:null}}let c=await Ar(e,t,n);return c.connectionSent&&!i&&Kt(t,o),c}async function Ar(e,t,n={}){let{message:o=null,useCustomMessage:r=!0,skipIfPending:i=!0,skipIfConnected:c=!0,excludeLocations:u=[]}=n,s={success:!1,reason:null,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null};try{let a=t.split("/in/")[1]?.replace("/","")||"unknown";if(console.log(`
239
- --- Connecting: ${a} ---`),u.length>0){let y=Y()[t]?.location;if(it(y,u))return console.log(` \u26A0 Excluded location (stored): ${y}`),s.reason="excluded_location",s.profileInfo={location:y},s}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(5e3),await ye(e)&&(console.log(" Dismissed Premium overlay"),await w(2e3),await bn(e,t),await w(2e3)),s.profileInfo=await e.evaluate(()=>{let y=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),k=D=>{let P=(D||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(P)},v={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},C=document.querySelector("main");if(!C)return v;let $=[...Array.from(C.querySelectorAll("h1")),...Array.from(C.querySelectorAll("h2"))],g=Array.from(C.querySelectorAll("h2")),E=$.find(D=>{let P=D.textContent&&D.textContent.trim();return P&&P.length>1&&P.length<100&&!y.has(P)&&P!=="0 notifications"}),L=E?E.textContent.trim():null,x=E?E.parentElement:null;for(;x&&x!==C&&!Array.from(x.children).filter(q=>q.tagName==="P").some(q=>{let U=q.textContent&&q.textContent.trim();return U&&U.length>5&&!k(U)});)x=x.parentElement;let j=null,J=null,R=null;if(x&&x!==C){let D=Array.from(x.children),P=D.filter(U=>U.tagName==="P").filter(U=>{let te=U.textContent&&U.textContent.trim();return te&&te.length>5&&!k(te)});P[0]&&(j=P[0].textContent.trim()),P[1]&&(J=P[1].textContent.trim());let q=D.filter(U=>U.tagName==="DIV");for(let U=q.length-1;U>=0;U--){let te=q[U].textContent&&q[U].textContent.trim();if(te&&!(L&&te.startsWith(L))&&(R=te.split(/[·•]/)[0].trim(),R))break}}let O=null;if(x){let D=x.querySelectorAll("p, span, div");for(let P of D){let q=(P.textContent||"").trim().replace(/^[·•]\s*/,"");if(q==="1st"||q==="2nd"||q==="3rd"){O=q;break}}}let H=null,N=g.find(D=>D.textContent&&D.textContent.trim()==="About");if(N){let D=N.parentElement;for(;D&&D.tagName!=="SECTION";)D=D.parentElement;D&&(H=(D.textContent||"").trim().replace(/^About\s*/,"").trim()||null,H&&(H=H.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let V=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),be=V&&V.src||null,W=!!C.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:L,title:j,location:R,about:H,company:J,connectionDegree:O,connectionsCount:null,mutualConnections:null,photoUrl:be,hasVerifiedBadge:W}}),u.length>0){let y=s.profileInfo?.location,k=Y()[t]?.location,v=y||k;if(it(v,u))return console.log(` \u26A0 Excluded location (${y?"live":"stored"}): ${v}`),s.reason="excluded_location",s;!y&&k==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let d=await Ae(e);if(d==="pending"&&i)return console.log(" \u26A0 Already pending - skipping"),s.reason="pending",s;if(d==="connected"&&c)return console.log(" \u26A0 Already connected - skipping"),s.reason="connected",s;await ye(e);let f=await Ye(e);if(!f&&(await ye(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await w(2e3),f=await Ye(e)),!f))return console.log(" \u2717 Connect not found"),s.reason="button_not_found",s;s.method=f.method;let p=await _t(e,f.button);if(p==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),s.reason="wrong_target",s;if(p==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(4e3);let y=await Ae(e);if(y==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s;console.log(` Status after upsell: ${y} \u2014 trying More dropdown...`),await ye(e),await w(1e3);let k=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if(k)try{await e.evaluate(C=>C.scrollIntoView({behavior:"smooth",block:"center"}),k),await w(500),await k.click().catch(()=>e.evaluate(C=>C.click(),k)),await w(2e3);let v=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(v){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(g=>g.click(),v),await w(3e3);let C=e.url();if(C.includes("/premium/")||C.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3),s.reason="premium_required",s;if(await Ae(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.method="more_dropdown",s.withCustomMessage=!1,s;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await w(500),s.reason="premium_required",s}catch(v){return console.log(" More dropdown failed:",v.message),await e.keyboard.press("Escape").catch(()=>{}),s.reason="premium_required",s}else return console.log(" \u2717 No More button found \u2014 Premium required"),s.reason="premium_required",s}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let y=await e.$('button[aria-label="Dismiss"]');return y&&await y.click(),await w(500),s.reason="email_required",s}let m=await e.$('button[aria-label="Add a note"]'),S=await e.$('button[aria-label="Send without a note"]');if(!m&&!S){let y=await e.evaluate(()=>{let k=document.querySelector("#interop-outlet")?.shadowRoot;if(!k)return{addNote:!1,sendWithout:!1};let v=k.querySelector('button[aria-label="Add a note"]'),C=k.querySelector('button[aria-label="Send without a note"]');return{addNote:!!v,sendWithout:!!C}});if(y.addNote){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));m=k?.asElement?.()||null,m||await k.dispose().catch(()=>{})}if(y.sendWithout){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));S=k?.asElement?.()||null,S||await k.dispose().catch(()=>{})}}if(r){if(m&&o){if(console.log(" Adding personalized note..."),await m.click(),await w(1500),await e.$("div.modal-upsell")){let v=await xr(e);return s.success=v,s.connectionSent=v,s.reason=v?"sent_without_note_upsell":"upsell_failed",s.withCustomMessage=!1,s}let k=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if(k){let v=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),C=o.replace("{name}",v);await k.type(C,{delay:20}),await w(500);let $=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if($){try{await $.evaluate(g=>g.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (with note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_with_note",s.withCustomMessage=!0,s.messageSent=C,s}}}else if(S){console.log(" Sending without note...");try{await S.evaluate(y=>y.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (without note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}else if(m&&!o){console.log(" No message provided, sending without note...");let y=await e.$('button[aria-label="Send without a note"]');if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (without note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}}}else{console.log(" Sending without note (custom messages disabled)...");let y=S;if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (without note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}}if(f.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(4e3)),await ye(e),await w(500);let k=await e.$$('button[id*="profile-overflow-action"]'),v=null;for(let C of k){let $=await e.evaluate(g=>{let E=g.getBoundingClientRect();return{visible:E.width>0&&E.height>0,inSticky:!!g.closest('.sticky-header, [class*="sticky"]')}},C);if($.visible&&!$.inSticky){v=C;break}}!v&&k.length>0&&(v=k[k.length-1]);for(let C of k)C!==v&&await C.dispose().catch(()=>{});if(v)try{await e.evaluate($=>$.scrollIntoView({behavior:"smooth",block:"center"}),v),await w(500),await v.click().catch(()=>e.evaluate($=>$.click(),v)),await w(2e3);let C=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(C){console.log(" Found Connect in More dropdown, clicking..."),s.method="more_dropdown",await e.evaluate(L=>L.click(),C),await w(3e3);let $=e.url();if($.includes("/premium/")||$.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3),await Ae(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s):(s.reason="premium_required",s);if(await Ae(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s;let E=await e.$('button[aria-label="Send without a note"]');if(E){console.log(" Modal appeared via More dropdown, sending without note...");try{await E.evaluate(L=>L.click())}catch{}return await w(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(C){console.log(" More dropdown fallback failed:",C.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),s.reason="modal_failed",s}catch(a){console.error(` \u2717 Error: ${a.message}`),s.reason="error",s.error=a.message;let l=a.message.toLowerCase();if(l.includes("detached")||l.includes("session closed")||l.includes("target closed")||l.includes("browser has disconnected")||l.includes("protocol error"))return s.fatal=!0,s;try{await e.goto("about:blank",{timeout:1e4}),await w(1e3)}catch{s.fatal=!0}return s}}async function Sn(e,t,n={}){let{message:o=null,useCustomMessage:r=!0,maxConnections:i=20,viewOnly:c=!1,delayBetweenProfiles:u=3e3,onProfileProcessed:s=null,excludeLocations:a=[],source:l="unknown"}=n,d={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
239
+ --- Connecting: ${a} ---`),u.length>0){let y=Y()[t]?.location;if(it(y,u))return console.log(` \u26A0 Excluded location (stored): ${y}`),s.reason="excluded_location",s.profileInfo={location:y},s}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(5e3),await ye(e)&&(console.log(" Dismissed Premium overlay"),await w(2e3),await bn(e,t),await w(2e3)),s.profileInfo=await e.evaluate(()=>{let y=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),k=D=>{let P=(D||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(P)},v={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},C=document.querySelector("main");if(!C)return v;let $=[...Array.from(C.querySelectorAll("h1")),...Array.from(C.querySelectorAll("h2"))],g=Array.from(C.querySelectorAll("h2")),E=$.find(D=>{let P=D.textContent&&D.textContent.trim();return P&&P.length>1&&P.length<100&&!y.has(P)&&P!=="0 notifications"}),L=E?E.textContent.trim():null,x=E?E.parentElement:null;for(;x&&x!==C&&!Array.from(x.children).filter(q=>q.tagName==="P").some(q=>{let U=q.textContent&&q.textContent.trim();return U&&U.length>5&&!k(U)});)x=x.parentElement;let j=null,J=null,R=null;if(x&&x!==C){let D=Array.from(x.children),P=D.filter(U=>U.tagName==="P").filter(U=>{let te=U.textContent&&U.textContent.trim();return te&&te.length>5&&!k(te)});P[0]&&(j=P[0].textContent.trim()),P[1]&&(J=P[1].textContent.trim());let q=D.filter(U=>U.tagName==="DIV");for(let U=q.length-1;U>=0;U--){let te=q[U].textContent&&q[U].textContent.trim();if(te&&!(L&&te.startsWith(L))&&(R=te.split(/[·•]/)[0].trim(),R))break}}let O=null;if(x){let D=x.querySelectorAll("p, span, div");for(let P of D){let q=(P.textContent||"").trim().replace(/^[·•]\s*/,"");if(q==="1st"||q==="2nd"||q==="3rd"){O=q;break}}}let H=null,N=g.find(D=>D.textContent&&D.textContent.trim()==="About");if(N){let D=N.parentElement;for(;D&&D.tagName!=="SECTION";)D=D.parentElement;D&&(H=(D.textContent||"").trim().replace(/^About\s*/,"").trim()||null,H&&(H=H.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let V=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),be=V&&V.src||null,W=!!C.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:L,title:j,location:R,about:H,company:J,connectionDegree:O,connectionsCount:null,mutualConnections:null,photoUrl:be,hasVerifiedBadge:W}}),u.length>0){let y=s.profileInfo?.location,k=Y()[t]?.location,v=y||k;if(it(v,u))return console.log(` \u26A0 Excluded location (${y?"live":"stored"}): ${v}`),s.reason="excluded_location",s;!y&&k==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let d=await Ae(e);if(s.profileInfo?.connectionDegree==="1st"&&d!=="pending"&&(d!=="connected"&&console.log(" (degree badge = 1st \u2192 already connected)"),d="connected"),d==="pending"&&i)return console.log(" \u26A0 Already pending - skipping"),s.reason="pending",s;if(d==="connected"&&c)return console.log(" \u26A0 Already connected - skipping"),s.reason="connected",s;await ye(e);let f=await Ye(e);if(!f&&(await ye(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await w(2e3),f=await Ye(e)),!f))return console.log(" \u2717 Connect not found"),s.reason="button_not_found",s;s.method=f.method;let p=await _t(e,f.button);if(p==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),s.reason="wrong_target",s;if(p==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(4e3);let y=await Ae(e);if(y==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s;console.log(` Status after upsell: ${y} \u2014 trying More dropdown...`),await ye(e),await w(1e3);let k=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if(k)try{await e.evaluate(C=>C.scrollIntoView({behavior:"smooth",block:"center"}),k),await w(500),await k.click().catch(()=>e.evaluate(C=>C.click(),k)),await w(2e3);let v=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(v){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(g=>g.click(),v),await w(3e3);let C=e.url();if(C.includes("/premium/")||C.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3),s.reason="premium_required",s;if(await Ae(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.method="more_dropdown",s.withCustomMessage=!1,s;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await w(500),s.reason="premium_required",s}catch(v){return console.log(" More dropdown failed:",v.message),await e.keyboard.press("Escape").catch(()=>{}),s.reason="premium_required",s}else return console.log(" \u2717 No More button found \u2014 Premium required"),s.reason="premium_required",s}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let y=await e.$('button[aria-label="Dismiss"]');return y&&await y.click(),await w(500),s.reason="email_required",s}let m=await e.$('button[aria-label="Add a note"]'),S=await e.$('button[aria-label="Send without a note"]');if(!m&&!S){let y=await e.evaluate(()=>{let k=document.querySelector("#interop-outlet")?.shadowRoot;if(!k)return{addNote:!1,sendWithout:!1};let v=k.querySelector('button[aria-label="Add a note"]'),C=k.querySelector('button[aria-label="Send without a note"]');return{addNote:!!v,sendWithout:!!C}});if(y.addNote){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));m=k?.asElement?.()||null,m||await k.dispose().catch(()=>{})}if(y.sendWithout){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));S=k?.asElement?.()||null,S||await k.dispose().catch(()=>{})}}if(r){if(m&&o){if(console.log(" Adding personalized note..."),await m.click(),await w(1500),await e.$("div.modal-upsell")){let v=await xr(e);return s.success=v,s.connectionSent=v,s.reason=v?"sent_without_note_upsell":"upsell_failed",s.withCustomMessage=!1,s}let k=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if(k){let v=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),C=o.replace("{name}",v);await k.type(C,{delay:20}),await w(500);let $=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if($){try{await $.evaluate(g=>g.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (with note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_with_note",s.withCustomMessage=!0,s.messageSent=C,s}}}else if(S){console.log(" Sending without note...");try{await S.evaluate(y=>y.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (without note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}else if(m&&!o){console.log(" No message provided, sending without note...");let y=await e.$('button[aria-label="Send without a note"]');if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (without note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}}}else{console.log(" Sending without note (custom messages disabled)...");let y=S;if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await w(3e3),console.log(" \u2713 Connection sent (without note)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}}if(f.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(4e3)),await ye(e),await w(500);let k=await e.$$('button[id*="profile-overflow-action"]'),v=null;for(let C of k){let $=await e.evaluate(g=>{let E=g.getBoundingClientRect();return{visible:E.width>0&&E.height>0,inSticky:!!g.closest('.sticky-header, [class*="sticky"]')}},C);if($.visible&&!$.inSticky){v=C;break}}!v&&k.length>0&&(v=k[k.length-1]);for(let C of k)C!==v&&await C.dispose().catch(()=>{});if(v)try{await e.evaluate($=>$.scrollIntoView({behavior:"smooth",block:"center"}),v),await w(500),await v.click().catch(()=>e.evaluate($=>$.click(),v)),await w(2e3);let C=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(C){console.log(" Found Connect in More dropdown, clicking..."),s.method="more_dropdown",await e.evaluate(L=>L.click(),C),await w(3e3);let $=e.url();if($.includes("/premium/")||$.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3),await Ae(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s):(s.reason="premium_required",s);if(await Ae(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s;let E=await e.$('button[aria-label="Send without a note"]');if(E){console.log(" Modal appeared via More dropdown, sending without note...");try{await E.evaluate(L=>L.click())}catch{}return await w(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),s.success=!0,s.connectionSent=!0,s.reason="sent_without_note",s.withCustomMessage=!1,s}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(C){console.log(" More dropdown fallback failed:",C.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),s.reason="modal_failed",s}catch(a){console.error(` \u2717 Error: ${a.message}`),s.reason="error",s.error=a.message;let l=a.message.toLowerCase();if(l.includes("detached")||l.includes("session closed")||l.includes("target closed")||l.includes("browser has disconnected")||l.includes("protocol error"))return s.fatal=!0,s;try{await e.goto("about:blank",{timeout:1e4}),await w(1e3)}catch{s.fatal=!0}return s}}async function Sn(e,t,n={}){let{message:o=null,useCustomMessage:r=!0,maxConnections:i=20,viewOnly:c=!1,delayBetweenProfiles:u=3e3,onProfileProcessed:s=null,excludeLocations:a=[],source:l="unknown"}=n,d={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
240
240
  === Running Funnel: ${t.length} profiles ===`),console.log(`Mode: ${c?"View Only":`Connect (max ${i})`}`),c||console.log(`Custom messages: ${r?"Enabled":"Disabled (saving quota)"}`),a.length>0&&console.log(`Excluding locations: ${a.join(", ")}`),!c){let p=Se();console.log(`Quota: today ${p.daily.sent}/${p.daily.max} | week ${p.weekly.sent}/${p.weekly.max}`)}console.log("");let f=0;for(let p=0;p<t.length;p++){let h=t[p];try{if(e.isClosed()){console.log(`
241
241
  \u26A0 Browser page is closed \u2014 aborting funnel`);break}}catch{console.log(`
242
242
  \u26A0 Browser disconnected \u2014 aborting funnel`);break}if(!h.profileUrl){console.log(`[${p+1}/${t.length}] Skipping - no URL`);continue}let m=Gt(h.profileUrl);if(m==="pending"||m==="connected"||m==="sent_with_note"||m==="sent_without_note"||m==="sent_without_note_upsell"){console.log(`[${p+1}/${t.length}] ${h.name||h.profileUrl} \u2014 skipped (db: ${m})`),m==="pending"||m==="sent_with_note"||m==="sent_without_note"||m==="sent_without_note_upsell"?d.skipped.pending++:d.skipped.connected++,s&&await s(h,d,{success:!1,reason:m,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null});continue}console.log(`[${p+1}/${t.length}] ${h.name||h.profileUrl}`);let S=null;if(c){let y=await Et(e,h.profileUrl);y?(ze(h.profileUrl,{...y,source:l}),d.viewed++,S={success:!0,reason:"viewed",connectionSent:!1,profileInfo:y}):(d.errors++,S={success:!1,reason:"view_failed",connectionSent:!1,profileInfo:null})}else{if(d.connectionsSent>=i){console.log(` Max connections per session (${i}) reached`);break}let y=qe();if(!y.allowed){console.log(` \u26A0 Global quota exhausted: ${y.reason}`);break}if(S=await It(e,h.profileUrl,{message:o,useCustomMessage:r,excludeLocations:a,source:l,skipQuotaGate:!0}),S.success)d.connectionsSent++;else switch(S.reason){case"pending":d.skipped.pending++;break;case"connected":d.skipped.connected++;break;case"email_required":d.skipped.email++;break;case"button_not_found":d.skipped.notFound++;break;case"excluded_location":d.skipped.excludedLocation++;break;default:d.errors++}}if(S?.fatal){console.log(`
@@ -243,7 +243,7 @@ function findEntryContainer(root) {
243
243
 
244
244
  ${o.join(`
245
245
  `)}`;try{await ut.addMessage(l,r)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var un=cn(import.meta.url),dn=ne.dirname(ne.dirname(un)),je=process.env.DATA_DIR?ne.resolve(process.env.DATA_DIR,"collected-profiles"):ne.join(dn,"collected-profiles"),Ne=ne.join(je,"run-log.json");function fn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";J.writeFileSync(o,n);for(let s=0;s<3;s++)try{J.renameSync(o,e);return}catch(i){if(s<2&&(i.code==="EPERM"||i.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw i}}function ft(){try{if(!J.existsSync(Ne))return{runs:[]};let e=JSON.parse(J.readFileSync(Ne,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function mt(e){J.existsSync(je)||J.mkdirSync(je,{recursive:!0});try{fn(Ne,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function pt(e,t="default"){let n=ft();for(let l of n.runs)l.status==="running"&&(l.status="interrupted",l.result="interrupted",l.timestamp&&(l.duration=Date.now()-new Date(l.timestamp).getTime()));let o=new Date,s={timestamp:o.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};n.runs.push(s);let i=Date.now()-30*24*60*60*1e3;return n.runs=n.runs.filter(l=>new Date(l.timestamp).getTime()>i),mt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function Fe(e,t,n=null,o=null){if(!e)return;let s=null;try{let l=ft(),c=l.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,s=c.duration;else{let r=l.runs.find(u=>u.script===e.script&&u.status==="running"&&u.timestamp===new Date(e.startTime).toISOString());r&&(r.status=t,r.result=t,r.duration=Date.now()-e.startTime,r.stats=n,r.error=o,s=r.duration)}mt(l)}catch(l){console.error(`[runLog] Failed to end run: ${l.message}`)}let i=n&&Array.isArray(n.summaryLines)?n.summaryLines:null;if(i&&i.length>0&&process.env.NODE_RUN_REPORTS){let l=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";dt({scriptName:e.script,mode:e.mode,status:l,summaryLines:i,error:o,duration:s??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}Ae();Ae();import{getPluginConfig as mn}from"@ilivemylife/graph-sdk";var pn=await mn();for(let[e,t]of Object.entries(pn))process.env[e]===void 0&&(process.env[e]=t);var Zo=process.env.LINKEDIN_NAME,le=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),er=Object.freeze(new Set([le.DRAFT,le.CONFIRMED,le.NEEDS_REVIEW])),tr=Object.freeze(new Set([le.DRAFT,le.CONFIRMED,le.REJECTED,le.NEEDS_REVIEW]));import"dotenv/config";import*as T from"fs";import*as M from"path";import{fileURLToPath as hn}from"url";var gn=hn(import.meta.url),yn=M.dirname(M.dirname(gn)),Q=process.env.DATA_DIR?M.resolve(process.env.DATA_DIR,"collected-profiles"):M.join(yn,"collected-profiles"),Le=M.join(Q,"people.json"),ir=M.join(Q,"jobs.json"),yt=M.join(Q,"quota.json"),lr=M.join(Q,"conversations.json"),ar=M.join(Q,"sync-state.json"),cr=M.join(Q,"application-questions.json"),Me=M.join(Q,"profile-history"),wt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},he=wt(process.env.CONNECT_MAX_DAILY,20),ge=wt(process.env.CONNECT_MAX_WEEKLY,100),fe=null,wn=null,z=null,Sn=null,bn=null,kn=null;function St(){fe=null,wn=null,z=null,Sn=null,bn=null,kn=null}function De(){T.existsSync(Q)||T.mkdirSync(Q,{recursive:!0})}function Pe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";T.writeFileSync(o,n);for(let s=0;s<3;s++)try{T.renameSync(o,e);return}catch(i){if(s<2&&(i.code==="EPERM"||i.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw i}}function qe(e,t){if(!T.existsSync(e))return null;try{let n=JSON.parse(T.readFileSync(e,"utf-8"));try{T.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${M.resolve(e)}`);let o=e+".backup";if(T.existsSync(o))try{let s=JSON.parse(T.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{T.copyFileSync(o,e)}catch{}return s}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{T.copyFileSync(e,e+".corrupted")}catch{}return null}}function ye(){return new Date().toISOString().split("T")[0]}var vn=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt","featured","education","skillsFull","recommendations","certifications"],$n=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function Be(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Cn(){T.existsSync(Me)||T.mkdirSync(Me,{recursive:!0})}function bt(e){let t=Be(e);return t?M.join(Me,`${t}.json`):null}function xn(e){let t=bt(e);return t?qe(t,`profile-history/${Be(e)}.json`)||[]:[]}function En(e,t){let n=bt(e);if(!n)return;Cn();let o=xn(e);o.unshift(t);try{Pe(n,o)}catch(s){console.error(`[!] Failed to append profile-history for ${Be(e)}: ${s.message}`)}}function ht(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function gt(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function An(e,t){if(!e)return[];let n=[];for(let o of $n){let s=e[o],i=t[o];ht(s)||ht(i)||gt(s)!==gt(i)&&n.push(o)}return n}function In(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,s]of Object.entries(e))t.has(o)||(n[o]=s);return n}function oe(){return fe||(De(),fe=qe(Le,"people.json")||{},fe)}function Ue(e){De(),fe=e;try{Pe(Le,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${M.resolve(Le)}`)}}function Ie(e,t={}){if(!e)return null;let n=oe(),o=ye(),s=new Date().toISOString(),i=n[e];if(i){let l=An(i,t);l.length>0&&(En(e,{capturedAt:s,previousLastUpdated:i.lastUpdated||null,changedFields:l,snapshot:In(i)}),i.lastSnapshotAt=s),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=s,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let c of vn)if(t[c]!=null){if(Array.isArray(t[c])&&t[c].length===0&&Array.isArray(i[c])&&i[c].length>0)continue;i[c]=t[c]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=s)}else n[e]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:s,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?s:null};return Ue(n),n[e]}function kt(e,t){if(!e||!t)return;let n=oe(),o=n[e];if(!o)return;o.encounters||(o.encounters=[]);let i={date:ye(),source:t.source||"unknown",action:t.action||"unknown"};t.jobId&&(i.jobId=String(t.jobId)),t.jobTitle&&(i.jobTitle=t.jobTitle),t.jobCompany&&(i.jobCompany=t.jobCompany),!o.encounters.some(c=>c.date===i.date&&c.source===i.source&&c.action===i.action&&(c.jobId||"")===(i.jobId||""))&&(o.encounters.push(i),o.lastUpdated=new Date().toISOString(),Ue(n))}function vt(e){return e&&oe()[e]?.connectionStatus||null}function $t(e,t,n={}){if(!e)return;n.profileInfo?Ie(e,n.profileInfo):oe()[e]||Ie(e,{});let o=oe(),s=o[e];s&&(s.connectionStatus=t,s.connectionDate=ye(),s.connectionMethod=n.method||s.connectionMethod,s.messageSent=n.messageSent||s.messageSent,s.lastUpdated=new Date().toISOString(),Ue(o))}function Ct(){return z||(De(),z=qe(yt,"quota.json"),(!z||!z.connections)&&(z={connections:[]}),z)}function Dn(e){De(),z=e;try{Pe(yt,e)}catch(t){console.error(`[!] Failed to save quota.json: ${t.message}`)}}function xt(e,t="unknown"){let n=Ct(),o=new Date;n.connections.push({date:o.toISOString().split("T")[0],time:o.toTimeString().split(" ")[0],profileUrl:e,source:t}),Dn(n)}function Et(){let e=Ct(),t=new Date;t.setDate(t.getDate()-7);let n=t.toISOString().split("T")[0];return e.connections.filter(o=>o.date>=n)}function Je(){let e=Et(),t=ye(),n=e.filter(r=>r.date===t).length,o=e.length,s=n>=he,i=o>=ge,l=!s&&!i,c={allowed:l,daily:{sent:n,max:he},weekly:{sent:o,max:ge}};return l||(c.reason=s?`Daily limit reached (${n}/${he})`:`Weekly limit reached (${o}/${ge})`),c}function Ve(){let e=Et(),t=ye(),n=e.filter(s=>s.date===t).length,o=e.length;return{daily:{sent:n,max:he,remaining:he-n},weekly:{sent:o,max:ge,remaining:ge-o}}}async function Rt(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}function Dt(e,t=[]){if(!e||!t||t.length===0)return!1;let n=e.toLowerCase();return t.some(o=>n.includes(o.toLowerCase()))}async function Fn(e,t,n={}){let{extractExperience:o=!1,extractFeatured:s=!1,extractEducation:i=!1,extractSkills:l=!1,extractRecommendations:c=!1,extractCertifications:r=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(3e3),await ie(e)&&(console.log(" Dismissed Premium overlay"),await y(1500),await Rt(e,t));let a=0;for(let b=0;b<2;b++){let C=await e.evaluate(()=>document.body.scrollHeight);for(let _=1;_<=6;_++)await e.evaluate(D=>window.scrollTo(0,D),C*_/6),await y(900);let I=await e.evaluate(()=>document.body.scrollHeight);if(I===a)break;a=I}await y(800);let d=await e.evaluate(()=>{let b=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),C=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),I=v=>{let x=(v||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(x)},_={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},D=document.querySelector("main");if(!D)return _;let B=[...Array.from(D.querySelectorAll("h1")),...Array.from(D.querySelectorAll("h2"))],k=Array.from(D.querySelectorAll("h2")),F=B.find(v=>{let x=v.textContent&&v.textContent.trim(),E=(x||"").replace(/\s*\(\d+\)$/,"").trim();return x&&x.length>1&&x.length<100&&!b.has(E)&&!C.has(E)}),K=F?F.textContent.trim():null,L=F?F.parentElement:null;for(;L&&L!==D&&!Array.from(L.children).filter(x=>x.tagName==="P").some(x=>{let E=x.textContent&&x.textContent.trim();return E&&E.length>5&&!I(E)});)L=L.parentElement;let se=null,ee=null,me=null,de=null;if(L&&L!==D){let v=Array.from(L.children).filter(E=>E.tagName==="P").filter(E=>{let te=E.textContent&&E.textContent.trim();return te&&te.length>5&&!I(te)});if(v[0]&&(se=v[0].textContent.trim()),v[1]){let E=v[1].textContent.trim().split(/\s*[·•]\s*/);ee=E[0]||null,E.length>1&&(me=E.slice(1).join(" \xB7 "))}let x=Array.from(L.children).filter(E=>E.tagName==="DIV");for(let E=x.length-1;E>=0;E--){let te=x[E].textContent&&x[E].textContent.trim();if(te&&!(K&&te.startsWith(K))&&(de=te.split(/[·•]/)[0].trim(),de))break}}let Ce=null;if(L){let v=L.querySelectorAll("p, span, div");for(let x of v){let E=(x.textContent||"").trim().replace(/^[·•]\s*/,"");if(E==="1st"||E==="2nd"||E==="3rd"){Ce=E;break}}}let _e=!!D.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),R=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),O=R&&R.src||null,j=D.textContent||"",N=null,Y=j.match(/(\d+\+?)\s+connections\b/i);Y&&(N=Y[1]+" connections");let xe=null,tt=j.match(/(\d+)\s+mutual connection/i),nt=j.match(/and\s+(\d+)\s+other mutual/i),Qt=j.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);tt?xe=parseInt(tt[1],10):nt?xe=2+parseInt(nt[1],10):Qt&&(xe=2);let ot=null,rt=null,st=k.find(v=>v.textContent&&v.textContent.trim()==="About");if(st){let v=st.parentElement;for(;v&&v.tagName!=="SECTION";)v=v.parentElement;if(v){let x=(v.textContent||"").trim();x=x.replace(/^About\s*/,"").trim();let E=x.match(/Top skills\s*(.+?)$/i);if(E){let Oe=E[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(tn=>tn.trim()).filter(Boolean);Oe.length>0&&Oe.length<10&&(rt=Oe)}x=x.split(/\n?…\s*more/i)[0].trim(),x=x.split(/\n?\.\.\.\s*more/i)[0].trim(),x=x.split(/\bTop skills\b/i)[0].trim(),x=x.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ot=x||null}}let it=null,lt=k.find(v=>v.textContent&&v.textContent.trim()==="Activity");if(lt){let v=lt.parentElement;for(;v&&v.tagName!=="SECTION";)v=v.parentElement;if(v){let x=(v.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);x&&(it=parseInt(x[1].replace(/,/g,""),10))}}let Xt=[...new Set(k.map(v=>(v.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(v=>v&&v.length>1&&v.length<60&&v!==K).filter(v=>b.has(v)))],pe=document.body.textContent||"",Zt=/#OpenToWork\b/i.test(pe)||/\bOpen to work\b/.test(pe),en=/#Hiring\b/i.test(pe)||/\bI'?m hiring\b/i.test(pe)||/\bWe are hiring\b/i.test(pe);return{name:K,title:se,location:de,currentCompany:ee,currentSchool:me,connectionDegree:Ce,hasVerifiedBadge:_e,photoUrl:O,connectionsLevel:N,mutualConnectionsCount:xe,followers:it,openToWork:Zt,hiring:en,about:ot,topSkills:rt,availableSections:Xt}});console.log(`Viewed: ${d.name} - ${d.title}`);let m=null,f=null,h=null,p=null,S=null,w=null;if(o||s||i||l||c||r){let b=await Promise.resolve().then(()=>(It(),At));o&&(m=await b.extractExperienceFromDetails(e,t),console.log(` + Experience: ${m.length} entries`)),s&&(f=await b.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${f.length} entries`)),i&&(h=await b.extractEducationFromDetails(e,t),console.log(` + Education: ${h.length} entries`)),l&&(p=await b.extractSkillsFromDetails(e,t),console.log(` + Skills: ${p.length} entries`)),c&&(S=await b.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${S.length} entries`)),r&&(w=await b.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${w.length} entries`))}return{...d,profileUrl:t,...m!==null&&{experience:m},...f!==null&&{featured:f},...h!==null&&{education:h},...p!==null&&{skillsFull:p},...S!==null&&{recommendations:S},...w!==null&&{certifications:w}}}catch(u){console.error(`Error viewing profile ${t}:`,u.message);try{await e.goto("about:blank",{timeout:1e4}),await y(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(u.message||""))throw u;return null}}async function ke(e){let t=await e.evaluate(()=>{let n='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside',o=u=>u&&!u.closest(n),s=u=>Array.from(document.querySelectorAll(u)).filter(o),i=s('button[aria-label*="Pending"], a[aria-label*="Pending"]'),l=s('button[aria-label*="Message"], a[aria-label*="Message"]')[0]||null,c=s('button[aria-label*="Invite"][aria-label*="connect"], button[aria-label="Connect"], a[href*="custom-invite"]')[0]||null,r={pendingCount:i.length,pendingLabels:i.map(u=>u.getAttribute("aria-label")),hasMessageBtn:!!l,hasConnectBtn:!!c};return i.length>0?{status:"pending",debug:r}:l&&!c?{status:"connected",debug:r}:document.body.innerText.includes("1st degree connection")?{status:"connected",debug:r}:{status:"not_connected",debug:r}});return console.log(" DEBUG connection status:",JSON.stringify(t.debug)),t.status}async function He(e){let t=null,n=await e.evaluate(()=>{let r=document.querySelector("h1")?.textContent?.trim();if(r&&!r.includes("notification"))return r;let u=document.querySelector('main h2, [class*="profile"] h2, [class*="top-card"] h2');if(u&&(r=u.textContent?.trim(),r&&!r.includes("notification")))return r;let a=document.querySelector('[class*="text-heading-xlarge"]')||document.querySelector('[class*="profile-card-title"]')||document.querySelector(".pv-text-details__left-panel h1");if(a)return a.textContent?.trim()||"";let d=document.title;return d&&d.includes("|")?d.split("|")[0].trim():""});if(console.log(` Profile name: "${n}"`),n){let r=await e.evaluate(()=>{let a=document.querySelectorAll('a[href*="custom-invite"]');return{count:a.length,labels:Array.from(a).map(d=>d.getAttribute("aria-label")?.slice(0,50))}});r.count>0&&console.log(` S0: ${r.count} custom-invite links: ${JSON.stringify(r.labels)}`),t=await e.evaluateHandle(a=>{let d=document.querySelectorAll('a[href*="custom-invite"]'),m=a.toLowerCase().split(" ")[0],f='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside';for(let h of d){let p=h.getBoundingClientRect();if(p.width===0||p.height===0||h.closest(f))continue;if((h.getAttribute("aria-label")||"").toLowerCase().includes(m))return h}return null},n);let u=t?.asElement?.()||null;if(u||await t?.dispose?.().catch(()=>{}),u)return console.log(" Found: Connect link (new LinkedIn 2025)"),{button:u,method:"connect_link"}}if(n){let r=n.split(" ")[0].toLowerCase();console.log(` Looking for button with name: "${r}"`);let u=await e.evaluate(d=>{let m=new RegExp("\\b"+d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i"),f=document.querySelectorAll("button[aria-label]");return Array.from(f).filter(p=>{let S=p.getAttribute("aria-label")||"";return(S.toLowerCase().includes("invite")||S.toLowerCase().includes("connect"))&&m.test(S)}).map(p=>p.getAttribute("aria-label")?.slice(0,50))},r);u.length>0&&console.log(` S1: matched buttons: ${JSON.stringify(u)}`),t=await e.evaluateHandle(d=>{let m=document.querySelectorAll("button[aria-label]"),f=new RegExp("\\b"+d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i");for(let h of m){let p=h.getAttribute("aria-label")||"";if((p.toLowerCase().includes("invite")||p.toLowerCase().includes("connect"))&&f.test(p))return h}return null},r);let a=t?.asElement?.()||null;if(a||await t?.dispose?.().catch(()=>{}),a)return console.log(" Found: button matching profile name"),{button:a,method:"name_matched_button"}}if(t=await e.$('button.artdeco-button--primary[aria-label*="Invite"]:not([class*="sticky-header"]):not([class*="muted"])'),t&&n){let r=await e.evaluate(a=>(a.getAttribute("aria-label")||"").toLowerCase(),t),u=n.split(" ")[0].toLowerCase();r.includes("invite")&&!r.includes(u)&&(console.log(` Skipping primary button: wrong person (${r})`),t=null)}if(t||(t=await e.$('button.artdeco-button--primary[aria-label="Connect"]:not([class*="sticky-header"]):not([class*="muted"])')),t)return console.log(" Found: primary button"),{button:t,method:"primary_button"};let o=await e.$$('button[aria-label*="Invite"][aria-label*="connect"]');o.length===0&&(o=await e.$$('button[aria-label="Connect"]'));let s=n?n.split(" ")[0].toLowerCase():"",i=null;for(let r of o){let u=await e.evaluate((a,d)=>{let m=a.className.includes("muted"),f=a.className.includes("sticky-header")||a.className.includes("sticky"),h=a.closest('[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"]')!==null,p=(a.getAttribute("aria-label")||"").toLowerCase(),S=p.includes("invite"),w=d?p.includes(d):!0;return{isMuted:m,isStickyHeader:f,inRecommendations:h,hasInvite:S,matchesName:w,ariaLabel:p}},r,s);if(!u.isMuted&&!u.isStickyHeader&&!u.inRecommendations){if(u.hasInvite&&!u.matchesName){console.log(` Skipping secondary button: wrong person (${u.ariaLabel})`);continue}i=r;break}}for(let r of o)r!==i&&await r.dispose().catch(()=>{});if(i)return console.log(" Found: secondary button"),{button:i,method:"secondary_button"};if(t=await e.$('section.pv-supplementary-action button[aria-label*="Invite"]'),t||(t=await e.$('section.pv-supplementary-action button[aria-label="Connect"]')),t)return console.log(" Found: supplementary section"),{button:t,method:"supplementary_section"};console.log(" Trying More actions dropdown...");let l=null,c=await e.$$('button[id*="profile-overflow-action"]');for(let r of c){let u=await e.evaluate(a=>{let d=a.getBoundingClientRect(),m=d.width>0&&d.height>0,f=a.closest('.sticky-header, [class*="sticky"]')!==null;return{isVisible:m,isInStickyHeader:f,top:d.top}},r);if(u.isVisible&&!u.isInStickyHeader){l=r,console.log(" Found More button by ID pattern (main)");break}}for(let r of c)r!==l&&await r.dispose().catch(()=>{});if(!l&&c.length>0&&(l=c[c.length-1],console.log(" Found More button by ID pattern (last)")),l||(l=await e.$('button[aria-label="More actions"]'),l&&console.log(" Found More button by aria-label")),!l){let r=await e.evaluateHandle(()=>{let a=Array.from(document.querySelectorAll("button, a")).find(m=>{let f=m.innerText?.trim(),h=m.getAttribute("aria-label")||"",p=m.getBoundingClientRect();return p.top<100||p.top>600||p.width===0?!1:f==="Follow"||f==="Message"||f==="Connect"||h.includes("Follow")||h.includes("Message")||h.includes("Invite")});if(!a)return null;let d=a.parentElement;for(let m=0;m<8&&d;m++){for(let f of d.querySelectorAll("button"))if(f.innerText?.trim()==="More"&&f!==a)return f;d=d.parentElement}return null});l=r?.asElement?.()||null,l||await r?.dispose?.().catch(()=>{}),l&&console.log(" Found More button by text (near profile actions)")}if(l)try{if(await e.evaluate(a=>a.scrollIntoView({behavior:"smooth",block:"center"}),l),await y(500),await e.evaluate(a=>a.click(),l),await y(2e3),!e.url().includes("/in/"))return console.log(" Redirect detected after More click, aborting"),null;let u=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]');if(u||(u=await e.$('.artdeco-dropdown__item[aria-label*="connect"]')),u||(u=await e.$('.artdeco-dropdown__item[aria-label="Connect"]')),u||(u=await e.$('div[role="button"][aria-label*="Invite"]')),u||(u=await e.$('div[role="button"][aria-label*="connect"]')),!u){let a=await e.evaluateHandle(()=>{let d=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content');for(let m of d){let f=m.querySelector('a[href*="custom-invite"]');if(f)return f;for(let h of m.querySelectorAll('a, div[role="menuitem"], div[role="button"]'))if(h.innerText?.trim()==="Connect")return h}return null});u=a?.asElement?.()||null,u||await a?.dispose?.().catch(()=>{})}if(!u){let a=await e.evaluate(()=>{let d=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content'),m=[];for(let f of d)for(let h of f.querySelectorAll('[role="menuitem"], a, div')){let p=h.innerText?.trim();p&&p.length<40&&m.push(p)}return[...new Set(m)].slice(0,10)});console.log(` More dropdown items: ${JSON.stringify(a)}`)}if(u)return console.log(" Found: More dropdown"),{button:u,method:"more_dropdown"};await e.keyboard.press("Escape")}catch(r){console.log(" More dropdown click failed:",r.message),await e.keyboard.press("Escape")}if(t=await e.$('button[aria-label*="Invite"]'),t&&n){let r=await e.evaluate(a=>(a.getAttribute("aria-label")||"").toLowerCase(),t),u=n.split(" ")[0].toLowerCase();r.includes("invite")&&!r.includes(u)&&(console.log(` Skipping generic button: wrong person (${r})`),t=null)}return t||(t=await e.$('button[aria-label="Connect"]')),t?(console.log(" Found: generic button"),{button:t,method:"generic_button"}):null}async function Ln(e,t){await e.evaluate(a=>a.scrollIntoView({behavior:"smooth",block:"center"}),t),await y(500);let n=await e.evaluate(a=>({tag:a.tagName,ariaLabel:a.getAttribute("aria-label"),href:a.getAttribute("href")}),t),s=n.tag==="A"&&n.href&&n.href.includes("custom-invite"),i=n.tag==="DIV",l=(n.ariaLabel||"").toLowerCase();if(l.includes("invite")){let a=await e.evaluate(()=>((document.querySelector("main h1")||document.querySelector("h1")||document.querySelector("main h2"))?.textContent?.trim()||"").split(" ")[0].toLowerCase());if(a&&!l.includes(a))return console.log(` \u2717 Identity guard: control is for someone else ("${n.ariaLabel}") \u2014 refusing to click (target: ${a})`),"wrong_target"}if(s){console.log(" Clicking custom-invite link (will navigate)..."),await Promise.all([e.waitForNavigation({waitUntil:"domcontentloaded",timeout:3e4}).catch(()=>{}),e.evaluate(d=>d.click(),t)]),await y(2e3);let a=e.url();if(a.includes("premium")||a.includes("redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium page - connection limit reached?"),await e.goBack(),await y(2e3),"premium_redirect"}else i?(await e.evaluate(a=>a.click(),t),await y(3e3)):(await e.evaluate(a=>a.click(),t),await y(3e3));let c=e.url();if(c.includes("/premium/")||c.includes("/redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium upsell page"),"premium_redirect";let r=await e.evaluate(()=>!!document.querySelector('[role="dialog"], .artdeco-modal, .send-invite')),u=e.url();return console.log(r?` \u2713 Connect sent \u2014 ${u}`:` \u26A0 No modal after connect click \u2014 ${u}`),"success"}async function Mn(e){console.log(" Upsell: Premium required for notes");let t=await e.$('button[aria-label="Dismiss"]')||await e.$("button.artdeco-modal__dismiss");t?await t.click():await e.keyboard.press("Escape"),await y(1500);let n=await He(e);if(n){await e.evaluate(s=>s.click(),n),await y(2e3);let o=await e.$('button[aria-label="Send without a note"]');if(o){try{await o.evaluate(s=>s.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (without note)"),!0}}return!1}async function Pn(e,t,n={}){let{source:o="unknown",skipQuotaGate:s=!1,skipQuotaRecord:i=!1}=n;if(!s){let c=Je();if(!c.allowed)return console.log(` \u26A0 Connection quota reached \u2014 not sending: ${c.reason}`),{success:!1,reason:"quota_exhausted",connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:c.reason,profileInfo:null}}let l=await qn(e,t,n);return l.connectionSent&&!i&&xt(t,o),l}async function qn(e,t,n={}){let{message:o=null,useCustomMessage:s=!0,skipIfPending:i=!0,skipIfConnected:l=!0,excludeLocations:c=[]}=n,r={success:!1,reason:null,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null};try{let u=t.split("/in/")[1]?.replace("/","")||"unknown";if(console.log(`
246
- --- Connecting: ${u} ---`),c.length>0){let w=oe()[t]?.location;if(Dt(w,c))return console.log(` \u26A0 Excluded location (stored): ${w}`),r.reason="excluded_location",r.profileInfo={location:w},r}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(5e3),await ie(e)&&(console.log(" Dismissed Premium overlay"),await y(2e3),await Rt(e,t),await y(2e3)),r.profileInfo=await e.evaluate(()=>{let w=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),$=R=>{let O=(R||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(O)},b={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},C=document.querySelector("main");if(!C)return b;let I=[...Array.from(C.querySelectorAll("h1")),...Array.from(C.querySelectorAll("h2"))],_=Array.from(C.querySelectorAll("h2")),D=I.find(R=>{let O=R.textContent&&R.textContent.trim();return O&&O.length>1&&O.length<100&&!w.has(O)&&O!=="0 notifications"}),B=D?D.textContent.trim():null,k=D?D.parentElement:null;for(;k&&k!==C&&!Array.from(k.children).filter(j=>j.tagName==="P").some(j=>{let N=j.textContent&&j.textContent.trim();return N&&N.length>5&&!$(N)});)k=k.parentElement;let F=null,K=null,L=null;if(k&&k!==C){let R=Array.from(k.children),O=R.filter(N=>N.tagName==="P").filter(N=>{let Y=N.textContent&&N.textContent.trim();return Y&&Y.length>5&&!$(Y)});O[0]&&(F=O[0].textContent.trim()),O[1]&&(K=O[1].textContent.trim());let j=R.filter(N=>N.tagName==="DIV");for(let N=j.length-1;N>=0;N--){let Y=j[N].textContent&&j[N].textContent.trim();if(Y&&!(B&&Y.startsWith(B))&&(L=Y.split(/[·•]/)[0].trim(),L))break}}let se=null;if(k){let R=k.querySelectorAll("p, span, div");for(let O of R){let j=(O.textContent||"").trim().replace(/^[·•]\s*/,"");if(j==="1st"||j==="2nd"||j==="3rd"){se=j;break}}}let ee=null,me=_.find(R=>R.textContent&&R.textContent.trim()==="About");if(me){let R=me.parentElement;for(;R&&R.tagName!=="SECTION";)R=R.parentElement;R&&(ee=(R.textContent||"").trim().replace(/^About\s*/,"").trim()||null,ee&&(ee=ee.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let de=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Ce=de&&de.src||null,_e=!!C.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:B,title:F,location:L,about:ee,company:K,connectionDegree:se,connectionsCount:null,mutualConnections:null,photoUrl:Ce,hasVerifiedBadge:_e}}),c.length>0){let w=r.profileInfo?.location,$=oe()[t]?.location,b=w||$;if(Dt(b,c))return console.log(` \u26A0 Excluded location (${w?"live":"stored"}): ${b}`),r.reason="excluded_location",r;!w&&$==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let d=await ke(e);if(d==="pending"&&i)return console.log(" \u26A0 Already pending - skipping"),r.reason="pending",r;if(d==="connected"&&l)return console.log(" \u26A0 Already connected - skipping"),r.reason="connected",r;await ie(e);let m=await He(e);if(!m&&(await ie(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await y(2e3),m=await He(e)),!m))return console.log(" \u2717 Connect not found"),r.reason="button_not_found",r;r.method=m.method;let f=await Ln(e,m.button);if(f==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),r.reason="wrong_target",r;if(f==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(4e3);let w=await ke(e);if(w==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;console.log(` Status after upsell: ${w} \u2014 trying More dropdown...`),await ie(e),await y(1e3);let $=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if($)try{await e.evaluate(C=>C.scrollIntoView({behavior:"smooth",block:"center"}),$),await y(500),await $.click().catch(()=>e.evaluate(C=>C.click(),$)),await y(2e3);let b=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(b){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(_=>_.click(),b),await y(3e3);let C=e.url();if(C.includes("/premium/")||C.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(3e3),r.reason="premium_required",r;if(await ke(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.method="more_dropdown",r.withCustomMessage=!1,r;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await y(500),r.reason="premium_required",r}catch(b){return console.log(" More dropdown failed:",b.message),await e.keyboard.press("Escape").catch(()=>{}),r.reason="premium_required",r}else return console.log(" \u2717 No More button found \u2014 Premium required"),r.reason="premium_required",r}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let w=await e.$('button[aria-label="Dismiss"]');return w&&await w.click(),await y(500),r.reason="email_required",r}let p=await e.$('button[aria-label="Add a note"]'),S=await e.$('button[aria-label="Send without a note"]');if(!p&&!S){let w=await e.evaluate(()=>{let $=document.querySelector("#interop-outlet")?.shadowRoot;if(!$)return{addNote:!1,sendWithout:!1};let b=$.querySelector('button[aria-label="Add a note"]'),C=$.querySelector('button[aria-label="Send without a note"]');return{addNote:!!b,sendWithout:!!C}});if(w.addNote){let $=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));p=$?.asElement?.()||null,p||await $.dispose().catch(()=>{})}if(w.sendWithout){let $=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));S=$?.asElement?.()||null,S||await $.dispose().catch(()=>{})}}if(s){if(p&&o){if(console.log(" Adding personalized note..."),await p.click(),await y(1500),await e.$("div.modal-upsell")){let b=await Mn(e);return r.success=b,r.connectionSent=b,r.reason=b?"sent_without_note_upsell":"upsell_failed",r.withCustomMessage=!1,r}let $=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if($){let b=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),C=o.replace("{name}",b);await $.type(C,{delay:20}),await y(500);let I=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if(I){try{await I.evaluate(_=>_.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (with note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_with_note",r.withCustomMessage=!0,r.messageSent=C,r}}}else if(S){console.log(" Sending without note...");try{await S.evaluate(w=>w.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}else if(p&&!o){console.log(" No message provided, sending without note...");let w=await e.$('button[aria-label="Send without a note"]');if(w){try{await w.evaluate($=>$.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}}else{console.log(" Sending without note (custom messages disabled)...");let w=S;if(w){try{await w.evaluate($=>$.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}if(m.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(4e3)),await ie(e),await y(500);let $=await e.$$('button[id*="profile-overflow-action"]'),b=null;for(let C of $){let I=await e.evaluate(_=>{let D=_.getBoundingClientRect();return{visible:D.width>0&&D.height>0,inSticky:!!_.closest('.sticky-header, [class*="sticky"]')}},C);if(I.visible&&!I.inSticky){b=C;break}}!b&&$.length>0&&(b=$[$.length-1]);for(let C of $)C!==b&&await C.dispose().catch(()=>{});if(b)try{await e.evaluate(I=>I.scrollIntoView({behavior:"smooth",block:"center"}),b),await y(500),await b.click().catch(()=>e.evaluate(I=>I.click(),b)),await y(2e3);let C=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(C){console.log(" Found Connect in More dropdown, clicking..."),r.method="more_dropdown",await e.evaluate(B=>B.click(),C),await y(3e3);let I=e.url();if(I.includes("/premium/")||I.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(3e3),await ke(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r):(r.reason="premium_required",r);if(await ke(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;let D=await e.$('button[aria-label="Send without a note"]');if(D){console.log(" Modal appeared via More dropdown, sending without note...");try{await D.evaluate(B=>B.click())}catch{}return await y(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(C){console.log(" More dropdown fallback failed:",C.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),r.reason="modal_failed",r}catch(u){console.error(` \u2717 Error: ${u.message}`),r.reason="error",r.error=u.message;let a=u.message.toLowerCase();if(a.includes("detached")||a.includes("session closed")||a.includes("target closed")||a.includes("browser has disconnected")||a.includes("protocol error"))return r.fatal=!0,r;try{await e.goto("about:blank",{timeout:1e4}),await y(1e3)}catch{r.fatal=!0}return r}}async function Tt(e,t,n={}){let{message:o=null,useCustomMessage:s=!0,maxConnections:i=20,viewOnly:l=!1,delayBetweenProfiles:c=3e3,onProfileProcessed:r=null,excludeLocations:u=[],source:a="unknown"}=n,d={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
246
+ --- Connecting: ${u} ---`),c.length>0){let w=oe()[t]?.location;if(Dt(w,c))return console.log(` \u26A0 Excluded location (stored): ${w}`),r.reason="excluded_location",r.profileInfo={location:w},r}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(5e3),await ie(e)&&(console.log(" Dismissed Premium overlay"),await y(2e3),await Rt(e,t),await y(2e3)),r.profileInfo=await e.evaluate(()=>{let w=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),$=R=>{let O=(R||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(O)},b={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},C=document.querySelector("main");if(!C)return b;let I=[...Array.from(C.querySelectorAll("h1")),...Array.from(C.querySelectorAll("h2"))],_=Array.from(C.querySelectorAll("h2")),D=I.find(R=>{let O=R.textContent&&R.textContent.trim();return O&&O.length>1&&O.length<100&&!w.has(O)&&O!=="0 notifications"}),B=D?D.textContent.trim():null,k=D?D.parentElement:null;for(;k&&k!==C&&!Array.from(k.children).filter(j=>j.tagName==="P").some(j=>{let N=j.textContent&&j.textContent.trim();return N&&N.length>5&&!$(N)});)k=k.parentElement;let F=null,K=null,L=null;if(k&&k!==C){let R=Array.from(k.children),O=R.filter(N=>N.tagName==="P").filter(N=>{let Y=N.textContent&&N.textContent.trim();return Y&&Y.length>5&&!$(Y)});O[0]&&(F=O[0].textContent.trim()),O[1]&&(K=O[1].textContent.trim());let j=R.filter(N=>N.tagName==="DIV");for(let N=j.length-1;N>=0;N--){let Y=j[N].textContent&&j[N].textContent.trim();if(Y&&!(B&&Y.startsWith(B))&&(L=Y.split(/[·•]/)[0].trim(),L))break}}let se=null;if(k){let R=k.querySelectorAll("p, span, div");for(let O of R){let j=(O.textContent||"").trim().replace(/^[·•]\s*/,"");if(j==="1st"||j==="2nd"||j==="3rd"){se=j;break}}}let ee=null,me=_.find(R=>R.textContent&&R.textContent.trim()==="About");if(me){let R=me.parentElement;for(;R&&R.tagName!=="SECTION";)R=R.parentElement;R&&(ee=(R.textContent||"").trim().replace(/^About\s*/,"").trim()||null,ee&&(ee=ee.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let de=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Ce=de&&de.src||null,_e=!!C.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:B,title:F,location:L,about:ee,company:K,connectionDegree:se,connectionsCount:null,mutualConnections:null,photoUrl:Ce,hasVerifiedBadge:_e}}),c.length>0){let w=r.profileInfo?.location,$=oe()[t]?.location,b=w||$;if(Dt(b,c))return console.log(` \u26A0 Excluded location (${w?"live":"stored"}): ${b}`),r.reason="excluded_location",r;!w&&$==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let d=await ke(e);if(r.profileInfo?.connectionDegree==="1st"&&d!=="pending"&&(d!=="connected"&&console.log(" (degree badge = 1st \u2192 already connected)"),d="connected"),d==="pending"&&i)return console.log(" \u26A0 Already pending - skipping"),r.reason="pending",r;if(d==="connected"&&l)return console.log(" \u26A0 Already connected - skipping"),r.reason="connected",r;await ie(e);let m=await He(e);if(!m&&(await ie(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await y(2e3),m=await He(e)),!m))return console.log(" \u2717 Connect not found"),r.reason="button_not_found",r;r.method=m.method;let f=await Ln(e,m.button);if(f==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),r.reason="wrong_target",r;if(f==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(4e3);let w=await ke(e);if(w==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;console.log(` Status after upsell: ${w} \u2014 trying More dropdown...`),await ie(e),await y(1e3);let $=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if($)try{await e.evaluate(C=>C.scrollIntoView({behavior:"smooth",block:"center"}),$),await y(500),await $.click().catch(()=>e.evaluate(C=>C.click(),$)),await y(2e3);let b=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(b){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(_=>_.click(),b),await y(3e3);let C=e.url();if(C.includes("/premium/")||C.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(3e3),r.reason="premium_required",r;if(await ke(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.method="more_dropdown",r.withCustomMessage=!1,r;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await y(500),r.reason="premium_required",r}catch(b){return console.log(" More dropdown failed:",b.message),await e.keyboard.press("Escape").catch(()=>{}),r.reason="premium_required",r}else return console.log(" \u2717 No More button found \u2014 Premium required"),r.reason="premium_required",r}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let w=await e.$('button[aria-label="Dismiss"]');return w&&await w.click(),await y(500),r.reason="email_required",r}let p=await e.$('button[aria-label="Add a note"]'),S=await e.$('button[aria-label="Send without a note"]');if(!p&&!S){let w=await e.evaluate(()=>{let $=document.querySelector("#interop-outlet")?.shadowRoot;if(!$)return{addNote:!1,sendWithout:!1};let b=$.querySelector('button[aria-label="Add a note"]'),C=$.querySelector('button[aria-label="Send without a note"]');return{addNote:!!b,sendWithout:!!C}});if(w.addNote){let $=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));p=$?.asElement?.()||null,p||await $.dispose().catch(()=>{})}if(w.sendWithout){let $=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));S=$?.asElement?.()||null,S||await $.dispose().catch(()=>{})}}if(s){if(p&&o){if(console.log(" Adding personalized note..."),await p.click(),await y(1500),await e.$("div.modal-upsell")){let b=await Mn(e);return r.success=b,r.connectionSent=b,r.reason=b?"sent_without_note_upsell":"upsell_failed",r.withCustomMessage=!1,r}let $=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if($){let b=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),C=o.replace("{name}",b);await $.type(C,{delay:20}),await y(500);let I=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if(I){try{await I.evaluate(_=>_.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (with note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_with_note",r.withCustomMessage=!0,r.messageSent=C,r}}}else if(S){console.log(" Sending without note...");try{await S.evaluate(w=>w.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}else if(p&&!o){console.log(" No message provided, sending without note...");let w=await e.$('button[aria-label="Send without a note"]');if(w){try{await w.evaluate($=>$.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}}else{console.log(" Sending without note (custom messages disabled)...");let w=S;if(w){try{await w.evaluate($=>$.click())}catch{console.log(" Click timeout, likely still sent")}return await y(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}if(m.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(4e3)),await ie(e),await y(500);let $=await e.$$('button[id*="profile-overflow-action"]'),b=null;for(let C of $){let I=await e.evaluate(_=>{let D=_.getBoundingClientRect();return{visible:D.width>0&&D.height>0,inSticky:!!_.closest('.sticky-header, [class*="sticky"]')}},C);if(I.visible&&!I.inSticky){b=C;break}}!b&&$.length>0&&(b=$[$.length-1]);for(let C of $)C!==b&&await C.dispose().catch(()=>{});if(b)try{await e.evaluate(I=>I.scrollIntoView({behavior:"smooth",block:"center"}),b),await y(500),await b.click().catch(()=>e.evaluate(I=>I.click(),b)),await y(2e3);let C=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(C){console.log(" Found Connect in More dropdown, clicking..."),r.method="more_dropdown",await e.evaluate(B=>B.click(),C),await y(3e3);let I=e.url();if(I.includes("/premium/")||I.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await y(3e3),await ke(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r):(r.reason="premium_required",r);if(await ke(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;let D=await e.$('button[aria-label="Send without a note"]');if(D){console.log(" Modal appeared via More dropdown, sending without note...");try{await D.evaluate(B=>B.click())}catch{}return await y(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(C){console.log(" More dropdown fallback failed:",C.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),r.reason="modal_failed",r}catch(u){console.error(` \u2717 Error: ${u.message}`),r.reason="error",r.error=u.message;let a=u.message.toLowerCase();if(a.includes("detached")||a.includes("session closed")||a.includes("target closed")||a.includes("browser has disconnected")||a.includes("protocol error"))return r.fatal=!0,r;try{await e.goto("about:blank",{timeout:1e4}),await y(1e3)}catch{r.fatal=!0}return r}}async function Tt(e,t,n={}){let{message:o=null,useCustomMessage:s=!0,maxConnections:i=20,viewOnly:l=!1,delayBetweenProfiles:c=3e3,onProfileProcessed:r=null,excludeLocations:u=[],source:a="unknown"}=n,d={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
247
247
  === Running Funnel: ${t.length} profiles ===`),console.log(`Mode: ${l?"View Only":`Connect (max ${i})`}`),l||console.log(`Custom messages: ${s?"Enabled":"Disabled (saving quota)"}`),u.length>0&&console.log(`Excluding locations: ${u.join(", ")}`),!l){let f=Ve();console.log(`Quota: today ${f.daily.sent}/${f.daily.max} | week ${f.weekly.sent}/${f.weekly.max}`)}console.log("");let m=0;for(let f=0;f<t.length;f++){let h=t[f];try{if(e.isClosed()){console.log(`
248
248
  \u26A0 Browser page is closed \u2014 aborting funnel`);break}}catch{console.log(`
249
249
  \u26A0 Browser disconnected \u2014 aborting funnel`);break}if(!h.profileUrl){console.log(`[${f+1}/${t.length}] Skipping - no URL`);continue}let p=vt(h.profileUrl);if(p==="pending"||p==="connected"||p==="sent_with_note"||p==="sent_without_note"||p==="sent_without_note_upsell"){console.log(`[${f+1}/${t.length}] ${h.name||h.profileUrl} \u2014 skipped (db: ${p})`),p==="pending"||p==="sent_with_note"||p==="sent_without_note"||p==="sent_without_note_upsell"?d.skipped.pending++:d.skipped.connected++,r&&await r(h,d,{success:!1,reason:p,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null});continue}console.log(`[${f+1}/${t.length}] ${h.name||h.profileUrl}`);let S=null;if(l){let w=await Fn(e,h.profileUrl);w?(Ie(h.profileUrl,{...w,source:a}),d.viewed++,S={success:!0,reason:"viewed",connectionSent:!1,profileInfo:w}):(d.errors++,S={success:!1,reason:"view_failed",connectionSent:!1,profileInfo:null})}else{if(d.connectionsSent>=i){console.log(` Max connections per session (${i}) reached`);break}let w=Je();if(!w.allowed){console.log(` \u26A0 Global quota exhausted: ${w.reason}`);break}if(S=await Pn(e,h.profileUrl,{message:o,useCustomMessage:s,excludeLocations:u,source:a,skipQuotaGate:!0}),S.success)d.connectionsSent++;else switch(S.reason){case"pending":d.skipped.pending++;break;case"connected":d.skipped.connected++;break;case"email_required":d.skipped.email++;break;case"button_not_found":d.skipped.notFound++;break;case"excluded_location":d.skipped.excludedLocation++;break;default:d.errors++}}if(S?.fatal){console.log(`
package/dist/run.mjs CHANGED
@@ -243,7 +243,7 @@ function findEntryContainer(root) {
243
243
  `),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
244
244
  `),console.error(` Or add ILML_TOKEN=... to .env
245
245
  `),process.exit(1));var we=Yn({token:So});var Ie=12e4;async function Le(e,{retries:t=2}={}){let o=process.env.NODE_EASY_APPLY_MAIN;if(!o||o.startsWith("YOUR_"))throw new Error('NODE_EASY_APPLY_MAIN is not configured in .env. Create a node in iLiveMyLife, add "assist" tag, and set the node ID in .env. See README.md for setup instructions.');for(let r=1;r<=t;r++)try{let n=await we.askLifebot(o,e,{timeout:Ie});return Ie=Math.max(12e4,Ie*.9),n.content}catch(n){if(n.constructor.name==="LifebotTimeoutError"&&r<t){Ie=Math.min(Ie*1.5,3e5),console.log(`Lifebot timeout (attempt ${r}/${t}), increasing timeout to ${Math.round(Ie/1e3)}s...`);continue}throw n}}async function It(e,t){(e=="City"||e=="Location (city)")&&(e="Tell my home city (not the city where position is).");let o=`Job application form field "${e}" \u2014 reply with ONLY the value to fill in, nothing else. `;return t&&(t==="Enter a decimal number larger than 0.0"&&(t="Enter a decimal number larger than 0"),o+=`Additional info: ${t}`),await Le(o)}async function it(e,t){let o=`Choose the best answer: ${e} Available options: ${t.join(", ")} `;return await Le(o)}async function Ve(e,t){let o=`Choose the best answer: ${e} Available options: ${t.join(", ")} `;return await Le(o)}jt();import{LIFEBOT_MESSAGE_TYPES as Tn}from"@ilivemylife/graph-sdk";Re();await ze();async function Wo(e,t){let o=e.url();if(o.includes("/in/"))return!1;if(o.includes("/login")||o.includes("/authwall")||o.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3);let r=e.url();return r.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${r.slice(0,80)}`),!0}function Go(e,t=[]){if(!e||!t||t.length===0)return!1;let o=e.toLowerCase();return t.some(r=>o.includes(r.toLowerCase()))}async function vr(e,t,o={}){let{extractExperience:r=!1,extractFeatured:n=!1,extractEducation:s=!1,extractSkills:l=!1,extractRecommendations:a=!1,extractCertifications:i=!1}=o;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),await te(e)&&(console.log(" Dismissed Premium overlay"),await g(1500),await Wo(e,t));let c=0;for(let v=0;v<2;v++){let b=await e.evaluate(()=>document.body.scrollHeight);for(let O=1;O<=6;O++)await e.evaluate(L=>window.scrollTo(0,L),b*O/6),await g(900);let E=await e.evaluate(()=>document.body.scrollHeight);if(E===c)break;c=E}await g(800);let d=await e.evaluate(()=>{let v=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),b=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),E=A=>{let R=(A||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(R)},O={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},L=document.querySelector("main");if(!L)return O;let W=[...Array.from(L.querySelectorAll("h1")),...Array.from(L.querySelectorAll("h2"))],C=Array.from(L.querySelectorAll("h2")),N=W.find(A=>{let R=A.textContent&&A.textContent.trim(),D=(R||"").replace(/\s*\(\d+\)$/,"").trim();return R&&R.length>1&&R.length<100&&!v.has(D)&&!b.has(D)}),Y=N?N.textContent.trim():null,U=N?N.parentElement:null;for(;U&&U!==L&&!Array.from(U.children).filter(R=>R.tagName==="P").some(R=>{let D=R.textContent&&R.textContent.trim();return D&&D.length>5&&!E(D)});)U=U.parentElement;let ae=null,H=null,_=null,B=null;if(U&&U!==L){let A=Array.from(U.children).filter(D=>D.tagName==="P").filter(D=>{let he=D.textContent&&D.textContent.trim();return he&&he.length>5&&!E(he)});if(A[0]&&(ae=A[0].textContent.trim()),A[1]){let D=A[1].textContent.trim().split(/\s*[·•]\s*/);H=D[0]||null,D.length>1&&(_=D.slice(1).join(" \xB7 "))}let R=Array.from(U.children).filter(D=>D.tagName==="DIV");for(let D=R.length-1;D>=0;D--){let he=R[D].textContent&&R[D].textContent.trim();if(he&&!(Y&&he.startsWith(Y))&&(B=he.split(/[·•]/)[0].trim(),B))break}}let T=null;if(U){let A=U.querySelectorAll("p, span, div");for(let R of A){let D=(R.textContent||"").trim().replace(/^[·•]\s*/,"");if(D==="1st"||D==="2nd"||D==="3rd"){T=D;break}}}let q=!!L.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),x=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),M=x&&x.src||null,j=L.textContent||"",I=null,G=j.match(/(\d+\+?)\s+connections\b/i);G&&(I=G[1]+" connections");let z=null,me=j.match(/(\d+)\s+mutual connection/i),Tt=j.match(/and\s+(\d+)\s+other mutual/i),Bn=j.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);me?z=parseInt(me[1],10):Tt?z=2+parseInt(Tt[1],10):Bn&&(z=2);let mo=null,ho=null,yo=C.find(A=>A.textContent&&A.textContent.trim()==="About");if(yo){let A=yo.parentElement;for(;A&&A.tagName!=="SECTION";)A=A.parentElement;if(A){let R=(A.textContent||"").trim();R=R.replace(/^About\s*/,"").trim();let D=R.match(/Top skills\s*(.+?)$/i);if(D){let Rt=D[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Gn=>Gn.trim()).filter(Boolean);Rt.length>0&&Rt.length<10&&(ho=Rt)}R=R.split(/\n?…\s*more/i)[0].trim(),R=R.split(/\n?\.\.\.\s*more/i)[0].trim(),R=R.split(/\bTop skills\b/i)[0].trim(),R=R.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),mo=R||null}}let go=null,bo=C.find(A=>A.textContent&&A.textContent.trim()==="Activity");if(bo){let A=bo.parentElement;for(;A&&A.tagName!=="SECTION";)A=A.parentElement;if(A){let R=(A.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);R&&(go=parseInt(R[1].replace(/,/g,""),10))}}let Jn=[...new Set(C.map(A=>(A.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(A=>A&&A.length>1&&A.length<60&&A!==Y).filter(A=>v.has(A)))],Be=document.body.textContent||"",Vn=/#OpenToWork\b/i.test(Be)||/\bOpen to work\b/.test(Be),Hn=/#Hiring\b/i.test(Be)||/\bI'?m hiring\b/i.test(Be)||/\bWe are hiring\b/i.test(Be);return{name:Y,title:ae,location:B,currentCompany:H,currentSchool:_,connectionDegree:T,hasVerifiedBadge:q,photoUrl:M,connectionsLevel:I,mutualConnectionsCount:z,followers:go,openToWork:Vn,hiring:Hn,about:mo,topSkills:ho,availableSections:Jn}});console.log(`Viewed: ${d.name} - ${d.title}`);let f=null,p=null,h=null,m=null,w=null,y=null;if(r||n||s||l||a||i){let v=await Promise.resolve().then(()=>(Ho(),Vo));r&&(f=await v.extractExperienceFromDetails(e,t),console.log(` + Experience: ${f.length} entries`)),n&&(p=await v.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${p.length} entries`)),s&&(h=await v.extractEducationFromDetails(e,t),console.log(` + Education: ${h.length} entries`)),l&&(m=await v.extractSkillsFromDetails(e,t),console.log(` + Skills: ${m.length} entries`)),a&&(w=await v.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${w.length} entries`)),i&&(y=await v.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${y.length} entries`))}return{...d,profileUrl:t,...f!==null&&{experience:f},...p!==null&&{featured:p},...h!==null&&{education:h},...m!==null&&{skillsFull:m},...w!==null&&{recommendations:w},...y!==null&&{certifications:y}}}catch(u){console.error(`Error viewing profile ${t}:`,u.message);try{await e.goto("about:blank",{timeout:1e4}),await g(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(u.message||""))throw u;return null}}async function tt(e){let t=await e.evaluate(()=>{let o='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside',r=u=>u&&!u.closest(o),n=u=>Array.from(document.querySelectorAll(u)).filter(r),s=n('button[aria-label*="Pending"], a[aria-label*="Pending"]'),l=n('button[aria-label*="Message"], a[aria-label*="Message"]')[0]||null,a=n('button[aria-label*="Invite"][aria-label*="connect"], button[aria-label="Connect"], a[href*="custom-invite"]')[0]||null,i={pendingCount:s.length,pendingLabels:s.map(u=>u.getAttribute("aria-label")),hasMessageBtn:!!l,hasConnectBtn:!!a};return s.length>0?{status:"pending",debug:i}:l&&!a?{status:"connected",debug:i}:document.body.innerText.includes("1st degree connection")?{status:"connected",debug:i}:{status:"not_connected",debug:i}});return console.log(" DEBUG connection status:",JSON.stringify(t.debug)),t.status}async function Jt(e){let t=null,o=await e.evaluate(()=>{let i=document.querySelector("h1")?.textContent?.trim();if(i&&!i.includes("notification"))return i;let u=document.querySelector('main h2, [class*="profile"] h2, [class*="top-card"] h2');if(u&&(i=u.textContent?.trim(),i&&!i.includes("notification")))return i;let c=document.querySelector('[class*="text-heading-xlarge"]')||document.querySelector('[class*="profile-card-title"]')||document.querySelector(".pv-text-details__left-panel h1");if(c)return c.textContent?.trim()||"";let d=document.title;return d&&d.includes("|")?d.split("|")[0].trim():""});if(console.log(` Profile name: "${o}"`),o){let i=await e.evaluate(()=>{let c=document.querySelectorAll('a[href*="custom-invite"]');return{count:c.length,labels:Array.from(c).map(d=>d.getAttribute("aria-label")?.slice(0,50))}});i.count>0&&console.log(` S0: ${i.count} custom-invite links: ${JSON.stringify(i.labels)}`),t=await e.evaluateHandle(c=>{let d=document.querySelectorAll('a[href*="custom-invite"]'),f=c.toLowerCase().split(" ")[0],p='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside';for(let h of d){let m=h.getBoundingClientRect();if(m.width===0||m.height===0||h.closest(p))continue;if((h.getAttribute("aria-label")||"").toLowerCase().includes(f))return h}return null},o);let u=t?.asElement?.()||null;if(u||await t?.dispose?.().catch(()=>{}),u)return console.log(" Found: Connect link (new LinkedIn 2025)"),{button:u,method:"connect_link"}}if(o){let i=o.split(" ")[0].toLowerCase();console.log(` Looking for button with name: "${i}"`);let u=await e.evaluate(d=>{let f=new RegExp("\\b"+d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i"),p=document.querySelectorAll("button[aria-label]");return Array.from(p).filter(m=>{let w=m.getAttribute("aria-label")||"";return(w.toLowerCase().includes("invite")||w.toLowerCase().includes("connect"))&&f.test(w)}).map(m=>m.getAttribute("aria-label")?.slice(0,50))},i);u.length>0&&console.log(` S1: matched buttons: ${JSON.stringify(u)}`),t=await e.evaluateHandle(d=>{let f=document.querySelectorAll("button[aria-label]"),p=new RegExp("\\b"+d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i");for(let h of f){let m=h.getAttribute("aria-label")||"";if((m.toLowerCase().includes("invite")||m.toLowerCase().includes("connect"))&&p.test(m))return h}return null},i);let c=t?.asElement?.()||null;if(c||await t?.dispose?.().catch(()=>{}),c)return console.log(" Found: button matching profile name"),{button:c,method:"name_matched_button"}}if(t=await e.$('button.artdeco-button--primary[aria-label*="Invite"]:not([class*="sticky-header"]):not([class*="muted"])'),t&&o){let i=await e.evaluate(c=>(c.getAttribute("aria-label")||"").toLowerCase(),t),u=o.split(" ")[0].toLowerCase();i.includes("invite")&&!i.includes(u)&&(console.log(` Skipping primary button: wrong person (${i})`),t=null)}if(t||(t=await e.$('button.artdeco-button--primary[aria-label="Connect"]:not([class*="sticky-header"]):not([class*="muted"])')),t)return console.log(" Found: primary button"),{button:t,method:"primary_button"};let r=await e.$$('button[aria-label*="Invite"][aria-label*="connect"]');r.length===0&&(r=await e.$$('button[aria-label="Connect"]'));let n=o?o.split(" ")[0].toLowerCase():"",s=null;for(let i of r){let u=await e.evaluate((c,d)=>{let f=c.className.includes("muted"),p=c.className.includes("sticky-header")||c.className.includes("sticky"),h=c.closest('[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"]')!==null,m=(c.getAttribute("aria-label")||"").toLowerCase(),w=m.includes("invite"),y=d?m.includes(d):!0;return{isMuted:f,isStickyHeader:p,inRecommendations:h,hasInvite:w,matchesName:y,ariaLabel:m}},i,n);if(!u.isMuted&&!u.isStickyHeader&&!u.inRecommendations){if(u.hasInvite&&!u.matchesName){console.log(` Skipping secondary button: wrong person (${u.ariaLabel})`);continue}s=i;break}}for(let i of r)i!==s&&await i.dispose().catch(()=>{});if(s)return console.log(" Found: secondary button"),{button:s,method:"secondary_button"};if(t=await e.$('section.pv-supplementary-action button[aria-label*="Invite"]'),t||(t=await e.$('section.pv-supplementary-action button[aria-label="Connect"]')),t)return console.log(" Found: supplementary section"),{button:t,method:"supplementary_section"};console.log(" Trying More actions dropdown...");let l=null,a=await e.$$('button[id*="profile-overflow-action"]');for(let i of a){let u=await e.evaluate(c=>{let d=c.getBoundingClientRect(),f=d.width>0&&d.height>0,p=c.closest('.sticky-header, [class*="sticky"]')!==null;return{isVisible:f,isInStickyHeader:p,top:d.top}},i);if(u.isVisible&&!u.isInStickyHeader){l=i,console.log(" Found More button by ID pattern (main)");break}}for(let i of a)i!==l&&await i.dispose().catch(()=>{});if(!l&&a.length>0&&(l=a[a.length-1],console.log(" Found More button by ID pattern (last)")),l||(l=await e.$('button[aria-label="More actions"]'),l&&console.log(" Found More button by aria-label")),!l){let i=await e.evaluateHandle(()=>{let c=Array.from(document.querySelectorAll("button, a")).find(f=>{let p=f.innerText?.trim(),h=f.getAttribute("aria-label")||"",m=f.getBoundingClientRect();return m.top<100||m.top>600||m.width===0?!1:p==="Follow"||p==="Message"||p==="Connect"||h.includes("Follow")||h.includes("Message")||h.includes("Invite")});if(!c)return null;let d=c.parentElement;for(let f=0;f<8&&d;f++){for(let p of d.querySelectorAll("button"))if(p.innerText?.trim()==="More"&&p!==c)return p;d=d.parentElement}return null});l=i?.asElement?.()||null,l||await i?.dispose?.().catch(()=>{}),l&&console.log(" Found More button by text (near profile actions)")}if(l)try{if(await e.evaluate(c=>c.scrollIntoView({behavior:"smooth",block:"center"}),l),await g(500),await e.evaluate(c=>c.click(),l),await g(2e3),!e.url().includes("/in/"))return console.log(" Redirect detected after More click, aborting"),null;let u=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]');if(u||(u=await e.$('.artdeco-dropdown__item[aria-label*="connect"]')),u||(u=await e.$('.artdeco-dropdown__item[aria-label="Connect"]')),u||(u=await e.$('div[role="button"][aria-label*="Invite"]')),u||(u=await e.$('div[role="button"][aria-label*="connect"]')),!u){let c=await e.evaluateHandle(()=>{let d=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content');for(let f of d){let p=f.querySelector('a[href*="custom-invite"]');if(p)return p;for(let h of f.querySelectorAll('a, div[role="menuitem"], div[role="button"]'))if(h.innerText?.trim()==="Connect")return h}return null});u=c?.asElement?.()||null,u||await c?.dispose?.().catch(()=>{})}if(!u){let c=await e.evaluate(()=>{let d=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content'),f=[];for(let p of d)for(let h of p.querySelectorAll('[role="menuitem"], a, div')){let m=h.innerText?.trim();m&&m.length<40&&f.push(m)}return[...new Set(f)].slice(0,10)});console.log(` More dropdown items: ${JSON.stringify(c)}`)}if(u)return console.log(" Found: More dropdown"),{button:u,method:"more_dropdown"};await e.keyboard.press("Escape")}catch(i){console.log(" More dropdown click failed:",i.message),await e.keyboard.press("Escape")}if(t=await e.$('button[aria-label*="Invite"]'),t&&o){let i=await e.evaluate(c=>(c.getAttribute("aria-label")||"").toLowerCase(),t),u=o.split(" ")[0].toLowerCase();i.includes("invite")&&!i.includes(u)&&(console.log(` Skipping generic button: wrong person (${i})`),t=null)}return t||(t=await e.$('button[aria-label="Connect"]')),t?(console.log(" Found: generic button"),{button:t,method:"generic_button"}):null}async function xr(e,t){await e.evaluate(c=>c.scrollIntoView({behavior:"smooth",block:"center"}),t),await g(500);let o=await e.evaluate(c=>({tag:c.tagName,ariaLabel:c.getAttribute("aria-label"),href:c.getAttribute("href")}),t),n=o.tag==="A"&&o.href&&o.href.includes("custom-invite"),s=o.tag==="DIV",l=(o.ariaLabel||"").toLowerCase();if(l.includes("invite")){let c=await e.evaluate(()=>((document.querySelector("main h1")||document.querySelector("h1")||document.querySelector("main h2"))?.textContent?.trim()||"").split(" ")[0].toLowerCase());if(c&&!l.includes(c))return console.log(` \u2717 Identity guard: control is for someone else ("${o.ariaLabel}") \u2014 refusing to click (target: ${c})`),"wrong_target"}if(n){console.log(" Clicking custom-invite link (will navigate)..."),await Promise.all([e.waitForNavigation({waitUntil:"domcontentloaded",timeout:3e4}).catch(()=>{}),e.evaluate(d=>d.click(),t)]),await g(2e3);let c=e.url();if(c.includes("premium")||c.includes("redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium page - connection limit reached?"),await e.goBack(),await g(2e3),"premium_redirect"}else s?(await e.evaluate(c=>c.click(),t),await g(3e3)):(await e.evaluate(c=>c.click(),t),await g(3e3));let a=e.url();if(a.includes("/premium/")||a.includes("/redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium upsell page"),"premium_redirect";let i=await e.evaluate(()=>!!document.querySelector('[role="dialog"], .artdeco-modal, .send-invite')),u=e.url();return console.log(i?` \u2713 Connect sent \u2014 ${u}`:` \u26A0 No modal after connect click \u2014 ${u}`),"success"}async function $r(e){console.log(" Upsell: Premium required for notes");let t=await e.$('button[aria-label="Dismiss"]')||await e.$("button.artdeco-modal__dismiss");t?await t.click():await e.keyboard.press("Escape"),await g(1500);let o=await Jt(e);if(o){await e.evaluate(n=>n.click(),o),await g(2e3);let r=await e.$('button[aria-label="Send without a note"]');if(r){try{await r.evaluate(n=>n.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (without note)"),!0}}return!1}async function Er(e,t,o={}){let{source:r="unknown",skipQuotaGate:n=!1,skipQuotaRecord:s=!1}=o;if(!n){let a=Ke();if(!a.allowed)return console.log(` \u26A0 Connection quota reached \u2014 not sending: ${a.reason}`),{success:!1,reason:"quota_exhausted",connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:a.reason,profileInfo:null}}let l=await Cr(e,t,o);return l.connectionSent&&!s&&wt(t,r),l}async function Cr(e,t,o={}){let{message:r=null,useCustomMessage:n=!0,skipIfPending:s=!0,skipIfConnected:l=!0,excludeLocations:a=[]}=o,i={success:!1,reason:null,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null};try{let u=t.split("/in/")[1]?.replace("/","")||"unknown";if(console.log(`
246
- --- Connecting: ${u} ---`),a.length>0){let y=X()[t]?.location;if(Go(y,a))return console.log(` \u26A0 Excluded location (stored): ${y}`),i.reason="excluded_location",i.profileInfo={location:y},i}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(5e3),await te(e)&&(console.log(" Dismissed Premium overlay"),await g(2e3),await Wo(e,t),await g(2e3)),i.profileInfo=await e.evaluate(()=>{let y=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),k=x=>{let M=(x||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(M)},v={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},b=document.querySelector("main");if(!b)return v;let E=[...Array.from(b.querySelectorAll("h1")),...Array.from(b.querySelectorAll("h2"))],O=Array.from(b.querySelectorAll("h2")),L=E.find(x=>{let M=x.textContent&&x.textContent.trim();return M&&M.length>1&&M.length<100&&!y.has(M)&&M!=="0 notifications"}),W=L?L.textContent.trim():null,C=L?L.parentElement:null;for(;C&&C!==b&&!Array.from(C.children).filter(j=>j.tagName==="P").some(j=>{let I=j.textContent&&j.textContent.trim();return I&&I.length>5&&!k(I)});)C=C.parentElement;let N=null,Y=null,U=null;if(C&&C!==b){let x=Array.from(C.children),M=x.filter(I=>I.tagName==="P").filter(I=>{let G=I.textContent&&I.textContent.trim();return G&&G.length>5&&!k(G)});M[0]&&(N=M[0].textContent.trim()),M[1]&&(Y=M[1].textContent.trim());let j=x.filter(I=>I.tagName==="DIV");for(let I=j.length-1;I>=0;I--){let G=j[I].textContent&&j[I].textContent.trim();if(G&&!(W&&G.startsWith(W))&&(U=G.split(/[·•]/)[0].trim(),U))break}}let ae=null;if(C){let x=C.querySelectorAll("p, span, div");for(let M of x){let j=(M.textContent||"").trim().replace(/^[·•]\s*/,"");if(j==="1st"||j==="2nd"||j==="3rd"){ae=j;break}}}let H=null,_=O.find(x=>x.textContent&&x.textContent.trim()==="About");if(_){let x=_.parentElement;for(;x&&x.tagName!=="SECTION";)x=x.parentElement;x&&(H=(x.textContent||"").trim().replace(/^About\s*/,"").trim()||null,H&&(H=H.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let B=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),T=B&&B.src||null,q=!!b.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:W,title:N,location:U,about:H,company:Y,connectionDegree:ae,connectionsCount:null,mutualConnections:null,photoUrl:T,hasVerifiedBadge:q}}),a.length>0){let y=i.profileInfo?.location,k=X()[t]?.location,v=y||k;if(Go(v,a))return console.log(` \u26A0 Excluded location (${y?"live":"stored"}): ${v}`),i.reason="excluded_location",i;!y&&k==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let d=await tt(e);if(d==="pending"&&s)return console.log(" \u26A0 Already pending - skipping"),i.reason="pending",i;if(d==="connected"&&l)return console.log(" \u26A0 Already connected - skipping"),i.reason="connected",i;await te(e);let f=await Jt(e);if(!f&&(await te(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await g(2e3),f=await Jt(e)),!f))return console.log(" \u2717 Connect not found"),i.reason="button_not_found",i;i.method=f.method;let p=await xr(e,f.button);if(p==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),i.reason="wrong_target",i;if(p==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(4e3);let y=await tt(e);if(y==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i;console.log(` Status after upsell: ${y} \u2014 trying More dropdown...`),await te(e),await g(1e3);let k=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if(k)try{await e.evaluate(b=>b.scrollIntoView({behavior:"smooth",block:"center"}),k),await g(500),await k.click().catch(()=>e.evaluate(b=>b.click(),k)),await g(2e3);let v=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(v){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(O=>O.click(),v),await g(3e3);let b=e.url();if(b.includes("/premium/")||b.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),i.reason="premium_required",i;if(await tt(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.method="more_dropdown",i.withCustomMessage=!1,i;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await g(500),i.reason="premium_required",i}catch(v){return console.log(" More dropdown failed:",v.message),await e.keyboard.press("Escape").catch(()=>{}),i.reason="premium_required",i}else return console.log(" \u2717 No More button found \u2014 Premium required"),i.reason="premium_required",i}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let y=await e.$('button[aria-label="Dismiss"]');return y&&await y.click(),await g(500),i.reason="email_required",i}let m=await e.$('button[aria-label="Add a note"]'),w=await e.$('button[aria-label="Send without a note"]');if(!m&&!w){let y=await e.evaluate(()=>{let k=document.querySelector("#interop-outlet")?.shadowRoot;if(!k)return{addNote:!1,sendWithout:!1};let v=k.querySelector('button[aria-label="Add a note"]'),b=k.querySelector('button[aria-label="Send without a note"]');return{addNote:!!v,sendWithout:!!b}});if(y.addNote){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));m=k?.asElement?.()||null,m||await k.dispose().catch(()=>{})}if(y.sendWithout){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));w=k?.asElement?.()||null,w||await k.dispose().catch(()=>{})}}if(n){if(m&&r){if(console.log(" Adding personalized note..."),await m.click(),await g(1500),await e.$("div.modal-upsell")){let v=await $r(e);return i.success=v,i.connectionSent=v,i.reason=v?"sent_without_note_upsell":"upsell_failed",i.withCustomMessage=!1,i}let k=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if(k){let v=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),b=r.replace("{name}",v);await k.type(b,{delay:20}),await g(500);let E=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if(E){try{await E.evaluate(O=>O.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (with note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_with_note",i.withCustomMessage=!0,i.messageSent=b,i}}}else if(w){console.log(" Sending without note...");try{await w.evaluate(y=>y.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (without note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}else if(m&&!r){console.log(" No message provided, sending without note...");let y=await e.$('button[aria-label="Send without a note"]');if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (without note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}}}else{console.log(" Sending without note (custom messages disabled)...");let y=w;if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (without note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}}if(f.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(4e3)),await te(e),await g(500);let k=await e.$$('button[id*="profile-overflow-action"]'),v=null;for(let b of k){let E=await e.evaluate(O=>{let L=O.getBoundingClientRect();return{visible:L.width>0&&L.height>0,inSticky:!!O.closest('.sticky-header, [class*="sticky"]')}},b);if(E.visible&&!E.inSticky){v=b;break}}!v&&k.length>0&&(v=k[k.length-1]);for(let b of k)b!==v&&await b.dispose().catch(()=>{});if(v)try{await e.evaluate(E=>E.scrollIntoView({behavior:"smooth",block:"center"}),v),await g(500),await v.click().catch(()=>e.evaluate(E=>E.click(),v)),await g(2e3);let b=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(b){console.log(" Found Connect in More dropdown, clicking..."),i.method="more_dropdown",await e.evaluate(W=>W.click(),b),await g(3e3);let E=e.url();if(E.includes("/premium/")||E.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),await tt(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i):(i.reason="premium_required",i);if(await tt(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i;let L=await e.$('button[aria-label="Send without a note"]');if(L){console.log(" Modal appeared via More dropdown, sending without note...");try{await L.evaluate(W=>W.click())}catch{}return await g(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(b){console.log(" More dropdown fallback failed:",b.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),i.reason="modal_failed",i}catch(u){console.error(` \u2717 Error: ${u.message}`),i.reason="error",i.error=u.message;let c=u.message.toLowerCase();if(c.includes("detached")||c.includes("session closed")||c.includes("target closed")||c.includes("browser has disconnected")||c.includes("protocol error"))return i.fatal=!0,i;try{await e.goto("about:blank",{timeout:1e4}),await g(1e3)}catch{i.fatal=!0}return i}}async function Vt(e,t,o={}){let{message:r=null,useCustomMessage:n=!0,maxConnections:s=20,viewOnly:l=!1,delayBetweenProfiles:a=3e3,onProfileProcessed:i=null,excludeLocations:u=[],source:c="unknown"}=o,d={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
246
+ --- Connecting: ${u} ---`),a.length>0){let y=X()[t]?.location;if(Go(y,a))return console.log(` \u26A0 Excluded location (stored): ${y}`),i.reason="excluded_location",i.profileInfo={location:y},i}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(5e3),await te(e)&&(console.log(" Dismissed Premium overlay"),await g(2e3),await Wo(e,t),await g(2e3)),i.profileInfo=await e.evaluate(()=>{let y=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),k=x=>{let M=(x||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(M)},v={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},b=document.querySelector("main");if(!b)return v;let E=[...Array.from(b.querySelectorAll("h1")),...Array.from(b.querySelectorAll("h2"))],O=Array.from(b.querySelectorAll("h2")),L=E.find(x=>{let M=x.textContent&&x.textContent.trim();return M&&M.length>1&&M.length<100&&!y.has(M)&&M!=="0 notifications"}),W=L?L.textContent.trim():null,C=L?L.parentElement:null;for(;C&&C!==b&&!Array.from(C.children).filter(j=>j.tagName==="P").some(j=>{let I=j.textContent&&j.textContent.trim();return I&&I.length>5&&!k(I)});)C=C.parentElement;let N=null,Y=null,U=null;if(C&&C!==b){let x=Array.from(C.children),M=x.filter(I=>I.tagName==="P").filter(I=>{let G=I.textContent&&I.textContent.trim();return G&&G.length>5&&!k(G)});M[0]&&(N=M[0].textContent.trim()),M[1]&&(Y=M[1].textContent.trim());let j=x.filter(I=>I.tagName==="DIV");for(let I=j.length-1;I>=0;I--){let G=j[I].textContent&&j[I].textContent.trim();if(G&&!(W&&G.startsWith(W))&&(U=G.split(/[·•]/)[0].trim(),U))break}}let ae=null;if(C){let x=C.querySelectorAll("p, span, div");for(let M of x){let j=(M.textContent||"").trim().replace(/^[·•]\s*/,"");if(j==="1st"||j==="2nd"||j==="3rd"){ae=j;break}}}let H=null,_=O.find(x=>x.textContent&&x.textContent.trim()==="About");if(_){let x=_.parentElement;for(;x&&x.tagName!=="SECTION";)x=x.parentElement;x&&(H=(x.textContent||"").trim().replace(/^About\s*/,"").trim()||null,H&&(H=H.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let B=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),T=B&&B.src||null,q=!!b.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:W,title:N,location:U,about:H,company:Y,connectionDegree:ae,connectionsCount:null,mutualConnections:null,photoUrl:T,hasVerifiedBadge:q}}),a.length>0){let y=i.profileInfo?.location,k=X()[t]?.location,v=y||k;if(Go(v,a))return console.log(` \u26A0 Excluded location (${y?"live":"stored"}): ${v}`),i.reason="excluded_location",i;!y&&k==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let d=await tt(e);if(i.profileInfo?.connectionDegree==="1st"&&d!=="pending"&&(d!=="connected"&&console.log(" (degree badge = 1st \u2192 already connected)"),d="connected"),d==="pending"&&s)return console.log(" \u26A0 Already pending - skipping"),i.reason="pending",i;if(d==="connected"&&l)return console.log(" \u26A0 Already connected - skipping"),i.reason="connected",i;await te(e);let f=await Jt(e);if(!f&&(await te(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await g(2e3),f=await Jt(e)),!f))return console.log(" \u2717 Connect not found"),i.reason="button_not_found",i;i.method=f.method;let p=await xr(e,f.button);if(p==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),i.reason="wrong_target",i;if(p==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(4e3);let y=await tt(e);if(y==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i;console.log(` Status after upsell: ${y} \u2014 trying More dropdown...`),await te(e),await g(1e3);let k=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if(k)try{await e.evaluate(b=>b.scrollIntoView({behavior:"smooth",block:"center"}),k),await g(500),await k.click().catch(()=>e.evaluate(b=>b.click(),k)),await g(2e3);let v=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(v){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(O=>O.click(),v),await g(3e3);let b=e.url();if(b.includes("/premium/")||b.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),i.reason="premium_required",i;if(await tt(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.method="more_dropdown",i.withCustomMessage=!1,i;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await g(500),i.reason="premium_required",i}catch(v){return console.log(" More dropdown failed:",v.message),await e.keyboard.press("Escape").catch(()=>{}),i.reason="premium_required",i}else return console.log(" \u2717 No More button found \u2014 Premium required"),i.reason="premium_required",i}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let y=await e.$('button[aria-label="Dismiss"]');return y&&await y.click(),await g(500),i.reason="email_required",i}let m=await e.$('button[aria-label="Add a note"]'),w=await e.$('button[aria-label="Send without a note"]');if(!m&&!w){let y=await e.evaluate(()=>{let k=document.querySelector("#interop-outlet")?.shadowRoot;if(!k)return{addNote:!1,sendWithout:!1};let v=k.querySelector('button[aria-label="Add a note"]'),b=k.querySelector('button[aria-label="Send without a note"]');return{addNote:!!v,sendWithout:!!b}});if(y.addNote){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));m=k?.asElement?.()||null,m||await k.dispose().catch(()=>{})}if(y.sendWithout){let k=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));w=k?.asElement?.()||null,w||await k.dispose().catch(()=>{})}}if(n){if(m&&r){if(console.log(" Adding personalized note..."),await m.click(),await g(1500),await e.$("div.modal-upsell")){let v=await $r(e);return i.success=v,i.connectionSent=v,i.reason=v?"sent_without_note_upsell":"upsell_failed",i.withCustomMessage=!1,i}let k=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if(k){let v=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),b=r.replace("{name}",v);await k.type(b,{delay:20}),await g(500);let E=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if(E){try{await E.evaluate(O=>O.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (with note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_with_note",i.withCustomMessage=!0,i.messageSent=b,i}}}else if(w){console.log(" Sending without note...");try{await w.evaluate(y=>y.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (without note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}else if(m&&!r){console.log(" No message provided, sending without note...");let y=await e.$('button[aria-label="Send without a note"]');if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (without note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}}}else{console.log(" Sending without note (custom messages disabled)...");let y=w;if(y){try{await y.evaluate(k=>k.click())}catch{console.log(" Click timeout, likely still sent")}return await g(3e3),console.log(" \u2713 Connection sent (without note)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}}if(f.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(4e3)),await te(e),await g(500);let k=await e.$$('button[id*="profile-overflow-action"]'),v=null;for(let b of k){let E=await e.evaluate(O=>{let L=O.getBoundingClientRect();return{visible:L.width>0&&L.height>0,inSticky:!!O.closest('.sticky-header, [class*="sticky"]')}},b);if(E.visible&&!E.inSticky){v=b;break}}!v&&k.length>0&&(v=k[k.length-1]);for(let b of k)b!==v&&await b.dispose().catch(()=>{});if(v)try{await e.evaluate(E=>E.scrollIntoView({behavior:"smooth",block:"center"}),v),await g(500),await v.click().catch(()=>e.evaluate(E=>E.click(),v)),await g(2e3);let b=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(b){console.log(" Found Connect in More dropdown, clicking..."),i.method="more_dropdown",await e.evaluate(W=>W.click(),b),await g(3e3);let E=e.url();if(E.includes("/premium/")||E.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),await tt(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i):(i.reason="premium_required",i);if(await tt(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i;let L=await e.$('button[aria-label="Send without a note"]');if(L){console.log(" Modal appeared via More dropdown, sending without note...");try{await L.evaluate(W=>W.click())}catch{}return await g(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),i.success=!0,i.connectionSent=!0,i.reason="sent_without_note",i.withCustomMessage=!1,i}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(b){console.log(" More dropdown fallback failed:",b.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),i.reason="modal_failed",i}catch(u){console.error(` \u2717 Error: ${u.message}`),i.reason="error",i.error=u.message;let c=u.message.toLowerCase();if(c.includes("detached")||c.includes("session closed")||c.includes("target closed")||c.includes("browser has disconnected")||c.includes("protocol error"))return i.fatal=!0,i;try{await e.goto("about:blank",{timeout:1e4}),await g(1e3)}catch{i.fatal=!0}return i}}async function Vt(e,t,o={}){let{message:r=null,useCustomMessage:n=!0,maxConnections:s=20,viewOnly:l=!1,delayBetweenProfiles:a=3e3,onProfileProcessed:i=null,excludeLocations:u=[],source:c="unknown"}=o,d={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
247
247
  === Running Funnel: ${t.length} profiles ===`),console.log(`Mode: ${l?"View Only":`Connect (max ${s})`}`),l||console.log(`Custom messages: ${n?"Enabled":"Disabled (saving quota)"}`),u.length>0&&console.log(`Excluding locations: ${u.join(", ")}`),!l){let p=Qe();console.log(`Quota: today ${p.daily.sent}/${p.daily.max} | week ${p.weekly.sent}/${p.weekly.max}`)}console.log("");let f=0;for(let p=0;p<t.length;p++){let h=t[p];try{if(e.isClosed()){console.log(`
248
248
  \u26A0 Browser page is closed \u2014 aborting funnel`);break}}catch{console.log(`
249
249
  \u26A0 Browser disconnected \u2014 aborting funnel`);break}if(!h.profileUrl){console.log(`[${p+1}/${t.length}] Skipping - no URL`);continue}let m=yt(h.profileUrl);if(m==="pending"||m==="connected"||m==="sent_with_note"||m==="sent_without_note"||m==="sent_without_note_upsell"){console.log(`[${p+1}/${t.length}] ${h.name||h.profileUrl} \u2014 skipped (db: ${m})`),m==="pending"||m==="sent_with_note"||m==="sent_without_note"||m==="sent_without_note_upsell"?d.skipped.pending++:d.skipped.connected++,i&&await i(h,d,{success:!1,reason:m,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null});continue}console.log(`[${p+1}/${t.length}] ${h.name||h.profileUrl}`);let w=null;if(l){let y=await vr(e,h.profileUrl);y?(ye(h.profileUrl,{...y,source:c}),d.viewed++,w={success:!0,reason:"viewed",connectionSent:!1,profileInfo:y}):(d.errors++,w={success:!1,reason:"view_failed",connectionSent:!1,profileInfo:null})}else{if(d.connectionsSent>=s){console.log(` Max connections per session (${s}) reached`);break}let y=Ke();if(!y.allowed){console.log(` \u26A0 Global quota exhausted: ${y.reason}`);break}if(w=await Er(e,h.profileUrl,{message:r,useCustomMessage:n,excludeLocations:u,source:c,skipQuotaGate:!0}),w.success)d.connectionsSent++;else switch(w.reason){case"pending":d.skipped.pending++;break;case"connected":d.skipped.connected++;break;case"email_required":d.skipped.email++;break;case"button_not_found":d.skipped.notFound++;break;case"excluded_location":d.skipped.excludedLocation++;break;default:d.errors++}}if(w?.fatal){console.log(`
package/dist/syncAll.mjs CHANGED
@@ -236,7 +236,7 @@ function findEntryContainer(root) {
236
236
  return candidates[0]?.el;
237
237
  }
238
238
  `});var go={};Ue(go,{clickConnectButton:()=>Qt,default:()=>Pr,detectConnectionStatus:()=>xe,findConnectButton:()=>rt,runFunnel:()=>po,sendConnectionRequest:()=>Xt,shouldExcludeLocation:()=>ht,viewProfile:()=>Kt});async function mo(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}function ht(e,t=[]){if(!e||!t||t.length===0)return!1;let n=e.toLowerCase();return t.some(o=>n.includes(o.toLowerCase()))}async function Kt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:s=!1,extractEducation:i=!1,extractSkills:a=!1,extractRecommendations:l=!1,extractCertifications:r=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),await he(e)&&(console.log(" Dismissed Premium overlay"),await $(1500),await mo(e,t));let c=0;for(let g=0;g<2;g++){let h=await e.evaluate(()=>document.body.scrollHeight);for(let C=1;C<=6;C++)await e.evaluate(_=>window.scrollTo(0,_),h*C/6),await $(900);let k=await e.evaluate(()=>document.body.scrollHeight);if(k===c)break;c=k}await $(800);let f=await e.evaluate(()=>{let g=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),h=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),k=R=>{let D=(R||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(D)},C={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},_=document.querySelector("main");if(!_)return C;let I=[...Array.from(_.querySelectorAll("h1")),...Array.from(_.querySelectorAll("h2"))],T=Array.from(_.querySelectorAll("h2")),L=I.find(R=>{let D=R.textContent&&R.textContent.trim(),O=(D||"").replace(/\s*\(\d+\)$/,"").trim();return D&&D.length>1&&D.length<100&&!g.has(O)&&!h.has(O)}),G=L?L.textContent.trim():null,v=L?L.parentElement:null;for(;v&&v!==_&&!Array.from(v.children).filter(D=>D.tagName==="P").some(D=>{let O=D.textContent&&D.textContent.trim();return O&&O.length>5&&!k(O)});)v=v.parentElement;let x=null,A=null,M=null,q=null;if(v&&v!==_){let R=Array.from(v.children).filter(O=>O.tagName==="P").filter(O=>{let de=O.textContent&&O.textContent.trim();return de&&de.length>5&&!k(de)});if(R[0]&&(x=R[0].textContent.trim()),R[1]){let O=R[1].textContent.trim().split(/\s*[·•]\s*/);A=O[0]||null,O.length>1&&(M=O.slice(1).join(" \xB7 "))}let D=Array.from(v.children).filter(O=>O.tagName==="DIV");for(let O=D.length-1;O>=0;O--){let de=D[O].textContent&&D[O].textContent.trim();if(de&&!(G&&de.startsWith(G))&&(q=de.split(/[·•]/)[0].trim(),q))break}}let re=null;if(v){let R=v.querySelectorAll("p, span, div");for(let D of R){let O=(D.textContent||"").trim().replace(/^[·•]\s*/,"");if(O==="1st"||O==="2nd"||O==="3rd"){re=O;break}}}let ie=!!_.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),j=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),F=j&&j.src||null,P=_.textContent||"",H=null,oe=P.match(/(\d+\+?)\s+connections\b/i);oe&&(H=oe[1]+" connections");let at=null,sn=P.match(/(\d+)\s+mutual connection/i),rn=P.match(/and\s+(\d+)\s+other mutual/i),Co=P.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);sn?at=parseInt(sn[1],10):rn?at=2+parseInt(rn[1],10):Co&&(at=2);let an=null,ln=null,cn=T.find(R=>R.textContent&&R.textContent.trim()==="About");if(cn){let R=cn.parentElement;for(;R&&R.tagName!=="SECTION";)R=R.parentElement;if(R){let D=(R.textContent||"").trim();D=D.replace(/^About\s*/,"").trim();let O=D.match(/Top skills\s*(.+?)$/i);if(O){let wt=O[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Ao=>Ao.trim()).filter(Boolean);wt.length>0&&wt.length<10&&(ln=wt)}D=D.split(/\n?…\s*more/i)[0].trim(),D=D.split(/\n?\.\.\.\s*more/i)[0].trim(),D=D.split(/\bTop skills\b/i)[0].trim(),D=D.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),an=D||null}}let un=null,dn=T.find(R=>R.textContent&&R.textContent.trim()==="Activity");if(dn){let R=dn.parentElement;for(;R&&R.tagName!=="SECTION";)R=R.parentElement;if(R){let D=(R.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);D&&(un=parseInt(D[1].replace(/,/g,""),10))}}let Eo=[...new Set(T.map(R=>(R.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(R=>R&&R.length>1&&R.length<60&&R!==G).filter(R=>g.has(R)))],Le=document.body.textContent||"",xo=/#OpenToWork\b/i.test(Le)||/\bOpen to work\b/.test(Le),_o=/#Hiring\b/i.test(Le)||/\bI'?m hiring\b/i.test(Le)||/\bWe are hiring\b/i.test(Le);return{name:G,title:x,location:q,currentCompany:A,currentSchool:M,connectionDegree:re,hasVerifiedBadge:ie,photoUrl:F,connectionsLevel:H,mutualConnectionsCount:at,followers:un,openToWork:xo,hiring:_o,about:an,topSkills:ln,availableSections:Eo}});console.log(`Viewed: ${f.name} - ${f.title}`);let d=null,m=null,y=null,p=null,S=null,w=null;if(o||s||i||a||l||r){let g=await Promise.resolve().then(()=>(fo(),uo));o&&(d=await g.extractExperienceFromDetails(e,t),console.log(` + Experience: ${d.length} entries`)),s&&(m=await g.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${m.length} entries`)),i&&(y=await g.extractEducationFromDetails(e,t),console.log(` + Education: ${y.length} entries`)),a&&(p=await g.extractSkillsFromDetails(e,t),console.log(` + Skills: ${p.length} entries`)),l&&(S=await g.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${S.length} entries`)),r&&(w=await g.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${w.length} entries`))}return{...f,profileUrl:t,...d!==null&&{experience:d},...m!==null&&{featured:m},...y!==null&&{education:y},...p!==null&&{skillsFull:p},...S!==null&&{recommendations:S},...w!==null&&{certifications:w}}}catch(u){console.error(`Error viewing profile ${t}:`,u.message);try{await e.goto("about:blank",{timeout:1e4}),await $(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(u.message||""))throw u;return null}}async function xe(e){let t=await e.evaluate(()=>{let n='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside',o=u=>u&&!u.closest(n),s=u=>Array.from(document.querySelectorAll(u)).filter(o),i=s('button[aria-label*="Pending"], a[aria-label*="Pending"]'),a=s('button[aria-label*="Message"], a[aria-label*="Message"]')[0]||null,l=s('button[aria-label*="Invite"][aria-label*="connect"], button[aria-label="Connect"], a[href*="custom-invite"]')[0]||null,r={pendingCount:i.length,pendingLabels:i.map(u=>u.getAttribute("aria-label")),hasMessageBtn:!!a,hasConnectBtn:!!l};return i.length>0?{status:"pending",debug:r}:a&&!l?{status:"connected",debug:r}:document.body.innerText.includes("1st degree connection")?{status:"connected",debug:r}:{status:"not_connected",debug:r}});return console.log(" DEBUG connection status:",JSON.stringify(t.debug)),t.status}async function rt(e){let t=null,n=await e.evaluate(()=>{let r=document.querySelector("h1")?.textContent?.trim();if(r&&!r.includes("notification"))return r;let u=document.querySelector('main h2, [class*="profile"] h2, [class*="top-card"] h2');if(u&&(r=u.textContent?.trim(),r&&!r.includes("notification")))return r;let c=document.querySelector('[class*="text-heading-xlarge"]')||document.querySelector('[class*="profile-card-title"]')||document.querySelector(".pv-text-details__left-panel h1");if(c)return c.textContent?.trim()||"";let f=document.title;return f&&f.includes("|")?f.split("|")[0].trim():""});if(console.log(` Profile name: "${n}"`),n){let r=await e.evaluate(()=>{let c=document.querySelectorAll('a[href*="custom-invite"]');return{count:c.length,labels:Array.from(c).map(f=>f.getAttribute("aria-label")?.slice(0,50))}});r.count>0&&console.log(` S0: ${r.count} custom-invite links: ${JSON.stringify(r.labels)}`),t=await e.evaluateHandle(c=>{let f=document.querySelectorAll('a[href*="custom-invite"]'),d=c.toLowerCase().split(" ")[0],m='[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"], [class*="discover"], [class*="similar"], aside';for(let y of f){let p=y.getBoundingClientRect();if(p.width===0||p.height===0||y.closest(m))continue;if((y.getAttribute("aria-label")||"").toLowerCase().includes(d))return y}return null},n);let u=t?.asElement?.()||null;if(u||await t?.dispose?.().catch(()=>{}),u)return console.log(" Found: Connect link (new LinkedIn 2025)"),{button:u,method:"connect_link"}}if(n){let r=n.split(" ")[0].toLowerCase();console.log(` Looking for button with name: "${r}"`);let u=await e.evaluate(f=>{let d=new RegExp("\\b"+f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i"),m=document.querySelectorAll("button[aria-label]");return Array.from(m).filter(p=>{let S=p.getAttribute("aria-label")||"";return(S.toLowerCase().includes("invite")||S.toLowerCase().includes("connect"))&&d.test(S)}).map(p=>p.getAttribute("aria-label")?.slice(0,50))},r);u.length>0&&console.log(` S1: matched buttons: ${JSON.stringify(u)}`),t=await e.evaluateHandle(f=>{let d=document.querySelectorAll("button[aria-label]"),m=new RegExp("\\b"+f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i");for(let y of d){let p=y.getAttribute("aria-label")||"";if((p.toLowerCase().includes("invite")||p.toLowerCase().includes("connect"))&&m.test(p))return y}return null},r);let c=t?.asElement?.()||null;if(c||await t?.dispose?.().catch(()=>{}),c)return console.log(" Found: button matching profile name"),{button:c,method:"name_matched_button"}}if(t=await e.$('button.artdeco-button--primary[aria-label*="Invite"]:not([class*="sticky-header"]):not([class*="muted"])'),t&&n){let r=await e.evaluate(c=>(c.getAttribute("aria-label")||"").toLowerCase(),t),u=n.split(" ")[0].toLowerCase();r.includes("invite")&&!r.includes(u)&&(console.log(` Skipping primary button: wrong person (${r})`),t=null)}if(t||(t=await e.$('button.artdeco-button--primary[aria-label="Connect"]:not([class*="sticky-header"]):not([class*="muted"])')),t)return console.log(" Found: primary button"),{button:t,method:"primary_button"};let o=await e.$$('button[aria-label*="Invite"][aria-label*="connect"]');o.length===0&&(o=await e.$$('button[aria-label="Connect"]'));let s=n?n.split(" ")[0].toLowerCase():"",i=null;for(let r of o){let u=await e.evaluate((c,f)=>{let d=c.className.includes("muted"),m=c.className.includes("sticky-header")||c.className.includes("sticky"),y=c.closest('[class*="pymk"], [class*="people-also-viewed"], [class*="browse-map"]')!==null,p=(c.getAttribute("aria-label")||"").toLowerCase(),S=p.includes("invite"),w=f?p.includes(f):!0;return{isMuted:d,isStickyHeader:m,inRecommendations:y,hasInvite:S,matchesName:w,ariaLabel:p}},r,s);if(!u.isMuted&&!u.isStickyHeader&&!u.inRecommendations){if(u.hasInvite&&!u.matchesName){console.log(` Skipping secondary button: wrong person (${u.ariaLabel})`);continue}i=r;break}}for(let r of o)r!==i&&await r.dispose().catch(()=>{});if(i)return console.log(" Found: secondary button"),{button:i,method:"secondary_button"};if(t=await e.$('section.pv-supplementary-action button[aria-label*="Invite"]'),t||(t=await e.$('section.pv-supplementary-action button[aria-label="Connect"]')),t)return console.log(" Found: supplementary section"),{button:t,method:"supplementary_section"};console.log(" Trying More actions dropdown...");let a=null,l=await e.$$('button[id*="profile-overflow-action"]');for(let r of l){let u=await e.evaluate(c=>{let f=c.getBoundingClientRect(),d=f.width>0&&f.height>0,m=c.closest('.sticky-header, [class*="sticky"]')!==null;return{isVisible:d,isInStickyHeader:m,top:f.top}},r);if(u.isVisible&&!u.isInStickyHeader){a=r,console.log(" Found More button by ID pattern (main)");break}}for(let r of l)r!==a&&await r.dispose().catch(()=>{});if(!a&&l.length>0&&(a=l[l.length-1],console.log(" Found More button by ID pattern (last)")),a||(a=await e.$('button[aria-label="More actions"]'),a&&console.log(" Found More button by aria-label")),!a){let r=await e.evaluateHandle(()=>{let c=Array.from(document.querySelectorAll("button, a")).find(d=>{let m=d.innerText?.trim(),y=d.getAttribute("aria-label")||"",p=d.getBoundingClientRect();return p.top<100||p.top>600||p.width===0?!1:m==="Follow"||m==="Message"||m==="Connect"||y.includes("Follow")||y.includes("Message")||y.includes("Invite")});if(!c)return null;let f=c.parentElement;for(let d=0;d<8&&f;d++){for(let m of f.querySelectorAll("button"))if(m.innerText?.trim()==="More"&&m!==c)return m;f=f.parentElement}return null});a=r?.asElement?.()||null,a||await r?.dispose?.().catch(()=>{}),a&&console.log(" Found More button by text (near profile actions)")}if(a)try{if(await e.evaluate(c=>c.scrollIntoView({behavior:"smooth",block:"center"}),a),await $(500),await e.evaluate(c=>c.click(),a),await $(2e3),!e.url().includes("/in/"))return console.log(" Redirect detected after More click, aborting"),null;let u=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]');if(u||(u=await e.$('.artdeco-dropdown__item[aria-label*="connect"]')),u||(u=await e.$('.artdeco-dropdown__item[aria-label="Connect"]')),u||(u=await e.$('div[role="button"][aria-label*="Invite"]')),u||(u=await e.$('div[role="button"][aria-label*="connect"]')),!u){let c=await e.evaluateHandle(()=>{let f=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content');for(let d of f){let m=d.querySelector('a[href*="custom-invite"]');if(m)return m;for(let y of d.querySelectorAll('a, div[role="menuitem"], div[role="button"]'))if(y.innerText?.trim()==="Connect")return y}return null});u=c?.asElement?.()||null,u||await c?.dispose?.().catch(()=>{})}if(!u){let c=await e.evaluate(()=>{let f=document.querySelectorAll('[role="menu"], [popover], .artdeco-dropdown__content'),d=[];for(let m of f)for(let y of m.querySelectorAll('[role="menuitem"], a, div')){let p=y.innerText?.trim();p&&p.length<40&&d.push(p)}return[...new Set(d)].slice(0,10)});console.log(` More dropdown items: ${JSON.stringify(c)}`)}if(u)return console.log(" Found: More dropdown"),{button:u,method:"more_dropdown"};await e.keyboard.press("Escape")}catch(r){console.log(" More dropdown click failed:",r.message),await e.keyboard.press("Escape")}if(t=await e.$('button[aria-label*="Invite"]'),t&&n){let r=await e.evaluate(c=>(c.getAttribute("aria-label")||"").toLowerCase(),t),u=n.split(" ")[0].toLowerCase();r.includes("invite")&&!r.includes(u)&&(console.log(` Skipping generic button: wrong person (${r})`),t=null)}return t||(t=await e.$('button[aria-label="Connect"]')),t?(console.log(" Found: generic button"),{button:t,method:"generic_button"}):null}async function Qt(e,t){await e.evaluate(c=>c.scrollIntoView({behavior:"smooth",block:"center"}),t),await $(500);let n=await e.evaluate(c=>({tag:c.tagName,ariaLabel:c.getAttribute("aria-label"),href:c.getAttribute("href")}),t),s=n.tag==="A"&&n.href&&n.href.includes("custom-invite"),i=n.tag==="DIV",a=(n.ariaLabel||"").toLowerCase();if(a.includes("invite")){let c=await e.evaluate(()=>((document.querySelector("main h1")||document.querySelector("h1")||document.querySelector("main h2"))?.textContent?.trim()||"").split(" ")[0].toLowerCase());if(c&&!a.includes(c))return console.log(` \u2717 Identity guard: control is for someone else ("${n.ariaLabel}") \u2014 refusing to click (target: ${c})`),"wrong_target"}if(s){console.log(" Clicking custom-invite link (will navigate)..."),await Promise.all([e.waitForNavigation({waitUntil:"domcontentloaded",timeout:3e4}).catch(()=>{}),e.evaluate(f=>f.click(),t)]),await $(2e3);let c=e.url();if(c.includes("premium")||c.includes("redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium page - connection limit reached?"),await e.goBack(),await $(2e3),"premium_redirect"}else i?(await e.evaluate(c=>c.click(),t),await $(3e3)):(await e.evaluate(c=>c.click(),t),await $(3e3));let l=e.url();if(l.includes("/premium/")||l.includes("/redeem"))return console.log(" \u26A0 LinkedIn redirected to Premium upsell page"),"premium_redirect";let r=await e.evaluate(()=>!!document.querySelector('[role="dialog"], .artdeco-modal, .send-invite')),u=e.url();return console.log(r?` \u2713 Connect sent \u2014 ${u}`:` \u26A0 No modal after connect click \u2014 ${u}`),"success"}async function Nr(e){console.log(" Upsell: Premium required for notes");let t=await e.$('button[aria-label="Dismiss"]')||await e.$("button.artdeco-modal__dismiss");t?await t.click():await e.keyboard.press("Escape"),await $(1500);let n=await rt(e);if(n){await e.evaluate(s=>s.click(),n),await $(2e3);let o=await e.$('button[aria-label="Send without a note"]');if(o){try{await o.evaluate(s=>s.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (without note)"),!0}}return!1}async function Xt(e,t,n={}){let{source:o="unknown",skipQuotaGate:s=!1,skipQuotaRecord:i=!1}=n;if(!s){let l=Et();if(!l.allowed)return console.log(` \u26A0 Connection quota reached \u2014 not sending: ${l.reason}`),{success:!1,reason:"quota_exhausted",connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:l.reason,profileInfo:null}}let a=await jr(e,t,n);return a.connectionSent&&!i&&_n(t,o),a}async function jr(e,t,n={}){let{message:o=null,useCustomMessage:s=!0,skipIfPending:i=!0,skipIfConnected:a=!0,excludeLocations:l=[]}=n,r={success:!1,reason:null,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null};try{let u=t.split("/in/")[1]?.replace("/","")||"unknown";if(console.log(`
239
- --- Connecting: ${u} ---`),l.length>0){let w=J()[t]?.location;if(ht(w,l))return console.log(` \u26A0 Excluded location (stored): ${w}`),r.reason="excluded_location",r.profileInfo={location:w},r}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(5e3),await he(e)&&(console.log(" Dismissed Premium overlay"),await $(2e3),await mo(e,t),await $(2e3)),r.profileInfo=await e.evaluate(()=>{let w=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),b=j=>{let F=(j||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(F)},g={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},h=document.querySelector("main");if(!h)return g;let k=[...Array.from(h.querySelectorAll("h1")),...Array.from(h.querySelectorAll("h2"))],C=Array.from(h.querySelectorAll("h2")),_=k.find(j=>{let F=j.textContent&&j.textContent.trim();return F&&F.length>1&&F.length<100&&!w.has(F)&&F!=="0 notifications"}),I=_?_.textContent.trim():null,T=_?_.parentElement:null;for(;T&&T!==h&&!Array.from(T.children).filter(P=>P.tagName==="P").some(P=>{let H=P.textContent&&P.textContent.trim();return H&&H.length>5&&!b(H)});)T=T.parentElement;let L=null,G=null,v=null;if(T&&T!==h){let j=Array.from(T.children),F=j.filter(H=>H.tagName==="P").filter(H=>{let oe=H.textContent&&H.textContent.trim();return oe&&oe.length>5&&!b(oe)});F[0]&&(L=F[0].textContent.trim()),F[1]&&(G=F[1].textContent.trim());let P=j.filter(H=>H.tagName==="DIV");for(let H=P.length-1;H>=0;H--){let oe=P[H].textContent&&P[H].textContent.trim();if(oe&&!(I&&oe.startsWith(I))&&(v=oe.split(/[·•]/)[0].trim(),v))break}}let x=null;if(T){let j=T.querySelectorAll("p, span, div");for(let F of j){let P=(F.textContent||"").trim().replace(/^[·•]\s*/,"");if(P==="1st"||P==="2nd"||P==="3rd"){x=P;break}}}let A=null,M=C.find(j=>j.textContent&&j.textContent.trim()==="About");if(M){let j=M.parentElement;for(;j&&j.tagName!=="SECTION";)j=j.parentElement;j&&(A=(j.textContent||"").trim().replace(/^About\s*/,"").trim()||null,A&&(A=A.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let q=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),re=q&&q.src||null,ie=!!h.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:I,title:L,location:v,about:A,company:G,connectionDegree:x,connectionsCount:null,mutualConnections:null,photoUrl:re,hasVerifiedBadge:ie}}),l.length>0){let w=r.profileInfo?.location,b=J()[t]?.location,g=w||b;if(ht(g,l))return console.log(` \u26A0 Excluded location (${w?"live":"stored"}): ${g}`),r.reason="excluded_location",r;!w&&b==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let f=await xe(e);if(f==="pending"&&i)return console.log(" \u26A0 Already pending - skipping"),r.reason="pending",r;if(f==="connected"&&a)return console.log(" \u26A0 Already connected - skipping"),r.reason="connected",r;await he(e);let d=await rt(e);if(!d&&(await he(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await $(2e3),d=await rt(e)),!d))return console.log(" \u2717 Connect not found"),r.reason="button_not_found",r;r.method=d.method;let m=await Qt(e,d.button);if(m==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),r.reason="wrong_target",r;if(m==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(4e3);let w=await xe(e);if(w==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;console.log(` Status after upsell: ${w} \u2014 trying More dropdown...`),await he(e),await $(1e3);let b=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if(b)try{await e.evaluate(h=>h.scrollIntoView({behavior:"smooth",block:"center"}),b),await $(500),await b.click().catch(()=>e.evaluate(h=>h.click(),b)),await $(2e3);let g=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(g){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(C=>C.click(),g),await $(3e3);let h=e.url();if(h.includes("/premium/")||h.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),r.reason="premium_required",r;if(await xe(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.method="more_dropdown",r.withCustomMessage=!1,r;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await $(500),r.reason="premium_required",r}catch(g){return console.log(" More dropdown failed:",g.message),await e.keyboard.press("Escape").catch(()=>{}),r.reason="premium_required",r}else return console.log(" \u2717 No More button found \u2014 Premium required"),r.reason="premium_required",r}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let w=await e.$('button[aria-label="Dismiss"]');return w&&await w.click(),await $(500),r.reason="email_required",r}let p=await e.$('button[aria-label="Add a note"]'),S=await e.$('button[aria-label="Send without a note"]');if(!p&&!S){let w=await e.evaluate(()=>{let b=document.querySelector("#interop-outlet")?.shadowRoot;if(!b)return{addNote:!1,sendWithout:!1};let g=b.querySelector('button[aria-label="Add a note"]'),h=b.querySelector('button[aria-label="Send without a note"]');return{addNote:!!g,sendWithout:!!h}});if(w.addNote){let b=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));p=b?.asElement?.()||null,p||await b.dispose().catch(()=>{})}if(w.sendWithout){let b=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));S=b?.asElement?.()||null,S||await b.dispose().catch(()=>{})}}if(s){if(p&&o){if(console.log(" Adding personalized note..."),await p.click(),await $(1500),await e.$("div.modal-upsell")){let g=await Nr(e);return r.success=g,r.connectionSent=g,r.reason=g?"sent_without_note_upsell":"upsell_failed",r.withCustomMessage=!1,r}let b=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if(b){let g=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),h=o.replace("{name}",g);await b.type(h,{delay:20}),await $(500);let k=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if(k){try{await k.evaluate(C=>C.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (with note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_with_note",r.withCustomMessage=!0,r.messageSent=h,r}}}else if(S){console.log(" Sending without note...");try{await S.evaluate(w=>w.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}else if(p&&!o){console.log(" No message provided, sending without note...");let w=await e.$('button[aria-label="Send without a note"]');if(w){try{await w.evaluate(b=>b.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}}else{console.log(" Sending without note (custom messages disabled)...");let w=S;if(w){try{await w.evaluate(b=>b.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}if(d.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(4e3)),await he(e),await $(500);let b=await e.$$('button[id*="profile-overflow-action"]'),g=null;for(let h of b){let k=await e.evaluate(C=>{let _=C.getBoundingClientRect();return{visible:_.width>0&&_.height>0,inSticky:!!C.closest('.sticky-header, [class*="sticky"]')}},h);if(k.visible&&!k.inSticky){g=h;break}}!g&&b.length>0&&(g=b[b.length-1]);for(let h of b)h!==g&&await h.dispose().catch(()=>{});if(g)try{await e.evaluate(k=>k.scrollIntoView({behavior:"smooth",block:"center"}),g),await $(500),await g.click().catch(()=>e.evaluate(k=>k.click(),g)),await $(2e3);let h=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(h){console.log(" Found Connect in More dropdown, clicking..."),r.method="more_dropdown",await e.evaluate(I=>I.click(),h),await $(3e3);let k=e.url();if(k.includes("/premium/")||k.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),await xe(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r):(r.reason="premium_required",r);if(await xe(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;let _=await e.$('button[aria-label="Send without a note"]');if(_){console.log(" Modal appeared via More dropdown, sending without note...");try{await _.evaluate(I=>I.click())}catch{}return await $(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(h){console.log(" More dropdown fallback failed:",h.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),r.reason="modal_failed",r}catch(u){console.error(` \u2717 Error: ${u.message}`),r.reason="error",r.error=u.message;let c=u.message.toLowerCase();if(c.includes("detached")||c.includes("session closed")||c.includes("target closed")||c.includes("browser has disconnected")||c.includes("protocol error"))return r.fatal=!0,r;try{await e.goto("about:blank",{timeout:1e4}),await $(1e3)}catch{r.fatal=!0}return r}}async function po(e,t,n={}){let{message:o=null,useCustomMessage:s=!0,maxConnections:i=20,viewOnly:a=!1,delayBetweenProfiles:l=3e3,onProfileProcessed:r=null,excludeLocations:u=[],source:c="unknown"}=n,f={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
239
+ --- Connecting: ${u} ---`),l.length>0){let w=J()[t]?.location;if(ht(w,l))return console.log(` \u26A0 Excluded location (stored): ${w}`),r.reason="excluded_location",r.profileInfo={location:w},r}if(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(5e3),await he(e)&&(console.log(" Dismissed Premium overlay"),await $(2e3),await mo(e,t),await $(2e3)),r.profileInfo=await e.evaluate(()=>{let w=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Courses","Test scores","Organizations","More profiles for you","Explore Premium profiles","Suggested for you","Promoted","Ad Options","Don\u2019t want to see this"]),b=j=>{let F=(j||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(F)},g={name:null,title:null,location:null,about:null,company:null,connectionDegree:null,connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1},h=document.querySelector("main");if(!h)return g;let k=[...Array.from(h.querySelectorAll("h1")),...Array.from(h.querySelectorAll("h2"))],C=Array.from(h.querySelectorAll("h2")),_=k.find(j=>{let F=j.textContent&&j.textContent.trim();return F&&F.length>1&&F.length<100&&!w.has(F)&&F!=="0 notifications"}),I=_?_.textContent.trim():null,T=_?_.parentElement:null;for(;T&&T!==h&&!Array.from(T.children).filter(P=>P.tagName==="P").some(P=>{let H=P.textContent&&P.textContent.trim();return H&&H.length>5&&!b(H)});)T=T.parentElement;let L=null,G=null,v=null;if(T&&T!==h){let j=Array.from(T.children),F=j.filter(H=>H.tagName==="P").filter(H=>{let oe=H.textContent&&H.textContent.trim();return oe&&oe.length>5&&!b(oe)});F[0]&&(L=F[0].textContent.trim()),F[1]&&(G=F[1].textContent.trim());let P=j.filter(H=>H.tagName==="DIV");for(let H=P.length-1;H>=0;H--){let oe=P[H].textContent&&P[H].textContent.trim();if(oe&&!(I&&oe.startsWith(I))&&(v=oe.split(/[·•]/)[0].trim(),v))break}}let x=null;if(T){let j=T.querySelectorAll("p, span, div");for(let F of j){let P=(F.textContent||"").trim().replace(/^[·•]\s*/,"");if(P==="1st"||P==="2nd"||P==="3rd"){x=P;break}}}let A=null,M=C.find(j=>j.textContent&&j.textContent.trim()==="About");if(M){let j=M.parentElement;for(;j&&j.tagName!=="SECTION";)j=j.parentElement;j&&(A=(j.textContent||"").trim().replace(/^About\s*/,"").trim()||null,A&&(A=A.replace(/(?:…|\.\.\.)?\s*(?:see (?:more|less)|show (?:more|less))\s*$/i,"").trim()||null))}let q=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),re=q&&q.src||null,ie=!!h.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]');return{name:I,title:L,location:v,about:A,company:G,connectionDegree:x,connectionsCount:null,mutualConnections:null,photoUrl:re,hasVerifiedBadge:ie}}),l.length>0){let w=r.profileInfo?.location,b=J()[t]?.location,g=w||b;if(ht(g,l))return console.log(` \u26A0 Excluded location (${w?"live":"stored"}): ${g}`),r.reason="excluded_location",r;!w&&b==null&&console.log(" \u26A0 Location unknown (live scrape null, no stored value) \u2014 proceeding")}let f=await xe(e);if(r.profileInfo?.connectionDegree==="1st"&&f!=="pending"&&(f!=="connected"&&console.log(" (degree badge = 1st \u2192 already connected)"),f="connected"),f==="pending"&&i)return console.log(" \u26A0 Already pending - skipping"),r.reason="pending",r;if(f==="connected"&&a)return console.log(" \u26A0 Already connected - skipping"),r.reason="connected",r;await he(e);let d=await rt(e);if(!d&&(await he(e)&&(console.log(" Dismissed overlay, retrying connect button search..."),await $(2e3),d=await rt(e)),!d))return console.log(" \u2717 Connect not found"),r.reason="button_not_found",r;r.method=d.method;let m=await Qt(e,d.button);if(m==="wrong_target")return console.log(" \u2717 Not sent \u2014 connect control did not belong to this profile"),r.reason="wrong_target",r;if(m==="premium_redirect"){console.log(" \u26A0 Premium upsell redirect \u2014 navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(4e3);let w=await xe(e);if(w==="pending")return console.log(" \u2713 Connection was sent (detected Pending after upsell redirect)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;console.log(` Status after upsell: ${w} \u2014 trying More dropdown...`),await he(e),await $(1e3);let b=await e.$('button[id*="profile-overflow-action"]:not([class*="sticky"])');if(b)try{await e.evaluate(h=>h.scrollIntoView({behavior:"smooth",block:"center"}),b),await $(500),await b.click().catch(()=>e.evaluate(h=>h.click(),b)),await $(2e3);let g=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(g){console.log(" Found Connect in More dropdown, clicking..."),await e.evaluate(C=>C.click(),g),await $(3e3);let h=e.url();if(h.includes("/premium/")||h.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),r.reason="premium_required",r;if(await xe(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.method="more_dropdown",r.withCustomMessage=!1,r;console.log(" More dropdown clicked, checking for modal...")}else return console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape"),await $(500),r.reason="premium_required",r}catch(g){return console.log(" More dropdown failed:",g.message),await e.keyboard.press("Escape").catch(()=>{}),r.reason="premium_required",r}else return console.log(" \u2717 No More button found \u2014 Premium required"),r.reason="premium_required",r}if(await e.$('input[name="email"][type="email"]')){console.log(" \u26A0 Email verification required - skipping");let w=await e.$('button[aria-label="Dismiss"]');return w&&await w.click(),await $(500),r.reason="email_required",r}let p=await e.$('button[aria-label="Add a note"]'),S=await e.$('button[aria-label="Send without a note"]');if(!p&&!S){let w=await e.evaluate(()=>{let b=document.querySelector("#interop-outlet")?.shadowRoot;if(!b)return{addNote:!1,sendWithout:!1};let g=b.querySelector('button[aria-label="Add a note"]'),h=b.querySelector('button[aria-label="Send without a note"]');return{addNote:!!g,sendWithout:!!h}});if(w.addNote){let b=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Add a note"]'));p=b?.asElement?.()||null,p||await b.dispose().catch(()=>{})}if(w.sendWithout){let b=await e.evaluateHandle(()=>document.querySelector("#interop-outlet")?.shadowRoot?.querySelector('button[aria-label="Send without a note"]'));S=b?.asElement?.()||null,S||await b.dispose().catch(()=>{})}}if(s){if(p&&o){if(console.log(" Adding personalized note..."),await p.click(),await $(1500),await e.$("div.modal-upsell")){let g=await Nr(e);return r.success=g,r.connectionSent=g,r.reason=g?"sent_without_note_upsell":"upsell_failed",r.withCustomMessage=!1,r}let b=await e.$('textarea[name="message"]')||await e.$("textarea#custom-message")||await e.$("textarea");if(b){let g=await e.evaluate(()=>document.querySelector("h1")?.textContent?.trim()?.split(" ")[0]||""),h=o.replace("{name}",g);await b.type(h,{delay:20}),await $(500);let k=await e.$('button[aria-label="Send invitation"]')||await e.$('button[aria-label="Send now"]');if(k){try{await k.evaluate(C=>C.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (with note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_with_note",r.withCustomMessage=!0,r.messageSent=h,r}}}else if(S){console.log(" Sending without note...");try{await S.evaluate(w=>w.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}else if(p&&!o){console.log(" No message provided, sending without note...");let w=await e.$('button[aria-label="Send without a note"]');if(w){try{await w.evaluate(b=>b.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}}else{console.log(" Sending without note (custom messages disabled)...");let w=S;if(w){try{await w.evaluate(b=>b.click())}catch{console.log(" Click timeout, likely still sent")}return await $(3e3),console.log(" \u2713 Connection sent (without note)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}}if(d.method!=="more_dropdown"){console.log(" \u26A0 No modal after click \u2014 trying More dropdown fallback..."),e.url().includes("/in/")||(await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(4e3)),await he(e),await $(500);let b=await e.$$('button[id*="profile-overflow-action"]'),g=null;for(let h of b){let k=await e.evaluate(C=>{let _=C.getBoundingClientRect();return{visible:_.width>0&&_.height>0,inSticky:!!C.closest('.sticky-header, [class*="sticky"]')}},h);if(k.visible&&!k.inSticky){g=h;break}}!g&&b.length>0&&(g=b[b.length-1]);for(let h of b)h!==g&&await h.dispose().catch(()=>{});if(g)try{await e.evaluate(k=>k.scrollIntoView({behavior:"smooth",block:"center"}),g),await $(500),await g.click().catch(()=>e.evaluate(k=>k.click(),g)),await $(2e3);let h=await e.$('.artdeco-dropdown__item[aria-label*="Invite"]')||await e.$('.artdeco-dropdown__item[aria-label*="connect"]')||await e.$('.artdeco-dropdown__item[aria-label="Connect"]')||await e.$('div[role="button"][aria-label*="Invite"]')||await e.$('div[role="button"][aria-label*="connect"]');if(h){console.log(" Found Connect in More dropdown, clicking..."),r.method="more_dropdown",await e.evaluate(I=>I.click(),h),await $(3e3);let k=e.url();if(k.includes("/premium/")||k.includes("/redeem"))return console.log(" \u2717 More dropdown also redirected to Premium"),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),await xe(e)==="pending"?(console.log(" \u2713 Connection was sent (detected Pending)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r):(r.reason="premium_required",r);if(await xe(e)==="pending")return console.log(" \u2713 Connection sent via More dropdown"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r;let _=await e.$('button[aria-label="Send without a note"]');if(_){console.log(" Modal appeared via More dropdown, sending without note...");try{await _.evaluate(I=>I.click())}catch{}return await $(3e3),console.log(" \u2713 Connection sent (without note, via More dropdown)"),r.success=!0,r.connectionSent=!0,r.reason="sent_without_note",r.withCustomMessage=!1,r}console.log(" More dropdown: no modal either")}else console.log(" No Connect option in More dropdown"),await e.keyboard.press("Escape")}catch(h){console.log(" More dropdown fallback failed:",h.message),await e.keyboard.press("Escape").catch(()=>{})}}return console.log(" \u2717 Could not complete connection request"),r.reason="modal_failed",r}catch(u){console.error(` \u2717 Error: ${u.message}`),r.reason="error",r.error=u.message;let c=u.message.toLowerCase();if(c.includes("detached")||c.includes("session closed")||c.includes("target closed")||c.includes("browser has disconnected")||c.includes("protocol error"))return r.fatal=!0,r;try{await e.goto("about:blank",{timeout:1e4}),await $(1e3)}catch{r.fatal=!0}return r}}async function po(e,t,n={}){let{message:o=null,useCustomMessage:s=!0,maxConnections:i=20,viewOnly:a=!1,delayBetweenProfiles:l=3e3,onProfileProcessed:r=null,excludeLocations:u=[],source:c="unknown"}=n,f={viewed:0,connectionsSent:0,skipped:{pending:0,connected:0,email:0,notFound:0,excludedLocation:0},errors:0};if(console.log(`
240
240
  === Running Funnel: ${t.length} profiles ===`),console.log(`Mode: ${a?"View Only":`Connect (max ${i})`}`),a||console.log(`Custom messages: ${s?"Enabled":"Disabled (saving quota)"}`),u.length>0&&console.log(`Excluding locations: ${u.join(", ")}`),!a){let m=ze();console.log(`Quota: today ${m.daily.sent}/${m.daily.max} | week ${m.weekly.sent}/${m.weekly.max}`)}console.log("");let d=0;for(let m=0;m<t.length;m++){let y=t[m];try{if(e.isClosed()){console.log(`
241
241
  \u26A0 Browser page is closed \u2014 aborting funnel`);break}}catch{console.log(`
242
242
  \u26A0 Browser disconnected \u2014 aborting funnel`);break}if(!y.profileUrl){console.log(`[${m+1}/${t.length}] Skipping - no URL`);continue}let p=Cn(y.profileUrl);if(p==="pending"||p==="connected"||p==="sent_with_note"||p==="sent_without_note"||p==="sent_without_note_upsell"){console.log(`[${m+1}/${t.length}] ${y.name||y.profileUrl} \u2014 skipped (db: ${p})`),p==="pending"||p==="sent_with_note"||p==="sent_without_note"||p==="sent_without_note_upsell"?f.skipped.pending++:f.skipped.connected++,r&&await r(y,f,{success:!1,reason:p,connectionSent:!1,withCustomMessage:!1,messageSent:null,method:null,error:null,profileInfo:null});continue}console.log(`[${m+1}/${t.length}] ${y.name||y.profileUrl}`);let S=null;if(a){let w=await Kt(e,y.profileUrl);w?(be(y.profileUrl,{...w,source:c}),f.viewed++,S={success:!0,reason:"viewed",connectionSent:!1,profileInfo:w}):(f.errors++,S={success:!1,reason:"view_failed",connectionSent:!1,profileInfo:null})}else{if(f.connectionsSent>=i){console.log(` Max connections per session (${i}) reached`);break}let w=Et();if(!w.allowed){console.log(` \u26A0 Global quota exhausted: ${w.reason}`);break}if(S=await Xt(e,y.profileUrl,{message:o,useCustomMessage:s,excludeLocations:u,source:c,skipQuotaGate:!0}),S.success)f.connectionsSent++;else switch(S.reason){case"pending":f.skipped.pending++;break;case"connected":f.skipped.connected++;break;case"email_required":f.skipped.email++;break;case"button_not_found":f.skipped.notFound++;break;case"excluded_location":f.skipped.excludedLocation++;break;default:f.errors++}}if(S?.fatal){console.log(`
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.14.4";try{let n=new URL("./ilml-plugin.json",import.meta.url);return JSON.parse(e(r(n),"utf-8")).version}catch{return"unknown"}}console.log(`ilml-plugin-linkedin ${i()}`);
1
+ import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.14.5";try{let n=new URL("./ilml-plugin.json",import.meta.url);return JSON.parse(e(r(n),"utf-8")).version}catch{return"unknown"}}console.log(`ilml-plugin-linkedin ${i()}`);
package/ilml-plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkedin",
3
- "version": "1.14.4",
3
+ "version": "1.14.5",
4
4
  "description": "Reference ilml plugin: keep a local mirror of your LinkedIn data with AI-assisted workflows",
5
5
  "commands": {
6
6
  "help": { "run": "node dist/help.mjs", "description": "List all commands with descriptions; or `help <cmd>` for detailed info on one command (usage, flags, ban-risk, when-to-use). Reads ilml-plugin.json directly.", "usage": "ilml linkedin help [<cmd>]", "useWhen": "You forgot what a command does, or you're an AI agent picking the right tool." },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilml-plugin-linkedin",
3
- "version": "1.14.4",
3
+ "version": "1.14.5",
4
4
  "description": "Reference ilml plugin: keep a local mirror of your LinkedIn data and run AI-assisted workflows under your direction.",
5
5
  "type": "module",
6
6
  "files": [