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
LinkedIn: recognize the server-driven share composer's Post button
Barack Sokullu88611ee62192
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 824fbd5d3..8b71a5b70 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -28681,9 +28681,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst publishWorkflowAuthorized = guard?.siteWorkflow?.adapterName === 'linkedin'&& guard?.siteWorkflow?.job?.id === 'publish-post';// A public Post control is not a message send, but it is still a- // consequential action. Only the explicit LinkedIn publish workflow can- // bypass recipient dispatch binding for that control.- if (!linkedInPublicPost || publishWorkflowAuthorized) return null;+ // consequential action. The explicit LinkedIn publish workflow+ // authorizes it, and so does a plan that requires a submission without+ // naming a private message to send: a task that started on another+ // site has no LinkedIn workflow yet. The normal submission gates still+ // apply to the post.+ const planAuthorizesPublication = !!guard && guard.requiresSubmission === true+ && guard.requiresStateChange === true && !target;+ if (!linkedInPublicPost || publishWorkflowAuthorized || planAuthorizesPublication) return null;return {success: false,blocked: true,@@ -28691,7 +28696,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout ddispatched: false,messageRecipientGuard: true,reasonCode: 'public_post_not_authorized',- error: 'LinkedIn Post blocked because this task authorizes a private message, not a public post.',+ error: target+ ? 'LinkedIn Post blocked because this task authorizes a private message, not a public post.'+ : 'LinkedIn Post blocked because this task does not ask to publish anything, so nothing was posted. Do not post; report what is ready instead.',};}// Gmail reply editors can be collapsed when planning begins. Allow only adiff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 5c7faca01..a26cece22 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -7757,6 +7757,24 @@} catch { return false; }};+ // LinkedIn's current share composer is server-driven UI: its controls+ // carry only generated class names and no data-control-name, but the+ // screen itself is marked (data-sdui-screen ending in+ // ".sharing.ShareCompose") whatever the page's language. Nothing in+ // that screen sends a private message. It counts only with one editor+ // of its own and outside every messaging scope.+ const linkedInShareComposeScreen = (clicked) => {+ if (params.adapterName !== 'linkedin') return null;+ const screen = _composedClosestElement(clicked, '[data-sdui-screen$=".sharing.ShareCompose"]');+ if (!screen || !visible(screen)) return null;+ const messageScope = 'form,[role="log"],[data-message-id],[data-thread-id],[data-conversation-id],'+ + '.msg-form,.msg-overlay-conversation-bubble,.msg-convo-wrapper';+ if (_composedClosestElement(clicked, messageScope) || _composedClosestElement(screen, messageScope)+ || _inMessagingSurface(clicked) || _inMessagingSurface(screen)) return null;+ const editors = Array.from(screen.querySelectorAll('[contenteditable="true"],textarea')).filter(visible);+ return editors.length === 1 ? screen : null;+ };+const verifiedLinkedInPublicPostControl = (clicked) => {if (params.adapterName !== 'linkedin') return false;const button = _composedClosestElement(clicked, 'button,[role="button"]');@@ -8127,6 +8145,29 @@// a private-message recipient is irrelevant to this composer.return { success: true, messageSend: false, conclusive: true, publicPost: true, identityCandidates: [] };}+ if (linkedInShareComposeScreen(target)) {+ // In the share composer, a control whose name, read in any+ // language, says it publishes or sends ("Gönder" posts in Turkish)+ // is its post action: a public post, which still goes through the+ // normal submission gates. The editor and every other control+ // (author, audience, emoji, media, schedule) only work on the+ // draft. A name nobody has read yet is read first.+ if (editable(target) || editable(control)) {+ return { success: true, messageSend: false, conclusive: true, nonMessagingTarget: true,+ reasonCode: 'non_messaging_target', identityCandidates: [] };+ }+ const shareReading = _messageControlReading(compact(+ control.getAttribute?.('aria-label') || control.innerText || control.textContent, 120));+ if (shareReading === null) {+ return { success: true, messageSend: null, conclusive: false, composerAvailable: false,+ reasonCode: 'message_control_unread', identityCandidates: [] };+ }+ if (shareReading === 'publish' || shareReading === 'send') {+ return { success: true, messageSend: false, conclusive: true, publicPost: true, identityCandidates: [] };+ }+ return { success: true, messageSend: false, conclusive: true, nonMessagingTarget: true,+ reasonCode: 'non_messaging_target', identityCandidates: [] };+ }const linkedInNavigation = classifyLinkedInNavigation(target, modal);if (linkedInNavigation === 'navigation') {return { success: true, messageSend: false, conclusive: true, navigation: true, identityCandidates: [] };diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 0dd3f9fef..943438696 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -25806,9 +25806,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst publishWorkflowAuthorized = guard?.siteWorkflow?.adapterName === 'linkedin'&& guard?.siteWorkflow?.job?.id === 'publish-post';// A public Post control is not a message send, but it is still a- // consequential action. Only the explicit LinkedIn publish workflow can- // bypass recipient dispatch binding for that control.- if (!linkedInPublicPost || publishWorkflowAuthorized) return null;+ // consequential action. The explicit LinkedIn publish workflow+ // authorizes it, and so does a plan that requires a submission without+ // naming a private message to send: a task that started on another+ // site has no LinkedIn workflow yet. The normal submission gates still+ // apply to the post.+ const planAuthorizesPublication = !!guard && guard.requiresSubmission === true+ && guard.requiresStateChange === true && !target;+ if (!linkedInPublicPost || publishWorkflowAuthorized || planAuthorizesPublication) return null;return {success: false,blocked: true,@@ -25816,7 +25821,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout ddispatched: false,messageRecipientGuard: true,reasonCode: 'public_post_not_authorized',- error: 'LinkedIn Post blocked because this task authorizes a private message, not a public post.',+ error: target+ ? 'LinkedIn Post blocked because this task authorizes a private message, not a public post.'+ : 'LinkedIn Post blocked because this task does not ask to publish anything, so nothing was posted. Do not post; report what is ready instead.',};}// Gmail reply editors can be collapsed when planning begins. Allow only adiff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex f64a164dd..36ccd08d9 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -6938,6 +6938,31 @@} catch { return false; }};+ // LinkedIn's current share composer is server-driven UI: its controls+ // carry only generated class names and no data-control-name, but the+ // screen itself is marked (data-sdui-screen ending in+ // ".sharing.ShareCompose") whatever the page's language. Nothing in+ // that screen sends a private message. It counts only with one editor+ // of its own and outside every messaging scope.+ const linkedInShareComposeScreen = (clicked) => {+ if (params.adapterName !== 'linkedin') return null;+ const screen = _composedClosestElement(clicked, '[data-sdui-screen$=".sharing.ShareCompose"]');+ if (!screen || !visible(screen)) return null;+ const messageScope = 'form,[role="log"],[data-message-id],[data-thread-id],[data-conversation-id],'+ + '.msg-form,.msg-overlay-conversation-bubble,.msg-convo-wrapper';+ // The messaging apps' own containers, as the composer check below+ // reads them.+ const messagingSurface = (el) => {+ try {+ return !!el?.closest?.('[class*="msg-"],[class*="messaging"],[id*="messaging"],[data-messaging],[data-test-messaging],[role="log"]');+ } catch { return false; }+ };+ if (_composedClosestElement(clicked, messageScope) || _composedClosestElement(screen, messageScope)+ || messagingSurface(clicked) || messagingSurface(screen)) return null;+ const editors = Array.from(screen.querySelectorAll('[contenteditable="true"],textarea')).filter(visible);+ return editors.length === 1 ? screen : null;+ };+const verifiedLinkedInPublicPostControl = (clicked) => {if (params.adapterName !== 'linkedin') return false;const button = _composedClosestElement(clicked, 'button,[role="button"]');@@ -7301,6 +7326,29 @@// a private-message recipient is irrelevant to this composer.return { success: true, messageSend: false, conclusive: true, publicPost: true, identityCandidates: [] };}+ if (linkedInShareComposeScreen(target)) {+ // In the share composer, a control whose name, read in any+ // language, says it publishes or sends ("Gönder" posts in Turkish)+ // is its post action: a public post, which still goes through the+ // normal submission gates. The editor and every other control+ // (author, audience, emoji, media, schedule) only work on the+ // draft. A name nobody has read yet is read first.+ if (editable(target) || editable(control)) {+ return { success: true, messageSend: false, conclusive: true, nonMessagingTarget: true,+ reasonCode: 'non_messaging_target', identityCandidates: [] };+ }+ const shareReading = _messageControlReading(compact(+ control.getAttribute?.('aria-label') || control.innerText || control.textContent, 120));+ if (shareReading === null) {+ return { success: true, messageSend: null, conclusive: false, composerAvailable: false,+ reasonCode: 'message_control_unread', identityCandidates: [] };+ }+ if (shareReading === 'publish' || shareReading === 'send') {+ return { success: true, messageSend: false, conclusive: true, publicPost: true, identityCandidates: [] };+ }+ return { success: true, messageSend: false, conclusive: true, nonMessagingTarget: true,+ reasonCode: 'non_messaging_target', identityCandidates: [] };+ }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 bcd17b44c..1cb70d5f0 100644--- a/test/fixtures/message-recipient-navigation.mjs+++ b/test/fixtures/message-recipient-navigation.mjs@@ -822,6 +822,76 @@ export function registerMessageRecipientNavigationFixtures({}});+ // LinkedIn's server-driven share composer, as it renders today: only the+ // screen carries a stable marker; its controls have generated classes+ // and no data-control-name.+ const composeShareScreen = (page, { postLabel = 'Post', editors = 1, scope = '' } = {}) => page.evaluate(+ ({ postLabel, editors, scope }) => {+ document.getElementById('share-dialog')?.remove();+ const dialog = document.createElement('dialog');+ dialog.id = 'share-dialog';+ dialog.setAttribute('data-testid', 'dialog');+ dialog.setAttribute('aria-labelledby', 'dialog-header');+ dialog.innerHTML = `<div><div data-testid="dialog-content" ${scope}>+ <div data-sdui-screen="com.linkedin.sdui.flagshipnav.sharing.ShareCompose">+ <header id="dialog-header"><div id="audience" role="button" tabindex="0" aria-expanded="false">Post to Anyone</div></header>+ ${'<div class="i0lme8" contenteditable="true" role="textbox">Announcement</div>'.repeat(editors)}+ <button id="emoji" class="i0lmel" type="button" aria-label="Show Emoji Picker" aria-haspopup="dialog" aria-expanded="false">☺</button>+ <button id="publish" class="i0lmel i0lmek" type="button" componentkey="e70cd7cc-0374-459c-b8c9-4c6b56099738"><span>${postLabel}</span></button>+ </div></div></div>+ <button id="dismiss" type="button" aria-label="Dismiss">×</button>`;+ document.body.append(dialog);+ dialog.showModal();+ document.getElementById('chat').hidden = true;+ }, { postLabel, editors, scope });++ register(`${kind}: LinkedIn's server-driven share composer posts in any language, and its other controls only edit the draft`, async (page) => {+ const { agent, guard, probe } = await setup(page);+ await page.evaluate(() => history.replaceState({}, '', '/sharing/compose'));+ const plan = (overrides = {}) => agent._startPlanExecutionGuard(1, 'act', {+ requestKind: 'execute', requiresStateChange: true, requiresSubmission: true, ...overrides });+ // The task started on another site: no LinkedIn workflow, and no+ // private message named. Its plan requires the submission.+ plan();+ for (const postLabel of ['Post', 'Gönder']) {+ await composeShareScreen(page, { postLabel });+ const ref = await page.evaluate(() => window.__wb_ax_ref(document.querySelector('#publish span')));+ for (const [tool, args] of [['click', { selector: '#publish' }], ['click', { text: postLabel }], ['click_ax', { ref_id: ref }]]) {+ const observed = await probe(tool, args);+ assert.equal(observed.publicPost, true, JSON.stringify({ postLabel, tool, args, observed }));+ assert.equal(observed.messageSend, false);+ assert.equal(await guard(tool, args), null, `${postLabel} ${tool}: the planned post goes through`);+ }+ }+ // The draft's other controls are not sends, and not the post.+ await composeShareScreen(page);+ for (const selector of ['#emoji', '#audience', '[contenteditable="true"]']) {+ const observed = await probe('click', { selector });+ assert.equal(observed.conclusive, true, selector);+ assert.equal(observed.messageSend, false, selector);+ assert.notEqual(observed.publicPost, true, selector);+ assert.equal(await guard('click', { selector }), null, selector);+ }+ // A task that names a private message to send, or asks for no+ // submission at all, does not post.+ plan({ messaging: { target_kind: 'named', recipients: [{ identity: 'Alice', role: 'to' }] } });+ const messageTask = await guard('click', { selector: '#publish' });+ assert.equal(messageTask?.reasonCode, 'public_post_not_authorized');+ assert.match(messageTask.error, /authorizes a private message, not a public post/);+ plan({ requiresSubmission: false, requiresStateChange: false });+ const readTask = await guard('click', { selector: '#publish' });+ assert.equal(readTask?.reasonCode, 'public_post_not_authorized');+ assert.match(readTask.error, /does not ask to publish anything/);+ // Without the screen's own evidence (a second editor, or a messaging+ // scope around it), the composer keeps the old refusal.+ plan();+ for (const variant of [{ editors: 2 }, { scope: 'data-conversation-id="alice"' }]) {+ await composeShareScreen(page, variant);+ assert.equal((await guard('click', { selector: '#publish' }))?.noDispatch, true, JSON.stringify(variant));+ }+ await page.evaluate(() => document.getElementById('share-dialog')?.remove());+ });+register(`${kind}: LinkedIn post entry classification rejects send and publish lookalikes`, async (page) => {const { guard, probe } = await setup(page);await addPostEntry(page);