Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix(linkedin): bind redirects to contact dialog
16Mikuc9749aaffcd5
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 55547dfab..0701840d4 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -5165,7 +5165,7 @@&& railRect.right <= composerRect.left + 64;};- const classifyLinkedInNavigation = (clicked) => {+ const classifyLinkedInNavigation = (clicked, blockingModal = null) => {if (params.adapterName !== 'linkedin' || !clicked) return 'none';const link = _composedClosestElement(clicked, 'a[href]');if (!link || !visible(link)) return 'none';@@ -5176,7 +5176,9 @@|| _composedClosestElement(link, 'form')|| link.hasAttribute?.('download')|| (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return 'blocked';- const modal = _composedClosestElement(link, 'dialog,[role="dialog"],[role="alertdialog"]') || _findTopmostBlockingModal();+ const modal = blockingModal && _isComposedAncestor(blockingModal, link)+ ? blockingModal+ : _composedClosestElement(link, 'dialog,[role="dialog"],[role="alertdialog"]');const unresolved = () => modal ? 'blocked' : 'none';try {const href = String(link.getAttribute('href') || '').trim();@@ -5199,8 +5201,19 @@} catch {}}if (modal) {- const contactInfoOverlay = /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(location.pathname);- if (!contactInfoOverlay || !verifiedExternalRedirect) return 'blocked';+ const contactInfoOverlay = /^\/in\/([^/]+)\/overlay\/contact-info\/?$/.exec(location.pathname);+ const profilePath = contactInfoOverlay ? `/in/${contactInfoOverlay[1]}` : '';+ const ownsContactInfoRoute = !!profilePath && Array.from(modal.querySelectorAll?.('a[href]') || [])+ .some((candidate) => {+ try {+ const candidateUrl = new URL(candidate.getAttribute('href'), document.baseURI);+ return isLinkedInHost(candidateUrl.hostname)+ && candidateUrl.pathname.replace(/\/+$/, '') === profilePath;+ } catch {+ return false;+ }+ });+ if (!ownsContactInfoRoute || !verifiedExternalRedirect) return 'blocked';}if (!linkedInDestination) return 'navigation';return (verifiedExternalRedirect@@ -5253,7 +5266,7 @@if (!visible(control) || (modal && !_isComposedAncestor(modal, target))) {return { success: true, messageSend: null, conclusive: false, identityCandidates: [] };}- const linkedInNavigation = classifyLinkedInNavigation(target);+ const linkedInNavigation = classifyLinkedInNavigation(target, modal);if (linkedInNavigation === 'navigation') {return { success: true, messageSend: false, conclusive: true, navigation: true, identityCandidates: [] };}diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex b21e741a6..6e2f10ce9 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -4328,7 +4328,7 @@&& railRect.right <= composerRect.left + 64;};- const classifyLinkedInNavigation = (clicked) => {+ const classifyLinkedInNavigation = (clicked, blockingModal = null) => {if (params.adapterName !== 'linkedin' || !clicked) return 'none';const link = _composedClosestElement(clicked, 'a[href]');if (!link || !visible(link)) return 'none';@@ -4339,7 +4339,9 @@|| _composedClosestElement(link, 'form')|| link.hasAttribute?.('download')|| (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return 'blocked';- const modal = _composedClosestElement(link, 'dialog,[role="dialog"],[role="alertdialog"]');+ const modal = blockingModal && _isComposedAncestor(blockingModal, link)+ ? blockingModal+ : _composedClosestElement(link, 'dialog,[role="dialog"],[role="alertdialog"]');const unresolved = () => modal ? 'blocked' : 'none';try {const href = String(link.getAttribute('href') || '').trim();@@ -4362,8 +4364,19 @@} catch {}}if (modal) {- const contactInfoOverlay = /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(location.pathname);- if (!contactInfoOverlay || !verifiedExternalRedirect) return 'blocked';+ const contactInfoOverlay = /^\/in\/([^/]+)\/overlay\/contact-info\/?$/.exec(location.pathname);+ const profilePath = contactInfoOverlay ? `/in/${contactInfoOverlay[1]}` : '';+ const ownsContactInfoRoute = !!profilePath && Array.from(modal.querySelectorAll?.('a[href]') || [])+ .some((candidate) => {+ try {+ const candidateUrl = new URL(candidate.getAttribute('href'), document.baseURI);+ return isLinkedInHost(candidateUrl.hostname)+ && candidateUrl.pathname.replace(/\/+$/, '') === profilePath;+ } catch {+ return false;+ }+ });+ if (!ownsContactInfoRoute || !verifiedExternalRedirect) return 'blocked';}if (!linkedInDestination) return 'navigation';return (verifiedExternalRedirect@@ -4416,7 +4429,7 @@if (!visible(control) || (modal && !_isComposedAncestor(modal, target))) {return { success: true, messageSend: null, conclusive: false, identityCandidates: [] };}- const linkedInNavigation = classifyLinkedInNavigation(target);+ const linkedInNavigation = classifyLinkedInNavigation(target, modal);if (linkedInNavigation === 'navigation') {return { success: true, messageSend: false, conclusive: true, navigation: true, identityCandidates: [] };}diff --git a/test/fixtures/message-recipient-navigation.mjs b/test/fixtures/message-recipient-navigation.mjsindex d5e36c0ba..bba4bc678 100644--- a/test/fixtures/message-recipient-navigation.mjs+++ b/test/fixtures/message-recipient-navigation.mjs@@ -31,6 +31,7 @@ export function registerMessageRecipientNavigationFixtures({</main><div id="contact-info-dialog" role="dialog" aria-modal="true" hidden><button id="close-contact-info" type="button">Close</button>+ <a id="contact-profile" href="/in/alice/">linkedin.com/in/alice</a><a id="safety-portfolio" href="/safety/go/?url=https%3A%2F%2Fportfolio.example%2F">portfolio.example</a><a id="legacy-portfolio" href="/redir/redirect?url=https%3A%2F%2Flegacy-portfolio.example%2F">legacy-portfolio.example</a></div>@@ -184,6 +185,7 @@ export function registerMessageRecipientNavigationFixtures({register(`${kind}: LinkedIn safety redirects cannot escape a shadow-root modal`, async (page) => {const { guard, probe } = await setup(page);const ref_id = await page.evaluate(() => {+ history.replaceState(null, '', '/in/alice/overlay/contact-info/');document.querySelector('#chat').hidden = false;const modal = document.createElement('div');modal.setAttribute('role', 'dialog');@@ -203,6 +205,24 @@ export function registerMessageRecipientNavigationFixtures({assert.equal((await guard('click_ax', args))?.noDispatch, true);});+ register(`${kind}: LinkedIn safety redirects cannot escape a heuristic modal`, async (page) => {+ const { guard, probe } = await setup(page);+ await page.evaluate(() => {+ history.replaceState(null, '', '/in/alice/overlay/contact-info/');+ document.querySelector('#chat').hidden = false;+ const modal = document.createElement('div');+ modal.className = 'modal show';+ modal.style.cssText = 'position:fixed;inset:0;background:white';+ modal.innerHTML = '<a id="heuristic-modal-link" href="/safety/go/?url=https%3A%2F%2Fportfolio.example%2F" style="display:inline-block;padding:8px">Heuristic modal link</a>';+ document.body.append(modal);+ });+ const args = { selector: '#heuristic-modal-link' };+ const result = await probe('click', args);+ assert.equal(result.navigationBlocked, true, JSON.stringify(result));+ assert.equal(result.conclusive, false, JSON.stringify(result));+ assert.equal((await guard('click', args))?.noDispatch, true);+ });+register(`${kind}: LinkedIn recipient guard rejects ambiguous navigation and action lookalikes`, async (page) => {const { guard } = await setup(page);for (const href of [