Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Keep Gmail Send ownership to structure, never to labels or history

Emre Sokulluc9b1a6f094e1
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index 40b8baa35..e96317ca5 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -7811,18 +7811,23 @@
if (tokens.length === 1 && tokens[0] === 'to') return 'to';
return '';
};
- const recipientRole = (el, root = null) => {
+ // `structural` reads the row from Gmail's own attributes and its input
+ // fields only, never from a label on another element, which page text
+ // (a contact's name, a message) can fill.
+ const recipientRole = (el, root = null, structural = false) => {
let current = el;
for (let depth = 0; current && depth < 7; depth++, current = current.parentElement) {
- for (const attribute of ['data-recipient-type', 'data-type', 'name', 'aria-label']) {
+ for (const attribute of structural ? ['data-recipient-type', 'data-type', 'name']
+ : ['data-recipient-type', 'data-type', 'name', 'aria-label']) {
const role = roleFromAttribute(attribute, current.getAttribute?.(attribute));
if (role) return role;
}
if (root && current === root) break;
try {
const descendantRoles = new Set();
- for (const marker of current.querySelectorAll?.(
- 'input[name="to"],input[name="cc"],input[name="bcc"],[aria-label]'
+ for (const marker of current.querySelectorAll?.(structural
+ ? 'input[name="to"],input[name="cc"],input[name="bcc"],input[aria-label]'
+ : 'input[name="to"],input[name="cc"],input[name="bcc"],[aria-label]'
) || []) {
const role = roleFromAttribute('name', marker.getAttribute?.('name'))
|| roleFromAttribute('aria-label', marker.getAttribute?.('aria-label'));
@@ -7835,7 +7840,7 @@
}
return '';
};
- const collectGmailRecipients = (root, editor = composer) => {
+ const collectGmailRecipients = (root, editor = composer, structural = false) => {
const collected = new Map();
if (!root?.querySelectorAll) return collected;
for (const el of root.querySelectorAll('[email],[data-hovercard-id],[data-email]')) {
@@ -7871,7 +7876,7 @@
}
const key = normalizedIdentity(email);
if (!key) continue;
- const role = recipientRole(el, root);
+ const role = recipientRole(el, root, structural);
if (!role) continue;
const recipientKey = `${role}:${key}`;
const prior = collected.get(recipientKey) || { identity: email, role, aliases: new Map() };
@@ -7882,26 +7887,30 @@
};
// A message's header field (To, Cc, Bcc or subject) belongs to its
// compose window and is never a message's body: Gmail's own field
- // names, or a label a model reads as one of those fields.
+ // names, or a single-line input whose label a model reads as one of
+ // those fields. A message body or a Chat composer is never an input,
+ // and a label (which can carry a contact's name) never exempts one.
const gmailHeaderField = el => {
if (el?.matches?.('[name="to"],[name="cc"],[name="bcc"],[name="subjectbox"]')) return true;
- const label = compact(el?.getAttribute?.('aria-label'), 120);
+ if (String(el?.tagName || '').toUpperCase() !== 'INPUT') return false;
+ const label = compact(el.getAttribute?.('aria-label'), 120);
return !!label && ['to', 'cc', 'bcc', 'subject'].includes(_pageReading('message_field', label));
};
// Another message's editor than `editor`: not nested with it, not a
// search or navigation field and not a message's header field.
const otherMessageEditor = (other, editor) => other !== editor && !editor?.contains?.(other)
&& !other.contains?.(editor) && !verifiedNavigationEditable(other) && !gmailHeaderField(other);
- // What marks a container as holding a message's recipients: Gmail's
- // own row names, a chip in a To/Cc/Bcc row, or a field read as one of
- // those rows, typed into or not.
+ // What marks a container as holding a message's recipients, read from
+ // Gmail's structure: its own row names, a chip in a row those name, or
+ // an input field read as a To/Cc/Bcc row, typed into or not.
const gmailRecipientMarkers = (root, editor) => !!root && (
!!root.querySelector?.('[name="to"],[name="cc"],[name="bcc"]')
- || collectGmailRecipients(root, editor).size > 0
+ || collectGmailRecipients(root, editor, true).size > 0
|| Array.from(root.querySelectorAll?.('input, textarea, [contenteditable="true"], [contenteditable=""]') || [])
- .slice(0, 40).some(input => visible(input) && input !== editor && !editor?.contains?.(input)
- && !!(roleFromAttribute('name', input.getAttribute?.('name'))
- || roleFromAttribute('aria-label', input.getAttribute?.('aria-label')))));
+ .slice(0, 40).some(field => visible(field) && field !== editor && !editor?.contains?.(field)
+ && !!(roleFromAttribute('name', field.getAttribute?.('name'))
+ || (String(field.tagName || '').toUpperCase() === 'INPUT'
+ && roleFromAttribute('aria-label', field.getAttribute?.('aria-label'))))));
// In Gmail a send has recipients only from its composer's own mail
// compose window: a popup or full-screen compose is the editor's
// dialog (else its form), marked by recipient rows, a subject or
@@ -7936,23 +7945,47 @@
|| /^#chat(?:[/?]|$)/.test(String(location.hash || '')));
} catch { return false; }
})();
- const gmailChatMainOf = (editor, ownWindow = gmailComposeWindowOf(editor)) => gmailChatRoute && editor && !ownWindow
- && editor.getAttribute?.('g_editable') !== 'true' && !editor.closest?.('[role="dialog"]')
- ? editor.closest?.('main,[role="main"]') || null : null;
+ // Between an element and the Chat's main region: a scrolling area (or,
+ // with `lists`, a log, list or feed), where the conversation's history
+ // and the threads inside it live.
+ const gmailInChatHistory = (el, main, lists = true) => {
+ for (let node = el?.parentElement; node && node !== main; node = node.parentElement) {
+ if (lists && node.matches?.('[role="log"],[role="list"],[role="feed"]')) return true;
+ try {
+ const style = getComputedStyle(node);
+ if (/^(auto|scroll|overlay)$/.test(String(style.overflowY || style.overflow || '').toLowerCase())
+ && Number(node.scrollHeight) > Number(node.clientHeight) + 1) return true;
+ } catch {}
+ }
+ return false;
+ };
+ // A composer inside that history, such as a thread's reply box in the
+ // scrolling message list, is not the Chat's own composer.
+ const gmailChatMainOf = (editor, ownWindow = gmailComposeWindowOf(editor)) => {
+ if (!gmailChatRoute || !editor || ownWindow || editor.getAttribute?.('g_editable') === 'true'
+ || editor.closest?.('[role="dialog"]')) return null;
+ const main = editor.closest?.('main,[role="main"]') || null;
+ return main && !gmailInChatHistory(editor, main) ? main : null;
+ };
// The composer a control (a Send, an attachment input) belongs to: the
// one message editor in the control's nearest ancestor holding any,
- // when that editor is a Gmail compose or Chat composer. Its message,
- // not the page's lowest editor, is what the control sends. None, or
- // more than one there, leaves the pairing to the page's layout.
+ // when the control lies inside that editor's own compose window or
+ // Chat region. Its message, not the page's lowest editor, is what the
+ // control sends. A click into an editor only focuses it; a page control
+ // that merely shares a distant ancestor with one editor (a toolbar's
+ // Archive) is no message's; and none, or more than one editor there,
+ // leaves the pairing to the page's layout.
const gmailControlComposer = control => {
- if (!gmailRecipientMode || !control) return null;
+ if (!gmailRecipientMode || !control || editable(control)) return null;
for (let node = control; node && node !== document.documentElement; node = node.parentElement) {
const inside = composerCandidates.filter(editor => node.contains?.(editor)
&& !verifiedNavigationEditable(editor) && !gmailHeaderField(editor));
if (!inside.length) continue;
const owners = inside.filter(editor => !inside.some(other => other !== editor && other.contains?.(editor)));
- return owners.length === 1 && (gmailComposeWindowOf(owners[0]) || gmailChatMainOf(owners[0]))
- ? owners[0] : null;
+ if (owners.length !== 1) return null;
+ const ownWindow = gmailComposeWindowOf(owners[0]);
+ const scope = ownWindow || gmailChatMainOf(owners[0], ownWindow);
+ return scope?.contains?.(control) ? owners[0] : null;
}
return null;
};
@@ -8229,6 +8262,9 @@
const addStrongIdentity = (el) => {
if (!visible(el) || editable(el) || el.closest?.('input,textarea,[contenteditable="true"]')) return;
if (!inConversationHeaderBand(el) || independentScrollableRegion(el, composer)) return;
+ // In a Gmail Chat, nothing inside a scrolling area below its main
+ // region (its history, a thread) names the conversation.
+ if (gmailChatMain && gmailInChatHistory(el, gmailChatMain, false)) return;
const text = compact(
el.getAttribute?.('aria-label')
|| el.getAttribute?.('title')
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 657251a65..8e6c7beff 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -6992,18 +6992,23 @@
if (tokens.length === 1 && tokens[0] === 'to') return 'to';
return '';
};
- const recipientRole = (el, root = null) => {
+ // `structural` reads the row from Gmail's own attributes and its input
+ // fields only, never from a label on another element, which page text
+ // (a contact's name, a message) can fill.
+ const recipientRole = (el, root = null, structural = false) => {
let current = el;
for (let depth = 0; current && depth < 7; depth++, current = current.parentElement) {
- for (const attribute of ['data-recipient-type', 'data-type', 'name', 'aria-label']) {
+ for (const attribute of structural ? ['data-recipient-type', 'data-type', 'name']
+ : ['data-recipient-type', 'data-type', 'name', 'aria-label']) {
const role = roleFromAttribute(attribute, current.getAttribute?.(attribute));
if (role) return role;
}
if (root && current === root) break;
try {
const descendantRoles = new Set();
- for (const marker of current.querySelectorAll?.(
- 'input[name="to"],input[name="cc"],input[name="bcc"],[aria-label]'
+ for (const marker of current.querySelectorAll?.(structural
+ ? 'input[name="to"],input[name="cc"],input[name="bcc"],input[aria-label]'
+ : 'input[name="to"],input[name="cc"],input[name="bcc"],[aria-label]'
) || []) {
const role = roleFromAttribute('name', marker.getAttribute?.('name'))
|| roleFromAttribute('aria-label', marker.getAttribute?.('aria-label'));
@@ -7016,7 +7021,7 @@
}
return '';
};
- const collectGmailRecipients = (root, editor = composer) => {
+ const collectGmailRecipients = (root, editor = composer, structural = false) => {
const collected = new Map();
if (!root?.querySelectorAll) return collected;
for (const el of root.querySelectorAll('[email],[data-hovercard-id],[data-email]')) {
@@ -7052,7 +7057,7 @@
}
const key = normalizedIdentity(email);
if (!key) continue;
- const role = recipientRole(el, root);
+ const role = recipientRole(el, root, structural);
if (!role) continue;
const recipientKey = `${role}:${key}`;
const prior = collected.get(recipientKey) || { identity: email, role, aliases: new Map() };
@@ -7063,26 +7068,30 @@
};
// A message's header field (To, Cc, Bcc or subject) belongs to its
// compose window and is never a message's body: Gmail's own field
- // names, or a label a model reads as one of those fields.
+ // names, or a single-line input whose label a model reads as one of
+ // those fields. A message body or a Chat composer is never an input,
+ // and a label (which can carry a contact's name) never exempts one.
const gmailHeaderField = el => {
if (el?.matches?.('[name="to"],[name="cc"],[name="bcc"],[name="subjectbox"]')) return true;
- const label = compact(el?.getAttribute?.('aria-label'), 120);
+ if (String(el?.tagName || '').toUpperCase() !== 'INPUT') return false;
+ const label = compact(el.getAttribute?.('aria-label'), 120);
return !!label && ['to', 'cc', 'bcc', 'subject'].includes(_pageReading('message_field', label));
};
// Another message's editor than `editor`: not nested with it, not a
// search or navigation field and not a message's header field.
const otherMessageEditor = (other, editor) => other !== editor && !editor?.contains?.(other)
&& !other.contains?.(editor) && !verifiedNavigationEditable(other) && !gmailHeaderField(other);
- // What marks a container as holding a message's recipients: Gmail's
- // own row names, a chip in a To/Cc/Bcc row, or a field read as one of
- // those rows, typed into or not.
+ // What marks a container as holding a message's recipients, read from
+ // Gmail's structure: its own row names, a chip in a row those name, or
+ // an input field read as a To/Cc/Bcc row, typed into or not.
const gmailRecipientMarkers = (root, editor) => !!root && (
!!root.querySelector?.('[name="to"],[name="cc"],[name="bcc"]')
- || collectGmailRecipients(root, editor).size > 0
+ || collectGmailRecipients(root, editor, true).size > 0
|| Array.from(root.querySelectorAll?.('input, textarea, [contenteditable="true"], [contenteditable=""]') || [])
- .slice(0, 40).some(input => visible(input) && input !== editor && !editor?.contains?.(input)
- && !!(roleFromAttribute('name', input.getAttribute?.('name'))
- || roleFromAttribute('aria-label', input.getAttribute?.('aria-label')))));
+ .slice(0, 40).some(field => visible(field) && field !== editor && !editor?.contains?.(field)
+ && !!(roleFromAttribute('name', field.getAttribute?.('name'))
+ || (String(field.tagName || '').toUpperCase() === 'INPUT'
+ && roleFromAttribute('aria-label', field.getAttribute?.('aria-label'))))));
// In Gmail a send has recipients only from its composer's own mail
// compose window: a popup or full-screen compose is the editor's
// dialog (else its form), marked by recipient rows, a subject or
@@ -7117,23 +7126,47 @@
|| /^#chat(?:[/?]|$)/.test(String(location.hash || '')));
} catch { return false; }
})();
- const gmailChatMainOf = (editor, ownWindow = gmailComposeWindowOf(editor)) => gmailChatRoute && editor && !ownWindow
- && editor.getAttribute?.('g_editable') !== 'true' && !editor.closest?.('[role="dialog"]')
- ? editor.closest?.('main,[role="main"]') || null : null;
+ // Between an element and the Chat's main region: a scrolling area (or,
+ // with `lists`, a log, list or feed), where the conversation's history
+ // and the threads inside it live.
+ const gmailInChatHistory = (el, main, lists = true) => {
+ for (let node = el?.parentElement; node && node !== main; node = node.parentElement) {
+ if (lists && node.matches?.('[role="log"],[role="list"],[role="feed"]')) return true;
+ try {
+ const style = getComputedStyle(node);
+ if (/^(auto|scroll|overlay)$/.test(String(style.overflowY || style.overflow || '').toLowerCase())
+ && Number(node.scrollHeight) > Number(node.clientHeight) + 1) return true;
+ } catch {}
+ }
+ return false;
+ };
+ // A composer inside that history, such as a thread's reply box in the
+ // scrolling message list, is not the Chat's own composer.
+ const gmailChatMainOf = (editor, ownWindow = gmailComposeWindowOf(editor)) => {
+ if (!gmailChatRoute || !editor || ownWindow || editor.getAttribute?.('g_editable') === 'true'
+ || editor.closest?.('[role="dialog"]')) return null;
+ const main = editor.closest?.('main,[role="main"]') || null;
+ return main && !gmailInChatHistory(editor, main) ? main : null;
+ };
// The composer a control (a Send, an attachment input) belongs to: the
// one message editor in the control's nearest ancestor holding any,
- // when that editor is a Gmail compose or Chat composer. Its message,
- // not the page's lowest editor, is what the control sends. None, or
- // more than one there, leaves the pairing to the page's layout.
+ // when the control lies inside that editor's own compose window or
+ // Chat region. Its message, not the page's lowest editor, is what the
+ // control sends. A click into an editor only focuses it; a page control
+ // that merely shares a distant ancestor with one editor (a toolbar's
+ // Archive) is no message's; and none, or more than one editor there,
+ // leaves the pairing to the page's layout.
const gmailControlComposer = control => {
- if (!gmailRecipientMode || !control) return null;
+ if (!gmailRecipientMode || !control || editable(control)) return null;
for (let node = control; node && node !== document.documentElement; node = node.parentElement) {
const inside = composerCandidates.filter(editor => node.contains?.(editor)
&& !verifiedNavigationEditable(editor) && !gmailHeaderField(editor));
if (!inside.length) continue;
const owners = inside.filter(editor => !inside.some(other => other !== editor && other.contains?.(editor)));
- return owners.length === 1 && (gmailComposeWindowOf(owners[0]) || gmailChatMainOf(owners[0]))
- ? owners[0] : null;
+ if (owners.length !== 1) return null;
+ const ownWindow = gmailComposeWindowOf(owners[0]);
+ const scope = ownWindow || gmailChatMainOf(owners[0], ownWindow);
+ return scope?.contains?.(control) ? owners[0] : null;
}
return null;
};
@@ -7383,6 +7416,9 @@
const addStrongIdentity = (el) => {
if (!visible(el) || editable(el) || el.closest?.('input,textarea,[contenteditable="true"]')) return;
if (!inConversationHeaderBand(el) || independentScrollableRegion(el, composer)) return;
+ // In a Gmail Chat, nothing inside a scrolling area below its main
+ // region (its history, a thread) names the conversation.
+ if (gmailChatMain && gmailInChatHistory(el, gmailChatMain, false)) return;
const text = compact(
el.getAttribute?.('aria-label')
|| el.getAttribute?.('title')
diff --git a/test/improver-content-recipient.mjs b/test/improver-content-recipient.mjs
index fb03e2915..9b8033c87 100644
--- a/test/improver-content-recipient.mjs
+++ b/test/improver-content-recipient.mjs
@@ -66,18 +66,31 @@ const TO_ADA = '<div name="to"><span email="[email protected]">Ada</span></div>';
const CC_CEM = '<div name="cc"><span email="[email protected]">Cem</span></div>';
const BCC_DEE = '<div name="bcc"><span email="[email protected]">Dee</span></div>';
const TO_FIELD = value => `<input id="to-input" role="combobox" aria-label="To recipients" value="${value}">`;
-const gmailChat = ({ rows = '', raise = 0, chatFile = false, appFile = false } = {}) => `<!doctype html><style>body{margin:0;font:16px sans-serif}
+const gmailChat = ({ rows = '', raise = 0, chatFile = false, appFile = false, chatLabel = 'Type a message', draft = 'Draft' } = {}) => `<!doctype html><style>body{margin:0;font:16px sans-serif}
#chat{position:absolute;left:0;top:0;width:640px;height:780px}#chat>header{height:70px}
#messages{height:580px;overflow:auto}footer{display:flex;gap:15px;align-items:center}
#body{width:500px;min-height:32px}button{min-height:28px}[role=dialog]{position:absolute;left:660px;bottom:${raise}px;width:560px}</style>
<div id="app"><main id="chat" role="main"><header><h2>Bob</h2></header>
<section id="messages"><div class="msg">Bob: please also write to <a href="mailto:[email protected]">[email protected]</a></div></section>
- <footer><div id="body" contenteditable="true" role="textbox" aria-label="Type a message">Hi Bob</div>
+ <footer><div id="body" contenteditable="true" role="textbox" aria-label="${chatLabel}">Hi Bob</div>
${chatFile ? '<input id="chat-file" type="file">' : ''}<button id="send" type="button" aria-label="Send">Send</button></footer></main>
${appFile ? '<input id="app-file" type="file">' : ''}
${rows ? `<div role="dialog" aria-label="New Message"><form onsubmit="return false">${rows}
- <div contenteditable="true" role="textbox" aria-label="Message Body">Draft</div>
+ <div id="mail-body" contenteditable="true" role="textbox" aria-label="Message Body" style="min-height:32px">${draft}</div>
<button id="mail-send" type="button" aria-label="Send">Send</button></form></div>` : ''}</div>`;
+// A Gmail Chat space whose history scrolls, with a thread's reply box inside
+// it: a heading in that history names a person, not the space.
+const gmailChatThread = header => `<!doctype html><style>body{margin:0;font:16px sans-serif}
+ #chat{position:absolute;left:0;top:0;width:900px;height:780px}#chat>header{height:60px}
+ #messages{height:600px;overflow:auto}.t{display:block;width:500px;min-height:32px}footer{display:flex;gap:10px}</style>
+ <main id="chat" role="main"><header>${header}</header>
+ <section id="messages"><div role="heading" aria-level="3">Ada</div><div>Ada: can you send me the numbers?</div>
+ <div style="height:150px"></div>
+ <div class="thread"><div class="t" contenteditable="true" role="textbox" aria-label="Type a message">The Q3 numbers</div>
+ <button id="send" type="button" aria-label="Send">Send</button></div>
+ <div style="height:600px"></div></section>
+ <footer><div class="t" contenteditable="true" role="textbox" aria-label="Type a message"></div>
+ <button id="main-send" type="button" aria-label="Send">Send</button></footer></main>`;
const gmailCompose = rows => `<!doctype html><style>body{margin:0;font:16px sans-serif}[role=dialog]{width:800px}
#body{display:block;width:700px;min-height:60px}</style>
<main role="main"><h2>Inbox</h2></main>
@@ -375,6 +388,62 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
});
}
+ // A model's reading of a label never makes a Chat composer something
+ // other than a message's editor, even when the label names a person.
+ for (const raise of [0, 150]) {
+ test(`${build}: a Gmail Chat composer labelled with a contact's name stays the Chat's own (${raise ? 'raised' : 'docked'} compose window)`, async () => {
+ const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/dm/abc', recipients: ['[email protected]'],
+ html: gmailChat({ rows: TO_ADA, raise, chatLabel: 'Reply to Bob' }) });
+ try {
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked?.success, false, JSON.stringify(blocked));
+ assert.deepEqual(blocked.recipientConfirmation?.recipients, [{ identity: 'Bob', role: 'to' }], JSON.stringify(blocked));
+ assert.equal(context.messageRecipientDispatchBinding, undefined);
+ assert.equal(await f.page.evaluate(() => window.sent), 0);
+ } finally { await f.browser.close(); }
+ });
+ }
+
+ // A thread's reply box inside the scrolling history is not the Chat's own
+ // composer, and a heading in that history never names its recipient.
+ for (const [kind, header] of [['in a plain block', '<div>Team space</div>'], ['as a heading', '<h2>Team space</h2>']]) {
+ test(`${build}: a Gmail Chat thread reply never takes its recipient from the history (space name ${kind})`, async () => {
+ for (const recipients of [['Ada'], ['Team space']]) {
+ const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/space/AAA', recipients, html: gmailChatThread(header) });
+ try {
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked?.success, false, `${recipients}: ${JSON.stringify(blocked)}`);
+ for (const item of blocked.recipientConfirmation?.recipients || []) assert.notEqual(item.identity, 'Ada', JSON.stringify(blocked));
+ assert.equal(context.messageRecipientDispatchBinding, undefined);
+ assert.equal(await f.page.evaluate(() => window.sent), 0);
+ } finally { await f.browser.close(); }
+ }
+ });
+ }
+
+ // A click into an editor only focuses it, and a page control far from
+ // any message is no message's Send.
+ test(`${build}: clicks into a Gmail editor or on a page control are not sends`, async () => {
+ const url = 'https://mail.google.com/mail/u/0/#chat/dm/abc';
+ for (const [raise, selector] of [[150, '#mail-body'], [0, '#body']]) {
+ const f = await fixture(build, Agent, { url, recipients: ['[email protected]'], html: gmailChat({ rows: TO_ADA, raise, draft: '' }) });
+ try {
+ assert.equal(await f.agent._messageRecipientGuardBlock(71, 'click', { selector }, url, {}), null, `${selector}, raise ${raise}`);
+ } finally { await f.browser.close(); }
+ }
+ const html = `<!doctype html><style>body{margin:0;font:16px sans-serif}main{position:absolute;left:0;top:0;width:1200px;height:780px}
+ .toolbar{position:absolute;left:900px;top:10px}.reply{position:absolute;left:0;top:80px}#body{display:block;width:560px;min-height:40px}</style>
+ <main role="main"><div class="toolbar"><button id="archive" type="button" aria-label="Archive">Archive</button></div>
+ <h2>Invoice</h2><div class="reply"><div class="rows">${TO_ADA}</div>
+ <div id="body" g_editable="true" contenteditable="true" role="textbox" aria-label="Message Body">Thanks Ada</div>
+ <div><button id="send" type="button" aria-label="Send">Send</button></div></div></main>`;
+ const inbox = 'https://mail.google.com/mail/u/0/#inbox/FMfc123';
+ const f = await fixture(build, Agent, { url: inbox, recipients: ['[email protected]'], html });
+ try {
+ assert.equal(await f.agent._messageRecipientGuardBlock(71, 'click', { selector: '#archive' }, inbox, {}), null);
+ } finally { await f.browser.close(); }
+ });
+
// An attachment goes with the message its file input belongs to: the
// Chat's input to the chat's person, an input no one message owns to no
// one, and neither to a compose window's recipients beside it.
@@ -461,6 +530,28 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
});
}
+ // Two replies open in one thread: each Send goes with its own reply.
+ test(`${build}: two Gmail inline replies each bind their own To`, async () => {
+ const html = `<!doctype html><style>body{margin:0;font:16px sans-serif}main{position:absolute;left:0;top:0;width:1200px;height:780px}
+ .r1{position:absolute;left:0;top:300px}.r2{position:absolute;left:0;top:560px}.b{display:block;width:560px;min-height:40px}</style>
+ <main role="main"><h2>Thread</h2>
+ <div class="r1"><div class="rows">${TO_ADA}</div><div class="b" g_editable="true" contenteditable="true" role="textbox" aria-label="Message Body">To Ada</div>
+ <div><button id="send" type="button" aria-label="Send">Send</button></div></div>
+ <div class="r2"><div class="rows">${CC_CEM.replace('name="cc"', 'name="to"')}</div><div class="b" g_editable="true" contenteditable="true" role="textbox" aria-label="Message Body">To Cem</div>
+ <div><button id="send2" type="button" aria-label="Send">Send</button></div></div></main>`;
+ const url = 'https://mail.google.com/mail/u/0/#inbox/FMfc123';
+ const f = await fixture(build, Agent, { url, recipients: ['[email protected]'], html });
+ try {
+ const second = await f.agent._messageRecipientGuardBlock(71, 'click', { selector: '#send2' }, url, {});
+ assert.deepEqual(second?.recipientConfirmation?.recipients, [{ identity: '[email protected]', role: 'to' }], JSON.stringify(second));
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked, null, JSON.stringify(blocked));
+ const result = await call(f.page, 'click', { ...sendArgs, ...context });
+ assert.equal(result.success, true, JSON.stringify(result));
+ assert.equal(await f.page.evaluate(() => window.sent), 1);
+ } finally { await f.browser.close(); }
+ });
+
test(`${build}: a Gmail popup compose with a typed To address binds with the To field focused`, async () => {
const html = `<!doctype html><style>body{margin:0;font:16px sans-serif}[role=dialog]{position:absolute;right:20px;bottom:0;width:560px}
#body{display:block;width:500px;min-height:60px}</style><main role="main"><h2>Inbox</h2></main>