Skip to content

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

Fix cross-site editor and dialog verification

Emre Sokullu01ac0aba0d19
diff --git a/package.json b/package.json
index ac104b8cf..06233b330 100644
--- a/package.json
+++ b/package.json
@@ -53,8 +53,8 @@
"benchmark:relevance": "node scripts/benchmark-offline-relevance.mjs --verbose",
"test:social-contract": "node --test test/social-publish-contract.mjs",
"test:social-contract:dom": "node test/social-publish-contract-dom.mjs",
- "test:runtime-lifecycle": "node --test test/agent-lifecycle.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/chat-steering.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/media-download-agent-handler.mjs && node test/ui-content-lifecycle.mjs && node --test test/chat-steering-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs && node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs",
- "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs && node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs",
+ "test:runtime-lifecycle": "node --test test/agent-lifecycle.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/chat-steering.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/media-download-agent-handler.mjs && node test/ui-content-lifecycle.mjs && node --test test/chat-steering-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs && node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs",
+ "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/draftjs-text.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs && node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs",
"test:chat-steering": "node --test test/chat-steering.mjs test/chat-steering-ui.mjs",
"test:rich-text-dom": "node test/ui-content-lifecycle.mjs --dom",
"test:firefox-bidi": "node --test test/firefox-bidi.mjs test/firefox-full-page-screenshot.mjs",
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 45b393ff9..63e94a6b2 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -25378,10 +25378,87 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
if (!children.every(node => node.nodeType === 1 && node.tagName === 'P')) return null;
return children.map(read).join('\n');
}
+ function readEmptyCaretText(el) {
+ if (!el?.isContentEditable || el.innerText !== '\n' || el.textContent !== '') return null;
+ let node = el;
+ for (let depth = 0; depth < 16; depth++) {
+ if (node.nodeType !== 1 || node.shadowRoot || node.hidden
+ || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return null;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ if (!style || style.display === 'none' || ['hidden', 'collapse'].includes(style.visibility)
+ || style.opacity === '0' || style.contentVisibility === 'hidden') return null;
+ if (node.tagName === 'BR') return node.childNodes.length === 0 ? '' : null;
+ // Only one caret placeholder through ordinary block/inline wrappers.
+ // Extra text, empty blocks, breaks, embeds or sibling nodes stay literal.
+ if ((node !== el && !['DIV', 'P', 'SPAN'].includes(node.tagName)) || node.childNodes.length !== 1) return null;
+ node = node.childNodes[0];
+ }
+ return null;
+ }
+
+ function isDraftJsEditor(el) {
+ return !!el?.isContentEditable && (el.classList?.contains('public-DraftEditor-content')
+ || Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true'));
+ }
+
+ function readDraftJsText(el) {
+ if (!el?.isContentEditable || !el.childNodes) return null;
+ const roots = Array.from(el.childNodes);
+ if (roots.length !== 1 || roots[0].nodeType !== 1 || roots[0].tagName !== 'DIV'
+ || roots[0].getAttribute('data-contents') !== 'true') return null;
+ let visited = 0;
+ const supported = node => {
+ if (++visited > 4096 || node.shadowRoot || node.hidden || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return false;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ return !!style && (style.display !== 'none' && !['hidden', 'collapse'].includes(style.visibility)
+ && style.opacity !== '0' && style.contentVisibility !== 'hidden');
+ };
+ if (!supported(el) || !supported(roots[0])) return null;
+ const blocks = Array.from(roots[0].childNodes);
+ if (!blocks.length) return null;
+ const texts = [];
+ for (const block of blocks) {
+ if (block.nodeType !== 1 || block.tagName !== 'DIV' || block.getAttribute('data-block') !== 'true'
+ || !block.getAttribute('data-offset-key') || !supported(block)) return null;
+ const children = Array.from(block.childNodes);
+ const body = children[0];
+ if (children.length !== 1 || body?.nodeType !== 1 || body.tagName !== 'DIV'
+ || !body.classList.contains('public-DraftStyleDefault-block')
+ || !body.getAttribute('data-offset-key') || !supported(body)) return null;
+ const leaves = [];
+ const read = (node, depth = 0) => {
+ if (depth > 32 || node.nodeType !== 1 || !supported(node)) return false;
+ if (node.tagName === 'BR') {
+ if (node.getAttribute('data-text') !== 'true' || node.childNodes.length) return false;
+ leaves.push(null); return true;
+ }
+ if (node.tagName !== 'SPAN') return false;
+ const descendants = Array.from(node.childNodes);
+ if (node.getAttribute('data-text') === 'true') {
+ if (!descendants.every(child => child.nodeType === 3)) return false;
+ leaves.push(descendants.map(child => child.nodeValue || '').join('')); return true;
+ }
+ return descendants.length > 0 && descendants.every(child => read(child, depth + 1));
+ };
+ if (!body.childNodes.length || !Array.from(body.childNodes).every(node => read(node))) return null;
+ // DraftJS's sole data-text BR in an empty block is a caret placeholder.
+ // Real document breaks are separators between blocks (or text in leaves).
+ // Mixed BR/text and embeds are unsupported; keep their rendered fallback.
+ const placeholders = leaves.filter(value => value === null).length;
+ if (placeholders && (placeholders !== 1 || leaves.some(value => value !== null && value !== ''))) return null;
+ texts.push(leaves.filter(value => value !== null).join(''));
+ }
+ return texts.join('\n');
+ }
+
const publicationEditorText = editor => {
- const semantic = readProseMirrorText(editor);
+ const draftJs = isDraftJsEditor(editor);
+ const semantic = draftJs ? readDraftJsText(editor) : (readProseMirrorText(editor) ?? readEmptyCaretText(editor));
if (semantic !== null) return semantic;
if (typeof editor.value === 'string') return editor.value;
+ if (draftJs) return null;
const read = node => {
if (node.nodeType === 3) return node.nodeValue || '';
if (node.nodeType !== 1) return '';
@@ -25491,7 +25568,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
const target = contextUrls.length === 1 ? contextUrls[0] : inlineThreadTarget;
return { bodyText, attachments,
context: { kind: reply ? 'reply' : contextUrls.length ? 'quote' : 'post', target },
- complete: bodyText.length <= 25000 && mediaNodes.length <= 20 && contextUrls.length <= 1 && (!reply || !!target) };
+ complete: typeof bodyText === 'string' && bodyText.length <= 25000 && mediaNodes.length <= 20 && contextUrls.length <= 1 && (!reply || !!target) };
});
return { complete: posts.every(p => p.complete) && !sharedMedia && allMedia.every(node => ownedMedia.has(node)), account: account.identity, posts };
} catch { return { complete: false }; }
diff --git a/src/chrome/src/cdp/cdp-client.js b/src/chrome/src/cdp/cdp-client.js
index 58ebc61b4..bf7340455 100644
--- a/src/chrome/src/cdp/cdp-client.js
+++ b/src/chrome/src/cdp/cdp-client.js
@@ -49,6 +49,81 @@ function readProseMirrorText(el) {
return children.map(read).join('\n');
}
+function readEmptyCaretText(el) {
+ if (!el?.isContentEditable || el.innerText !== '\n' || el.textContent !== '') return null;
+ let node = el;
+ for (let depth = 0; depth < 16; depth++) {
+ if (node.nodeType !== 1 || node.shadowRoot || node.hidden
+ || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return null;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ if (!style || style.display === 'none' || ['hidden', 'collapse'].includes(style.visibility)
+ || style.opacity === '0' || style.contentVisibility === 'hidden') return null;
+ if (node.tagName === 'BR') return node.childNodes.length === 0 ? '' : null;
+ // Only one caret placeholder through ordinary block/inline wrappers.
+ // Extra text, empty blocks, breaks, embeds or sibling nodes stay literal.
+ if ((node !== el && !['DIV', 'P', 'SPAN'].includes(node.tagName)) || node.childNodes.length !== 1) return null;
+ node = node.childNodes[0];
+ }
+ return null;
+}
+
+function isDraftJsEditor(el) {
+ return !!el?.isContentEditable && (el.classList?.contains('public-DraftEditor-content')
+ || Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true'));
+}
+
+function readDraftJsText(el) {
+ if (!el?.isContentEditable || !el.childNodes) return null;
+ const roots = Array.from(el.childNodes);
+ if (roots.length !== 1 || roots[0].nodeType !== 1 || roots[0].tagName !== 'DIV'
+ || roots[0].getAttribute('data-contents') !== 'true') return null;
+ let visited = 0;
+ const supported = node => {
+ if (++visited > 4096 || node.shadowRoot || node.hidden || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return false;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ return !!style && (style.display !== 'none' && !['hidden', 'collapse'].includes(style.visibility)
+ && style.opacity !== '0' && style.contentVisibility !== 'hidden');
+ };
+ if (!supported(el) || !supported(roots[0])) return null;
+ const blocks = Array.from(roots[0].childNodes);
+ if (!blocks.length) return null;
+ const texts = [];
+ for (const block of blocks) {
+ if (block.nodeType !== 1 || block.tagName !== 'DIV' || block.getAttribute('data-block') !== 'true'
+ || !block.getAttribute('data-offset-key') || !supported(block)) return null;
+ const children = Array.from(block.childNodes);
+ const body = children[0];
+ if (children.length !== 1 || body?.nodeType !== 1 || body.tagName !== 'DIV'
+ || !body.classList.contains('public-DraftStyleDefault-block')
+ || !body.getAttribute('data-offset-key') || !supported(body)) return null;
+ const leaves = [];
+ const read = (node, depth = 0) => {
+ if (depth > 32 || node.nodeType !== 1 || !supported(node)) return false;
+ if (node.tagName === 'BR') {
+ if (node.getAttribute('data-text') !== 'true' || node.childNodes.length) return false;
+ leaves.push(null); return true;
+ }
+ if (node.tagName !== 'SPAN') return false;
+ const descendants = Array.from(node.childNodes);
+ if (node.getAttribute('data-text') === 'true') {
+ if (!descendants.every(child => child.nodeType === 3)) return false;
+ leaves.push(descendants.map(child => child.nodeValue || '').join('')); return true;
+ }
+ return descendants.length > 0 && descendants.every(child => read(child, depth + 1));
+ };
+ if (!body.childNodes.length || !Array.from(body.childNodes).every(node => read(node))) return null;
+ // DraftJS's sole data-text BR in an empty block is a caret placeholder.
+ // Real document breaks are separators between blocks (or text in leaves).
+ // Mixed BR/text and embeds are unsupported; keep their rendered fallback.
+ const placeholders = leaves.filter(value => value === null).length;
+ if (placeholders && (placeholders !== 1 || leaves.some(value => value !== null && value !== ''))) return null;
+ texts.push(leaves.filter(value => value !== null).join(''));
+ }
+ return texts.join('\n');
+}
+
const FULL_PAGE_SCROLL_SETTLE_MS = 100;
const FULL_PAGE_STABLE_PASSES = 2;
const FULL_PAGE_MAX_DISCOVERY_STEPS = 100;
@@ -4760,7 +4835,10 @@ export class CDPClient {
if (!el || el.nodeType !== 1 || !el.isConnected) return null;
const tag = String(el.tagName || '').toUpperCase();
if (!(el.isContentEditable || ['INPUT', 'TEXTAREA'].includes(tag))) return null;
- const semantic = (${readProseMirrorText.toString()})(el);
+ const draftJs = (${isDraftJsEditor.toString()})(el);
+ const semantic = draftJs ? (${readDraftJsText.toString()})(el)
+ : ((${readProseMirrorText.toString()})(el) ?? (${readEmptyCaretText.toString()})(el));
+ if (draftJs && semantic === null) return null;
const value = semantic !== null ? semantic : String(el.isContentEditable ? (el.textContent || '') : (el.value || ''));
return (${TEXT_ENTRY_SIGNATURE_SOURCE})(value);
}`;
@@ -4811,7 +4889,10 @@ export class CDPClient {
if (!el || !el.isConnected) return null;
const tag = String(el.tagName || '').toUpperCase();
if (!(el.isContentEditable || ['INPUT', 'TEXTAREA'].includes(tag))) return null;
- const semantic = (${readProseMirrorText.toString()})(el);
+ const draftJs = (${isDraftJsEditor.toString()})(el);
+ const semantic = draftJs ? (${readDraftJsText.toString()})(el)
+ : ((${readProseMirrorText.toString()})(el) ?? (${readEmptyCaretText.toString()})(el));
+ if (draftJs && semantic === null) return null;
const value = semantic !== null ? semantic : String(el.isContentEditable ? (el.textContent || '') : (el.value || ''));
return (${TEXT_ENTRY_SIGNATURE_SOURCE})(value);
})()
@@ -4855,7 +4936,10 @@ export class CDPClient {
const tag = String(el.tagName || '').toUpperCase();
const typeable = el.isContentEditable || ['INPUT', 'TEXTAREA'].includes(tag);
if (!typeable) return { found: true, verified: false };
- const semantic = (${readProseMirrorText.toString()})(el);
+ const draftJs = (${isDraftJsEditor.toString()})(el);
+ const semantic = draftJs ? (${readDraftJsText.toString()})(el)
+ : ((${readProseMirrorText.toString()})(el) ?? (${readEmptyCaretText.toString()})(el));
+ if (draftJs && semantic === null) return { found: true, verified: false };
if (semantic !== null) expected = expected.replace(/\\r\\n?/g, '\\n');
const value = semantic !== null ? semantic : String(el.isContentEditable ? (el.textContent || '') : (el.value || ''));
const signatureOf = ${TEXT_ENTRY_SIGNATURE_SOURCE};
@@ -4937,7 +5021,10 @@ export class CDPClient {
const tag = String(el.tagName || '').toUpperCase();
const typeable = el.isContentEditable || ['INPUT', 'TEXTAREA'].includes(tag);
if (!typeable) return { found: true, verified: false };
- const semantic = (${readProseMirrorText.toString()})(el);
+ const draftJs = (${isDraftJsEditor.toString()})(el);
+ const semantic = draftJs ? (${readDraftJsText.toString()})(el)
+ : ((${readProseMirrorText.toString()})(el) ?? (${readEmptyCaretText.toString()})(el));
+ if (draftJs && semantic === null) return { found: true, verified: false };
if (semantic !== null) expected = expected.replace(/\\r\\n?/g, '\\n');
const value = semantic !== null ? semantic : String(el.isContentEditable ? (el.textContent || '') : (el.value || ''));
const signatureOf = ${TEXT_ENTRY_SIGNATURE_SOURCE};
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index fdc3cffd0..5fb12f9e6 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -4665,8 +4665,84 @@
return children.map(read).join('\n');
}
+ function readEmptyCaretText(el) {
+ if (!el?.isContentEditable || el.innerText !== '\n' || el.textContent !== '') return null;
+ let node = el;
+ for (let depth = 0; depth < 16; depth++) {
+ if (node.nodeType !== 1 || node.shadowRoot || node.hidden
+ || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return null;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ if (!style || style.display === 'none' || ['hidden', 'collapse'].includes(style.visibility)
+ || style.opacity === '0' || style.contentVisibility === 'hidden') return null;
+ if (node.tagName === 'BR') return node.childNodes.length === 0 ? '' : null;
+ // Only one caret placeholder through ordinary block/inline wrappers.
+ // Extra text, empty blocks, breaks, embeds or sibling nodes stay literal.
+ if ((node !== el && !['DIV', 'P', 'SPAN'].includes(node.tagName)) || node.childNodes.length !== 1) return null;
+ node = node.childNodes[0];
+ }
+ return null;
+ }
+
+ function isDraftJsEditor(el) {
+ return !!el?.isContentEditable && (el.classList?.contains('public-DraftEditor-content')
+ || Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true'));
+ }
+
+ function readDraftJsText(el) {
+ if (!el?.isContentEditable || !el.childNodes) return null;
+ const roots = Array.from(el.childNodes);
+ if (roots.length !== 1 || roots[0].nodeType !== 1 || roots[0].tagName !== 'DIV'
+ || roots[0].getAttribute('data-contents') !== 'true') return null;
+ let visited = 0;
+ const supported = node => {
+ if (++visited > 4096 || node.shadowRoot || node.hidden || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return false;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ return !!style && (style.display !== 'none' && !['hidden', 'collapse'].includes(style.visibility)
+ && style.opacity !== '0' && style.contentVisibility !== 'hidden');
+ };
+ if (!supported(el) || !supported(roots[0])) return null;
+ const blocks = Array.from(roots[0].childNodes);
+ if (!blocks.length) return null;
+ const texts = [];
+ for (const block of blocks) {
+ if (block.nodeType !== 1 || block.tagName !== 'DIV' || block.getAttribute('data-block') !== 'true'
+ || !block.getAttribute('data-offset-key') || !supported(block)) return null;
+ const children = Array.from(block.childNodes);
+ const body = children[0];
+ if (children.length !== 1 || body?.nodeType !== 1 || body.tagName !== 'DIV'
+ || !body.classList.contains('public-DraftStyleDefault-block')
+ || !body.getAttribute('data-offset-key') || !supported(body)) return null;
+ const leaves = [];
+ const read = (node, depth = 0) => {
+ if (depth > 32 || node.nodeType !== 1 || !supported(node)) return false;
+ if (node.tagName === 'BR') {
+ if (node.getAttribute('data-text') !== 'true' || node.childNodes.length) return false;
+ leaves.push(null); return true;
+ }
+ if (node.tagName !== 'SPAN') return false;
+ const descendants = Array.from(node.childNodes);
+ if (node.getAttribute('data-text') === 'true') {
+ if (!descendants.every(child => child.nodeType === 3)) return false;
+ leaves.push(descendants.map(child => child.nodeValue || '').join('')); return true;
+ }
+ return descendants.length > 0 && descendants.every(child => read(child, depth + 1));
+ };
+ if (!body.childNodes.length || !Array.from(body.childNodes).every(node => read(node))) return null;
+ // DraftJS's sole data-text BR in an empty block is a caret placeholder.
+ // Real document breaks are separators between blocks (or text in leaves).
+ // Mixed BR/text and embeds are unsupported; keep their rendered fallback.
+ const placeholders = leaves.filter(value => value === null).length;
+ if (placeholders && (placeholders !== 1 || leaves.some(value => value !== null && value !== ''))) return null;
+ texts.push(leaves.filter(value => value !== null).join(''));
+ }
+ return texts.join('\n');
+ }
+
function _editableTextValue(el) {
- const semantic = readProseMirrorText(el);
+ const semantic = isDraftJsEditor(el) ? readDraftJsText(el)
+ : (readProseMirrorText(el) ?? readEmptyCaretText(el));
return semantic !== null ? semantic : (typeof el.innerText === 'string' ? el.innerText : (el.textContent || ''));
}
@@ -8088,6 +8164,10 @@
} catch { return null; }
})();
const fieldMeta = _fieldMeta(el);
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure cannot establish its exact document text. Re-observe this editor before typing.',
+ { ref_id, verified: false, fieldMeta, recoveryRequired: 'fresh_tree', retryable: false },
+ );
let previous = '';
let method = '';
let selectExpected = null;
@@ -8180,10 +8260,14 @@
{ ref_id, verified: false, recoveryRequired: 'verify_or_restore_field', failureScope: `field-value:${ref_id}`, retryable: false, fieldMeta },
);
}
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure changed during typing and cannot establish its exact document text.',
+ { ref_id, verified: false, fieldMeta, recoveryRequired: 'verify_or_restore_field', failureScope: `field-value:${ref_id}`, retryable: false },
+ );
const actual = el.isContentEditable ? _editableTextValue(el) : (el.value || '');
const verified = selectExpected !== null
? actual === selectExpected
- : _setFieldValueMatches(actual, previous, text, !!clear, el.isContentEditable, readProseMirrorText(el) !== null);
+ : _setFieldValueMatches(actual, previous, text, !!clear, el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null));
const fallbackAttempted = false;
if (!verified) {
return failure(
@@ -8295,6 +8379,10 @@
return failure(`ref_id ${ref_id} is not a text field (tag=${el.tagName}). set_field works on input/textarea/contenteditable only.`);
}
const fieldMeta = _fieldMeta(el);
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure cannot establish its exact document text. Re-observe this editor before typing.',
+ { ref_id, verified: false, fieldMeta, recoveryRequired: 'fresh_tree', retryable: false },
+ );
let prevValue = '';
if (el.isContentEditable) {
prevValue = _editableTextValue(el);
@@ -8340,8 +8428,12 @@
{ ref_id, verified: false, recoveryRequired: 'verify_or_restore_field', failureScope: `field-value:${ref_id}`, retryable: false },
);
}
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure changed during typing and cannot establish its exact document text.',
+ { ref_id, verified: false, fieldMeta, recoveryRequired: 'verify_or_restore_field', failureScope: `field-value:${ref_id}`, retryable: false },
+ );
const actual = el.isContentEditable ? _editableTextValue(el) : (el.value || '');
- const verified = _setFieldValueMatches(actual, prevValue, text, clear, el.isContentEditable, readProseMirrorText(el) !== null);
+ const verified = _setFieldValueMatches(actual, prevValue, text, clear, el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null));
const fallbackAttempted = false;
let nativeSubmitAttempted = false;
let submissionOutcomeUnknown = false;
@@ -8566,6 +8658,8 @@
if (typeof window.__wb_ax_lookup !== 'function') return { success: false, verified: false, error: 'accessibility-tree.js not injected' };
const el = window.__wb_ax_lookup(ref_id);
if (!el || !el.isConnected) return { success: false, verified: false, error: `ref_id ${ref_id} is stale` };
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null)
+ return { success: false, verified: false, error: 'The DraftJS editor structure cannot establish its exact document text.' };
const actual = el.isContentEditable ? _editableTextValue(el) : (el.value || '');
const verifiesAppend = el.isContentEditable && typeof appendText === 'string';
const expectedPrefix = verifiesAppend
@@ -8580,7 +8674,7 @@
expectedPrefix,
verifiesAppend ? appendText : expected,
!verifiesAppend,
- el.isContentEditable, readProseMirrorText(el) !== null,
+ el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null),
),
actual: actual.slice(0, 200),
fieldMeta: _fieldMeta(el),
@@ -8635,6 +8729,8 @@
if (!(el.isContentEditable || tag === 'INPUT' || tag === 'TEXTAREA')) {
return { success: false, error: 'target is not a text field' };
}
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null)
+ return { success: false, verified: false, error: 'The DraftJS editor structure cannot establish its exact document text.' };
const value = String(el.isContentEditable ? _editableTextValue(el) : (el.value || ''));
if (!globalThis.crypto?.subtle) return { success: false, error: 'SHA-256 is unavailable' };
const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
@@ -8644,7 +8740,7 @@
return {
success: true,
...(typeof expected === 'string' ? {
- verified: _setFieldValueMatches(value, '', expected, true, el.isContentEditable, readProseMirrorText(el) !== null),
+ verified: _setFieldValueMatches(value, '', expected, true, el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null)),
} : {}),
valueLength: value.length,
valueSha256,
diff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.js
index 2b19a5747..45eb0c998 100644
--- a/src/chrome/src/content/page-monitor.js
+++ b/src/chrome/src/content/page-monitor.js
@@ -606,7 +606,11 @@
for (const id of (el.getAttribute(attribute) || '').split(/\s+/).filter(Boolean)) {
const root = el.getRootNode();
const matches = root.querySelectorAll?.(`[id="${CSS.escape(id)}"]`);
- if (matches?.length !== 1) return null;
+ // Dangling ARIA references name no current label. Their attributes
+ // remain bound, and a label appearing later changes the footprint.
+ // Ambiguous references cannot establish an exact action context.
+ if (!matches?.length) continue;
+ if (matches.length !== 1) return null;
labels.add(matches[0]);
}
}
@@ -632,16 +636,46 @@
return context;
} catch { return null; }
}
- function dialogTextIsCovered(owner, boundTextNodes, addNode) {
+ function dialogTextIsCovered(owner, boundTextNodes, addNode, identities, form) {
+ const authoredLabel = node => ['aria-label', 'aria-labelledby', 'aria-describedby', 'title', 'alt']
+ .some(attribute => node.getAttribute(attribute)?.trim());
+ const collectedIdentities = new Set();
+ const addIdentity = node => {
+ const pending = [node];
+ while (pending.length) {
+ const current = pending.pop();
+ if (collectedIdentities.has(current)) continue;
+ if (collectedIdentities.size >= 256 || current.shadowRoot || current.closest('aside,[role="complementary"]')
+ || (current.closest('form,[role="form"]') && current.closest('form,[role="form"]') !== form)
+ || current.matches('input,textarea,select,[contenteditable]:not([contenteditable="false"])')
+ || current.querySelector('input,textarea,select,[contenteditable]:not([contenteditable="false"])')
+ || [...current.querySelectorAll(modelControlSelector)].some(control => !boundTextNodes.has(control))
+ || !addNode(current, { text: true, fullTextRequired: true })) return false;
+ identities.add(current); collectedIdentities.add(current);
+ const labels = modelLabels(current);
+ if (!labels || labels.length + pending.length + collectedIdentities.size > 256) return false;
+ pending.push(...labels.map(label => label.node));
+ }
+ return true;
+ };
const stack = [...owner.childNodes];
let visited = 0;
while (stack.length) {
if (++visited > 256) return false;
const node = stack.pop();
if (node.nodeType === 3) {
- // Direct owner text is already bound; generic nested text may name a
- // destination that the control/heading footprint cannot establish.
- if (node.data.trim() && node.parentElement !== owner) return false;
+ if (node.data.trim()) {
+ const parent = node.parentElement;
+ // Plain recipient/account text needs the same complete observation
+ // as authored labels. Do not borrow text from an excluded control,
+ // another form/sidebar, or a wrapper containing editable values.
+ if (parent !== owner && (parent.closest(modelControlSelector)
+ || parent.closest('aside,[role="complementary"]')
+ || (parent.closest('form,[role="form"]') && parent.closest('form,[role="form"]') !== form)
+ || parent.querySelector('input,textarea,select,[contenteditable]:not([contenteditable="false"])')
+ || !addNode(parent, { directText: true }))) return false;
+ identities.add(parent);
+ }
continue;
}
if (!(node instanceof Element) || ignored(node)) continue;
@@ -651,8 +685,15 @@
// text. Shadow subtrees have no complete text binding here.
if (node.shadowRoot) return false;
if (boundTextNodes.has(node)) continue;
- if (node.matches(modelEntityIdentitySelector) || ['aria-label', 'aria-labelledby', 'aria-describedby', 'title', 'alt']
- .some(attribute => node.getAttribute(attribute)?.trim())) return false;
+ if (node.matches(modelEntityIdentitySelector) || node.matches(entityOwnerSelector)
+ || node.matches(modelControlSelector)) return false;
+ if (authoredLabel(node)) {
+ // Account avatars and other authored labels are meaningful context.
+ // Bind their complete subtree and expose the current rendered identity
+ // in the same model observation rather than silently omitting it.
+ if (!addIdentity(node)) return false;
+ continue;
+ }
if (visited + stack.length + node.childNodes.length > 256) return false;
stack.push(...node.childNodes);
}
@@ -661,14 +702,22 @@
// including label roots outside the dialog. Editable descendants keep
// their existing value continuation instead of acquiring extra bindings.
for (const root of boundTextNodes) {
+ // Authored wrappers can conceal nested account labels. Their reference
+ // chains are collected when admitted, even for roots already visited.
const descendants = root.querySelectorAll('*');
if (root.shadowRoot || descendants.length > 256) return false;
for (const child of descendants) {
if (ignored(child)) continue;
- if (child.shadowRoot || (child.matches(modelEntityIdentitySelector) && !boundTextNodes.has(child))) return false;
+ if (child.shadowRoot || ((child.matches(modelEntityIdentitySelector) || child.matches(entityOwnerSelector)
+ || child.matches(modelControlSelector)) && !boundTextNodes.has(child))) return false;
// An ARIA textbox can be a read-only destination display. Only real
// editable DOM hosts need the native value-continuation exemption.
- if (!child.isContentEditable && !child.closest('input,textarea,select') && !addNode(child)) return false;
+ if (!child.isContentEditable && !child.closest('input,textarea,select')) {
+ const style = getComputedStyle(child);
+ if (authoredLabel(child) && style.display !== 'none' && style.opacity !== '0' && style.contentVisibility !== 'hidden') {
+ if (!addIdentity(child)) return false;
+ } else if (!addNode(child)) return false;
+ }
}
}
return true;
@@ -711,10 +760,17 @@
}
if (!owner) { owner = fallback; unstructuredOwner = true; }
}
- const nodes = [], ancestors = [], boundTextNodes = new Set();
+ const nodes = [], ancestors = [], boundTextNodes = new Set(), dialogIdentities = new Set();
let uncoveredLabel = false;
const addNode = (node, options = {}) => {
- if (nodes.some(item => item.node === node)) return true;
+ const previous = nodes.find(item => item.node === node);
+ if (previous) {
+ // A form/owner may already have an attribute-only binding. Plain
+ // destination text must strengthen it without aggregating editor data
+ // or downgrading an existing complete label/control binding.
+ if (options.directText && !boundTextNodes.has(node)) previous.value = modelSemantic(node, { directText: true });
+ return !options.fullTextRequired || boundTextNodes.has(node);
+ }
if (nodes.length >= 256 || (node.tagName === 'INPUT' && node.type === 'file' && node.files?.length > 32)) return false;
const labels = modelLabels(node);
if (!labels) return false;
@@ -732,7 +788,7 @@
if (!addNode(target, { text: true, control: true, observedName: !structuralFile, structuralFile })
|| !addNode(action, { text: true, control: true, observedName: !structuralFile, structuralFile })) return null;
for (let ancestor = bindingParent(target); ancestor; ancestor = bindingParent(ancestor)) {
- if (ancestors.length >= 24) return null;
+ if (ancestors.length >= 64) return null;
const labels = modelLabels(ancestor);
if (!labels) return null;
const style = getComputedStyle(ancestor);
@@ -783,9 +839,9 @@
for (const control of owner.querySelectorAll(modelControlSelector)) {
if (belongs(control, headingFreeDialog) && !addNode(control, { text: true, control: true })) return null;
}
- // A heading-free dialog can supply a boundary for a controls-only
- // composer. Uncovered generic destination text keeps the strict fence.
- meaningfulOwner ||= headingFreeDialog && dialogTextIsCovered(owner, boundTextNodes, addNode) && !uncoveredLabel;
+ // A heading-free dialog can supply a boundary when all local labels,
+ // text and controls are bound and identities are completely observed.
+ meaningfulOwner ||= headingFreeDialog && dialogTextIsCovered(owner, boundTextNodes, addNode, dialogIdentities, form) && !uncoveredLabel;
}
// An arbitrary container/toolbar with no entity anchor cannot establish
// the recipient or item. Such targets retain strict legacy dispatch only.
@@ -802,6 +858,7 @@
const hit = structuralFile ? null : deepElementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
if (!structuralFile && (!hit || !(target === hit || target.contains(hit) || (action.contains(target) && action.contains(hit))))) return null;
return { model: true, structuralFile, target, scope: owner || form || action, ancestors, nodes, hit,
+ dialogIdentities,
...(conversation ? { conversationCarrier: conversation.carrier, conversationComposer: conversation.composer } : {}),
context: JSON.stringify([location.href, document.baseURI, currentViewport(), window.scrollX, window.scrollY,
rect ? [rect.left, rect.top, rect.width, rect.height] : null,
@@ -943,8 +1000,10 @@
}
let evidenceLength = 0;
const exposedEditableNames = new WeakMap();
- const exposeIdentity = (node, { authoredEditableName = false } = {}) => {
- if (publicNodes.has(node) && !authoredEditableName) return true;
+ const exposedCompleteLabels = new WeakSet();
+ const exposeIdentity = (node, { authoredEditableName = false, completeLabel = false } = {}) => {
+ if (publicNodes.has(node) && !authoredEditableName && !completeLabel) return true;
+ if (completeLabel && exposedCompleteLabels.has(node)) return true;
// Emit only current rendered page labels. Editable contents, input
// values, data identities and private control/file state stay private.
if (!visible(node) || (!authoredEditableName && node.matches('input,textarea,select,[contenteditable]:not([contenteditable="false"])'))
@@ -966,7 +1025,11 @@
const authored = String(node.getAttribute('aria-label') || node.getAttribute('title')
|| (authoredEditableName ? node.getAttribute('placeholder') : node.getAttribute('alt')) || '')
.replace(/\s+/g, ' ').trim();
- const name = authored || rendered;
+ // A reference-only carrier may have no own text. Its full referenced
+ // labels are exposed separately before the footprint is certified.
+ const referencedName = completeLabel && node.getAttribute('aria-labelledby')
+ ? String(window.__wb_ax_name?.(node) || '').replace(/\s+/g, ' ').trim() : '';
+ const name = authored || rendered || referencedName;
if (!name || authored.length > 512) return false;
if (authoredEditableName && exposedEditableNames.get(node) === authored) return true;
const ref = window.__wb_ax_ref?.(node);
@@ -980,6 +1043,7 @@
evidenceLength += line.length;
refs.set(ref, node); publicNodes.add(node);
if (authoredEditableName) exposedEditableNames.set(node, authored);
+ if (completeLabel) exposedCompleteLabels.add(node);
return true;
};
const observedFootprint = footprint => {
@@ -998,9 +1062,10 @@
}
const evidence = footprint.nodes.filter(item => item.node !== footprint.target
&& (item.node === footprint.conversationCarrier
+ || footprint.dialogIdentities?.has(item.node)
|| item.node.matches('h1,h2,h3,h4,h5,h6,[role="heading"],[aria-current],'+modelEntityIdentitySelector))
- && visible(item.node));
- return evidence.every(item => exposeIdentity(item.node))
+ && (footprint.dialogIdentities?.has(item.node) || visible(item.node)));
+ return evidence.every(item => exposeIdentity(item.node, { completeLabel: footprint.dialogIdentities?.has(item.node) }))
&& (publicNodes.has(footprint.scope) || evidence.some(item => publicNodes.has(item.node)));
};
const captureTarget = node => {
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index b70cffbae..a0e2e7692 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -23033,10 +23033,87 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (!children.every(node => node.nodeType === 1 && node.tagName === 'P')) return null;
return children.map(read).join('\n');
}
+ function readEmptyCaretText(el) {
+ if (!el?.isContentEditable || el.innerText !== '\n' || el.textContent !== '') return null;
+ let node = el;
+ for (let depth = 0; depth < 16; depth++) {
+ if (node.nodeType !== 1 || node.shadowRoot || node.hidden
+ || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return null;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ if (!style || style.display === 'none' || ['hidden', 'collapse'].includes(style.visibility)
+ || style.opacity === '0' || style.contentVisibility === 'hidden') return null;
+ if (node.tagName === 'BR') return node.childNodes.length === 0 ? '' : null;
+ // Only one caret placeholder through ordinary block/inline wrappers.
+ // Extra text, empty blocks, breaks, embeds or sibling nodes stay literal.
+ if ((node !== el && !['DIV', 'P', 'SPAN'].includes(node.tagName)) || node.childNodes.length !== 1) return null;
+ node = node.childNodes[0];
+ }
+ return null;
+ }
+
+ function isDraftJsEditor(el) {
+ return !!el?.isContentEditable && (el.classList?.contains('public-DraftEditor-content')
+ || Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true'));
+ }
+
+ function readDraftJsText(el) {
+ if (!el?.isContentEditable || !el.childNodes) return null;
+ const roots = Array.from(el.childNodes);
+ if (roots.length !== 1 || roots[0].nodeType !== 1 || roots[0].tagName !== 'DIV'
+ || roots[0].getAttribute('data-contents') !== 'true') return null;
+ let visited = 0;
+ const supported = node => {
+ if (++visited > 4096 || node.shadowRoot || node.hidden || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return false;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ return !!style && (style.display !== 'none' && !['hidden', 'collapse'].includes(style.visibility)
+ && style.opacity !== '0' && style.contentVisibility !== 'hidden');
+ };
+ if (!supported(el) || !supported(roots[0])) return null;
+ const blocks = Array.from(roots[0].childNodes);
+ if (!blocks.length) return null;
+ const texts = [];
+ for (const block of blocks) {
+ if (block.nodeType !== 1 || block.tagName !== 'DIV' || block.getAttribute('data-block') !== 'true'
+ || !block.getAttribute('data-offset-key') || !supported(block)) return null;
+ const children = Array.from(block.childNodes);
+ const body = children[0];
+ if (children.length !== 1 || body?.nodeType !== 1 || body.tagName !== 'DIV'
+ || !body.classList.contains('public-DraftStyleDefault-block')
+ || !body.getAttribute('data-offset-key') || !supported(body)) return null;
+ const leaves = [];
+ const read = (node, depth = 0) => {
+ if (depth > 32 || node.nodeType !== 1 || !supported(node)) return false;
+ if (node.tagName === 'BR') {
+ if (node.getAttribute('data-text') !== 'true' || node.childNodes.length) return false;
+ leaves.push(null); return true;
+ }
+ if (node.tagName !== 'SPAN') return false;
+ const descendants = Array.from(node.childNodes);
+ if (node.getAttribute('data-text') === 'true') {
+ if (!descendants.every(child => child.nodeType === 3)) return false;
+ leaves.push(descendants.map(child => child.nodeValue || '').join('')); return true;
+ }
+ return descendants.length > 0 && descendants.every(child => read(child, depth + 1));
+ };
+ if (!body.childNodes.length || !Array.from(body.childNodes).every(node => read(node))) return null;
+ // DraftJS's sole data-text BR in an empty block is a caret placeholder.
+ // Real document breaks are separators between blocks (or text in leaves).
+ // Mixed BR/text and embeds are unsupported; keep their rendered fallback.
+ const placeholders = leaves.filter(value => value === null).length;
+ if (placeholders && (placeholders !== 1 || leaves.some(value => value !== null && value !== ''))) return null;
+ texts.push(leaves.filter(value => value !== null).join(''));
+ }
+ return texts.join('\n');
+ }
+
const publicationEditorText = editor => {
- const semantic = readProseMirrorText(editor);
+ const draftJs = isDraftJsEditor(editor);
+ const semantic = draftJs ? readDraftJsText(editor) : (readProseMirrorText(editor) ?? readEmptyCaretText(editor));
if (semantic !== null) return semantic;
if (typeof editor.value === 'string') return editor.value;
+ if (draftJs) return null;
const read = node => {
if (node.nodeType === 3) return node.nodeValue || '';
if (node.nodeType !== 1) return '';
@@ -23146,7 +23223,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const target = contextUrls.length === 1 ? contextUrls[0] : inlineThreadTarget;
return { bodyText, attachments,
context: { kind: reply ? 'reply' : contextUrls.length ? 'quote' : 'post', target },
- complete: bodyText.length <= 25000 && mediaNodes.length <= 20 && contextUrls.length <= 1 && (!reply || !!target) };
+ complete: typeof bodyText === 'string' && bodyText.length <= 25000 && mediaNodes.length <= 20 && contextUrls.length <= 1 && (!reply || !!target) };
});
return { complete: posts.every(p => p.complete) && !sharedMedia && allMedia.every(node => ownedMedia.has(node)), account: account.identity, posts };
} catch { return { complete: false }; }
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 843a26930..102b573e6 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -3886,8 +3886,84 @@
return children.map(read).join('\n');
}
+ function readEmptyCaretText(el) {
+ if (!el?.isContentEditable || el.innerText !== '\n' || el.textContent !== '') return null;
+ let node = el;
+ for (let depth = 0; depth < 16; depth++) {
+ if (node.nodeType !== 1 || node.shadowRoot || node.hidden
+ || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return null;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ if (!style || style.display === 'none' || ['hidden', 'collapse'].includes(style.visibility)
+ || style.opacity === '0' || style.contentVisibility === 'hidden') return null;
+ if (node.tagName === 'BR') return node.childNodes.length === 0 ? '' : null;
+ // Only one caret placeholder through ordinary block/inline wrappers.
+ // Extra text, empty blocks, breaks, embeds or sibling nodes stay literal.
+ if ((node !== el && !['DIV', 'P', 'SPAN'].includes(node.tagName)) || node.childNodes.length !== 1) return null;
+ node = node.childNodes[0];
+ }
+ return null;
+ }
+
+ function isDraftJsEditor(el) {
+ return !!el?.isContentEditable && (el.classList?.contains('public-DraftEditor-content')
+ || Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true'));
+ }
+
+ function readDraftJsText(el) {
+ if (!el?.isContentEditable || !el.childNodes) return null;
+ const roots = Array.from(el.childNodes);
+ if (roots.length !== 1 || roots[0].nodeType !== 1 || roots[0].tagName !== 'DIV'
+ || roots[0].getAttribute('data-contents') !== 'true') return null;
+ let visited = 0;
+ const supported = node => {
+ if (++visited > 4096 || node.shadowRoot || node.hidden || String(node.getAttribute('aria-hidden') || '').trim().toLowerCase() === 'true'
+ || String(node.getAttribute('contenteditable') || '').trim().toLowerCase() === 'false') return false;
+ const style = node.ownerDocument?.defaultView?.getComputedStyle?.(node);
+ return !!style && (style.display !== 'none' && !['hidden', 'collapse'].includes(style.visibility)
+ && style.opacity !== '0' && style.contentVisibility !== 'hidden');
+ };
+ if (!supported(el) || !supported(roots[0])) return null;
+ const blocks = Array.from(roots[0].childNodes);
+ if (!blocks.length) return null;
+ const texts = [];
+ for (const block of blocks) {
+ if (block.nodeType !== 1 || block.tagName !== 'DIV' || block.getAttribute('data-block') !== 'true'
+ || !block.getAttribute('data-offset-key') || !supported(block)) return null;
+ const children = Array.from(block.childNodes);
+ const body = children[0];
+ if (children.length !== 1 || body?.nodeType !== 1 || body.tagName !== 'DIV'
+ || !body.classList.contains('public-DraftStyleDefault-block')
+ || !body.getAttribute('data-offset-key') || !supported(body)) return null;
+ const leaves = [];
+ const read = (node, depth = 0) => {
+ if (depth > 32 || node.nodeType !== 1 || !supported(node)) return false;
+ if (node.tagName === 'BR') {
+ if (node.getAttribute('data-text') !== 'true' || node.childNodes.length) return false;
+ leaves.push(null); return true;
+ }
+ if (node.tagName !== 'SPAN') return false;
+ const descendants = Array.from(node.childNodes);
+ if (node.getAttribute('data-text') === 'true') {
+ if (!descendants.every(child => child.nodeType === 3)) return false;
+ leaves.push(descendants.map(child => child.nodeValue || '').join('')); return true;
+ }
+ return descendants.length > 0 && descendants.every(child => read(child, depth + 1));
+ };
+ if (!body.childNodes.length || !Array.from(body.childNodes).every(node => read(node))) return null;
+ // DraftJS's sole data-text BR in an empty block is a caret placeholder.
+ // Real document breaks are separators between blocks (or text in leaves).
+ // Mixed BR/text and embeds are unsupported; keep their rendered fallback.
+ const placeholders = leaves.filter(value => value === null).length;
+ if (placeholders && (placeholders !== 1 || leaves.some(value => value !== null && value !== ''))) return null;
+ texts.push(leaves.filter(value => value !== null).join(''));
+ }
+ return texts.join('\n');
+ }
+
function _editableTextValue(el) {
- const semantic = readProseMirrorText(el);
+ const semantic = isDraftJsEditor(el) ? readDraftJsText(el)
+ : (readProseMirrorText(el) ?? readEmptyCaretText(el));
return semantic !== null ? semantic : (typeof el.innerText === 'string' ? el.innerText : (el.textContent || ''));
}
@@ -7099,11 +7175,15 @@
return { x: Math.round(r.x), y: Math.round(r.y), w: Math.round(r.width), h: Math.round(r.height) };
} catch { return null; }
})();
+ const fieldMeta = _fieldMeta(el);
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure cannot establish its exact document text. Re-observe this editor before typing.',
+ { ref_id, verified: false, fieldMeta, recoveryRequired: 'fresh_tree', retryable: false },
+ );
if (msg.params?._bidiPrepare && el.tagName !== 'SELECT') {
if (!_isTypeableElement(el)) return failure('Target is not editable');
return prepareBidiTarget(el, msg.params._bidiPrepare);
}
- const fieldMeta = _fieldMeta(el);
let previous = '';
let method = '';
let selectExpected = null;
@@ -7196,10 +7276,14 @@
{ ref_id, verified: false, recoveryRequired: 'verify_or_restore_field', failureScope: `field-value:${ref_id}`, retryable: false, fieldMeta },
);
}
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure changed during typing and cannot establish its exact document text.',
+ { ref_id, verified: false, fieldMeta, recoveryRequired: 'verify_or_restore_field', failureScope: `field-value:${ref_id}`, retryable: false },
+ );
const actual = el.isContentEditable ? _editableTextValue(el) : (el.value || '');
const verified = selectExpected !== null
? actual === selectExpected
- : _setFieldValueMatches(actual, previous, text, !!clear, el.isContentEditable, readProseMirrorText(el) !== null);
+ : _setFieldValueMatches(actual, previous, text, !!clear, el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null));
const fallbackAttempted = false;
if (!verified) {
return failure(
@@ -7295,6 +7379,10 @@
} else if (!el.isContentEditable && el.tagName !== 'TEXTAREA' && el.tagName !== 'INPUT') {
return failure(`ref_id ${ref_id} is not a text field (tag=${el.tagName}). set_field works on input/textarea/contenteditable only.`);
}
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure cannot establish its exact document text. Re-observe this editor before typing.',
+ { ref_id, verified: false, fieldMeta: _fieldMeta(el), recoveryRequired: 'fresh_tree', retryable: false },
+ );
if (msg.params?._bidiPrepare) {
if (submit && msg.params.messageRecipientGuardRequired) {
const validation = _consumeMessageRecipientDispatchBinding(msg.params, el);
@@ -7365,8 +7453,12 @@
);
}
const fieldMeta = _fieldMeta(el);
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) return failure(
+ 'The DraftJS editor structure changed during typing and cannot establish its exact document text.',
+ { ref_id, verified: false, fieldMeta, recoveryRequired: 'verify_or_restore_field', failureScope: `field-value:${ref_id}`, retryable: false },
+ );
const actual = el.isContentEditable ? _editableTextValue(el) : (el.value || '');
- const verified = _setFieldValueMatches(actual, prevValue, text, clear, el.isContentEditable, readProseMirrorText(el) !== null);
+ const verified = _setFieldValueMatches(actual, prevValue, text, clear, el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null));
const fallbackAttempted = false;
let nativeSubmitAttempted = false;
let submissionOutcomeUnknown = false;
@@ -7533,6 +7625,8 @@
if (typeof window.__wb_ax_lookup !== 'function') return { success: false, verified: false, error: 'accessibility-tree.js not injected' };
const el = window.__wb_ax_lookup(ref_id);
if (!el || !el.isConnected) return { success: false, verified: false, error: `ref_id ${ref_id} is stale` };
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null)
+ return { success: false, verified: false, error: 'The DraftJS editor structure cannot establish its exact document text.' };
const actual = el.isContentEditable ? _editableTextValue(el) : (el.value || '');
const verifiesAppend = el.isContentEditable && typeof appendText === 'string';
const expectedPrefix = verifiesAppend
@@ -7547,7 +7641,7 @@
expectedPrefix,
verifiesAppend ? appendText : expected,
!verifiesAppend,
- el.isContentEditable, readProseMirrorText(el) !== null,
+ el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null),
),
actual: actual.slice(0, 200),
fieldMeta: _fieldMeta(el),
@@ -7602,6 +7696,8 @@
if (!(el.isContentEditable || tag === 'INPUT' || tag === 'TEXTAREA')) {
return { success: false, error: 'target is not a text field' };
}
+ if (isDraftJsEditor(el) && readDraftJsText(el) === null)
+ return { success: false, verified: false, error: 'The DraftJS editor structure cannot establish its exact document text.' };
const value = String(el.isContentEditable ? _editableTextValue(el) : (el.value || ''));
if (!globalThis.crypto?.subtle) return { success: false, error: 'SHA-256 is unavailable' };
const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
@@ -7611,7 +7707,7 @@
return {
success: true,
...(typeof expected === 'string' ? {
- verified: _setFieldValueMatches(value, '', expected, true, el.isContentEditable, readProseMirrorText(el) !== null),
+ verified: _setFieldValueMatches(value, '', expected, true, el.isContentEditable, (readProseMirrorText(el) !== null || readDraftJsText(el) !== null || readEmptyCaretText(el) !== null)),
} : {}),
valueLength: value.length,
valueSha256,
diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.js
index 2b19a5747..45eb0c998 100644
--- a/src/firefox/src/content/page-monitor.js
+++ b/src/firefox/src/content/page-monitor.js
@@ -606,7 +606,11 @@
for (const id of (el.getAttribute(attribute) || '').split(/\s+/).filter(Boolean)) {
const root = el.getRootNode();
const matches = root.querySelectorAll?.(`[id="${CSS.escape(id)}"]`);
- if (matches?.length !== 1) return null;
+ // Dangling ARIA references name no current label. Their attributes
+ // remain bound, and a label appearing later changes the footprint.
+ // Ambiguous references cannot establish an exact action context.
+ if (!matches?.length) continue;
+ if (matches.length !== 1) return null;
labels.add(matches[0]);
}
}
@@ -632,16 +636,46 @@
return context;
} catch { return null; }
}
- function dialogTextIsCovered(owner, boundTextNodes, addNode) {
+ function dialogTextIsCovered(owner, boundTextNodes, addNode, identities, form) {
+ const authoredLabel = node => ['aria-label', 'aria-labelledby', 'aria-describedby', 'title', 'alt']
+ .some(attribute => node.getAttribute(attribute)?.trim());
+ const collectedIdentities = new Set();
+ const addIdentity = node => {
+ const pending = [node];
+ while (pending.length) {
+ const current = pending.pop();
+ if (collectedIdentities.has(current)) continue;
+ if (collectedIdentities.size >= 256 || current.shadowRoot || current.closest('aside,[role="complementary"]')
+ || (current.closest('form,[role="form"]') && current.closest('form,[role="form"]') !== form)
+ || current.matches('input,textarea,select,[contenteditable]:not([contenteditable="false"])')
+ || current.querySelector('input,textarea,select,[contenteditable]:not([contenteditable="false"])')
+ || [...current.querySelectorAll(modelControlSelector)].some(control => !boundTextNodes.has(control))
+ || !addNode(current, { text: true, fullTextRequired: true })) return false;
+ identities.add(current); collectedIdentities.add(current);
+ const labels = modelLabels(current);
+ if (!labels || labels.length + pending.length + collectedIdentities.size > 256) return false;
+ pending.push(...labels.map(label => label.node));
+ }
+ return true;
+ };
const stack = [...owner.childNodes];
let visited = 0;
while (stack.length) {
if (++visited > 256) return false;
const node = stack.pop();
if (node.nodeType === 3) {
- // Direct owner text is already bound; generic nested text may name a
- // destination that the control/heading footprint cannot establish.
- if (node.data.trim() && node.parentElement !== owner) return false;
+ if (node.data.trim()) {
+ const parent = node.parentElement;
+ // Plain recipient/account text needs the same complete observation
+ // as authored labels. Do not borrow text from an excluded control,
+ // another form/sidebar, or a wrapper containing editable values.
+ if (parent !== owner && (parent.closest(modelControlSelector)
+ || parent.closest('aside,[role="complementary"]')
+ || (parent.closest('form,[role="form"]') && parent.closest('form,[role="form"]') !== form)
+ || parent.querySelector('input,textarea,select,[contenteditable]:not([contenteditable="false"])')
+ || !addNode(parent, { directText: true }))) return false;
+ identities.add(parent);
+ }
continue;
}
if (!(node instanceof Element) || ignored(node)) continue;
@@ -651,8 +685,15 @@
// text. Shadow subtrees have no complete text binding here.
if (node.shadowRoot) return false;
if (boundTextNodes.has(node)) continue;
- if (node.matches(modelEntityIdentitySelector) || ['aria-label', 'aria-labelledby', 'aria-describedby', 'title', 'alt']
- .some(attribute => node.getAttribute(attribute)?.trim())) return false;
+ if (node.matches(modelEntityIdentitySelector) || node.matches(entityOwnerSelector)
+ || node.matches(modelControlSelector)) return false;
+ if (authoredLabel(node)) {
+ // Account avatars and other authored labels are meaningful context.
+ // Bind their complete subtree and expose the current rendered identity
+ // in the same model observation rather than silently omitting it.
+ if (!addIdentity(node)) return false;
+ continue;
+ }
if (visited + stack.length + node.childNodes.length > 256) return false;
stack.push(...node.childNodes);
}
@@ -661,14 +702,22 @@
// including label roots outside the dialog. Editable descendants keep
// their existing value continuation instead of acquiring extra bindings.
for (const root of boundTextNodes) {
+ // Authored wrappers can conceal nested account labels. Their reference
+ // chains are collected when admitted, even for roots already visited.
const descendants = root.querySelectorAll('*');
if (root.shadowRoot || descendants.length > 256) return false;
for (const child of descendants) {
if (ignored(child)) continue;
- if (child.shadowRoot || (child.matches(modelEntityIdentitySelector) && !boundTextNodes.has(child))) return false;
+ if (child.shadowRoot || ((child.matches(modelEntityIdentitySelector) || child.matches(entityOwnerSelector)
+ || child.matches(modelControlSelector)) && !boundTextNodes.has(child))) return false;
// An ARIA textbox can be a read-only destination display. Only real
// editable DOM hosts need the native value-continuation exemption.
- if (!child.isContentEditable && !child.closest('input,textarea,select') && !addNode(child)) return false;
+ if (!child.isContentEditable && !child.closest('input,textarea,select')) {
+ const style = getComputedStyle(child);
+ if (authoredLabel(child) && style.display !== 'none' && style.opacity !== '0' && style.contentVisibility !== 'hidden') {
+ if (!addIdentity(child)) return false;
+ } else if (!addNode(child)) return false;
+ }
}
}
return true;
@@ -711,10 +760,17 @@
}
if (!owner) { owner = fallback; unstructuredOwner = true; }
}
- const nodes = [], ancestors = [], boundTextNodes = new Set();
+ const nodes = [], ancestors = [], boundTextNodes = new Set(), dialogIdentities = new Set();
let uncoveredLabel = false;
const addNode = (node, options = {}) => {
- if (nodes.some(item => item.node === node)) return true;
+ const previous = nodes.find(item => item.node === node);
+ if (previous) {
+ // A form/owner may already have an attribute-only binding. Plain
+ // destination text must strengthen it without aggregating editor data
+ // or downgrading an existing complete label/control binding.
+ if (options.directText && !boundTextNodes.has(node)) previous.value = modelSemantic(node, { directText: true });
+ return !options.fullTextRequired || boundTextNodes.has(node);
+ }
if (nodes.length >= 256 || (node.tagName === 'INPUT' && node.type === 'file' && node.files?.length > 32)) return false;
const labels = modelLabels(node);
if (!labels) return false;
@@ -732,7 +788,7 @@
if (!addNode(target, { text: true, control: true, observedName: !structuralFile, structuralFile })
|| !addNode(action, { text: true, control: true, observedName: !structuralFile, structuralFile })) return null;
for (let ancestor = bindingParent(target); ancestor; ancestor = bindingParent(ancestor)) {
- if (ancestors.length >= 24) return null;
+ if (ancestors.length >= 64) return null;
const labels = modelLabels(ancestor);
if (!labels) return null;
const style = getComputedStyle(ancestor);
@@ -783,9 +839,9 @@
for (const control of owner.querySelectorAll(modelControlSelector)) {
if (belongs(control, headingFreeDialog) && !addNode(control, { text: true, control: true })) return null;
}
- // A heading-free dialog can supply a boundary for a controls-only
- // composer. Uncovered generic destination text keeps the strict fence.
- meaningfulOwner ||= headingFreeDialog && dialogTextIsCovered(owner, boundTextNodes, addNode) && !uncoveredLabel;
+ // A heading-free dialog can supply a boundary when all local labels,
+ // text and controls are bound and identities are completely observed.
+ meaningfulOwner ||= headingFreeDialog && dialogTextIsCovered(owner, boundTextNodes, addNode, dialogIdentities, form) && !uncoveredLabel;
}
// An arbitrary container/toolbar with no entity anchor cannot establish
// the recipient or item. Such targets retain strict legacy dispatch only.
@@ -802,6 +858,7 @@
const hit = structuralFile ? null : deepElementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
if (!structuralFile && (!hit || !(target === hit || target.contains(hit) || (action.contains(target) && action.contains(hit))))) return null;
return { model: true, structuralFile, target, scope: owner || form || action, ancestors, nodes, hit,
+ dialogIdentities,
...(conversation ? { conversationCarrier: conversation.carrier, conversationComposer: conversation.composer } : {}),
context: JSON.stringify([location.href, document.baseURI, currentViewport(), window.scrollX, window.scrollY,
rect ? [rect.left, rect.top, rect.width, rect.height] : null,
@@ -943,8 +1000,10 @@
}
let evidenceLength = 0;
const exposedEditableNames = new WeakMap();
- const exposeIdentity = (node, { authoredEditableName = false } = {}) => {
- if (publicNodes.has(node) && !authoredEditableName) return true;
+ const exposedCompleteLabels = new WeakSet();
+ const exposeIdentity = (node, { authoredEditableName = false, completeLabel = false } = {}) => {
+ if (publicNodes.has(node) && !authoredEditableName && !completeLabel) return true;
+ if (completeLabel && exposedCompleteLabels.has(node)) return true;
// Emit only current rendered page labels. Editable contents, input
// values, data identities and private control/file state stay private.
if (!visible(node) || (!authoredEditableName && node.matches('input,textarea,select,[contenteditable]:not([contenteditable="false"])'))
@@ -966,7 +1025,11 @@
const authored = String(node.getAttribute('aria-label') || node.getAttribute('title')
|| (authoredEditableName ? node.getAttribute('placeholder') : node.getAttribute('alt')) || '')
.replace(/\s+/g, ' ').trim();
- const name = authored || rendered;
+ // A reference-only carrier may have no own text. Its full referenced
+ // labels are exposed separately before the footprint is certified.
+ const referencedName = completeLabel && node.getAttribute('aria-labelledby')
+ ? String(window.__wb_ax_name?.(node) || '').replace(/\s+/g, ' ').trim() : '';
+ const name = authored || rendered || referencedName;
if (!name || authored.length > 512) return false;
if (authoredEditableName && exposedEditableNames.get(node) === authored) return true;
const ref = window.__wb_ax_ref?.(node);
@@ -980,6 +1043,7 @@
evidenceLength += line.length;
refs.set(ref, node); publicNodes.add(node);
if (authoredEditableName) exposedEditableNames.set(node, authored);
+ if (completeLabel) exposedCompleteLabels.add(node);
return true;
};
const observedFootprint = footprint => {
@@ -998,9 +1062,10 @@
}
const evidence = footprint.nodes.filter(item => item.node !== footprint.target
&& (item.node === footprint.conversationCarrier
+ || footprint.dialogIdentities?.has(item.node)
|| item.node.matches('h1,h2,h3,h4,h5,h6,[role="heading"],[aria-current],'+modelEntityIdentitySelector))
- && visible(item.node));
- return evidence.every(item => exposeIdentity(item.node))
+ && (footprint.dialogIdentities?.has(item.node) || visible(item.node)));
+ return evidence.every(item => exposeIdentity(item.node, { completeLabel: footprint.dialogIdentities?.has(item.node) }))
&& (publicNodes.has(footprint.scope) || evidence.some(item => publicNodes.has(item.node)));
};
const captureTarget = node => {
diff --git a/test/draftjs-text.mjs b/test/draftjs-text.mjs
new file mode 100644
index 000000000..5dd3ab830
--- /dev/null
+++ b/test/draftjs-text.mjs
@@ -0,0 +1,353 @@
+// Replays the real X DraftJS markup without opening a browser or an account.
+import assert from 'node:assert/strict';
+import { createHash, webcrypto } from 'node:crypto';
+import fs from 'node:fs';
+import vm from 'node:vm';
+import { test } from 'node:test';
+
+const area = { get: async () => ({}), set: async () => {}, remove: async () => {} };
+const api = { storage: { local: area, session: area },
+ runtime: { getURL: value => `chrome-extension://test/${value}`, sendMessage: async () => ({}) },
+ tabs: { get: async id => ({ id, url: 'https://x.com/compose/post' }), sendMessage: async () => ({}) },
+ scripting: { executeScript: async () => [{ result: null }] } };
+globalThis.chrome = api; globalThis.browser = api;
+const { Agent } = await import('../src/chrome/src/agent/agent.js');
+const { cdpClient } = await import('../src/chrome/src/cdp/cdp-client.js');
+const doc = { defaultView: { getComputedStyle: node => ({ display: 'inline', visibility: 'visible',
+ opacity: '1', contentVisibility: 'visible', ...node.style }) } };
+const textNode = value => ({ nodeType: 3, nodeValue: value });
+function element(tagName, attrs = {}, childNodes = []) {
+ return { nodeType: 1, tagName, childNodes, ownerDocument: doc, isConnected: true,
+ isContentEditable: true, style: {}, hidden: false, shadowRoot: null,
+ getAttribute: name => Object.hasOwn(attrs, name) ? attrs[name] : null,
+ classList: { contains: name => String(attrs.class || '').split(/\s+/).includes(name) },
+ get children() { return this.childNodes.filter(node => node.nodeType === 1); },
+ get firstElementChild() { return this.children[0] || null; },
+ get textContent() { return this.childNodes.map(node => node.nodeType === 3 ? node.nodeValue : node.textContent).join(''); },
+ focus() {}, getBoundingClientRect: () => ({ x: 10, y: 20, width: 300, height: 90 }),
+ };
+}
+const leaf = value => element('SPAN', { 'data-text': 'true' }, [textNode(value)]);
+function draft(lines = [''], { styledUrl = false, raw = lines.join('\n') } = {}) {
+ const blocks = lines.map((value, index) => {
+ const key = `block${index}-0-0`;
+ let leaves = value ? [element('SPAN', { 'data-offset-key': key }, [leaf(value)])]
+ : [element('SPAN', { 'data-offset-key': key }, [element('BR', { 'data-text': 'true' })])];
+ if (styledUrl && value) {
+ const split = value.indexOf('https://');
+ assert(split >= 0);
+ leaves = [element('SPAN', { 'data-offset-key': key }, [leaf(value.slice(0, split))]),
+ element('SPAN', { style: 'color: rgb(29, 155, 240)' }, [
+ element('SPAN', { 'data-offset-key': `block${index}-1-0` }, [leaf(value.slice(split))]),
+ ])];
+ }
+ return element('DIV', { 'data-block': 'true', 'data-editor': '5enet', 'data-offset-key': key }, [
+ element('DIV', { 'data-offset-key': key, class: 'public-DraftStyleDefault-block public-DraftStyleDefault-ltr' }, leaves),
+ ]);
+ });
+ const editor = element('DIV', { contenteditable: 'true', role: 'textbox' }, [element('DIV', { 'data-contents': 'true' }, blocks)]);
+ editor.innerText = raw; return editor;
+}
+function caret(wrappers = []) {
+ let node = element('BR');
+ for (const tag of [...wrappers].reverse()) node = element(tag, {}, [node]);
+ const editor = element('DIV', { contenteditable: 'true' }, [node]);
+ editor.innerText = '\n'; return editor;
+}
+function typeIntoCaret(editor, value) {
+ let parent = editor;
+ while (parent.firstElementChild?.tagName !== 'BR') parent = parent.firstElementChild;
+ parent.childNodes = [textNode(value)]; editor.innerText = value;
+}
+function functionSource(source, name) {
+ const start = source.indexOf(`function ${name}(`);
+ assert(start >= 0, name);
+ const indent = source.slice(source.lastIndexOf('\n', start) + 1, start);
+ const end = source.indexOf(`\n${indent}}`, start) + indent.length + 2;
+ assert(end > start, name); return source.slice(start, end);
+}
+function handlerSource(source, action) {
+ const start = source.indexOf(`'${action}':`);
+ const end = source.indexOf('\n },', start);
+ assert(start >= 0 && end > start, action);
+ return source.slice(source.indexOf(':', start) + 1, end + 8).trim();
+}
+function contentHarness(build, current) {
+ const source = fs.readFileSync(`src/${build}/src/content/content.js`, 'utf8');
+ const names = ['_setFieldValueMatches', 'readProseMirrorText', 'readEmptyCaretText', 'isDraftJsEditor', 'readDraftJsText', '_editableTextValue'];
+ if (build === 'chrome') names.unshift('_contentEditableValueMatches');
+ const context = vm.createContext({ crypto: webcrypto, TextEncoder, Uint8Array,
+ window: { __wb_ax_lookup: () => current.editor }, msg: { params: {} },
+ actionDeadlineExpired: () => false, _scrollElementIntoClearView() {}, showAgentWorkingTarget() {},
+ _fieldMeta: () => ({ tag: 'div', contentEditable: true, role: 'textbox', ariaLabel: 'Post text' }),
+ _stableFieldSelector: () => '#editor',
+ SET_FIELD_VERIFY_DELAY_MS: 0, setTimeout: resolve => resolve(),
+ document: { execCommand: (command, _ui, value) => {
+ if (command === 'insertText') current.onInsert?.(current.editor, value);
+ return true;
+ } },
+ });
+ vm.runInContext(names.map(name => functionSource(source, name)).join('\n'), context);
+ const handlers = Object.fromEntries(['type_ax', 'set_field', 'ax_verify_field_value', 'field_value_digest']
+ .map(action => [action, vm.runInContext(`(${handlerSource(source, action)})`, context)]));
+ return { read: editor => { context.el = editor; return vm.runInContext('_editableTextValue(el)', context); },
+ semantic: editor => { context.el = editor; return vm.runInContext('readDraftJsText(el)', context); },
+ matches: (actual, expected) => { context.actual = actual; context.expected = expected;
+ return vm.runInContext('_setFieldValueMatches(actual, "", expected, true, true, true)', context); },
+ async call(action, params = {}) { context.msg = { params }; return handlers[action](); },
+ };
+}
+const tweet = "Hidden gem on HF: AveLabs grafted Qwen3.8-27B's language head back onto Perplexity's pplx-decider-v1-27b. One set of weights handles both typed decisions and full chat on one server. https://huggingface.co/AveLabs/Qwen3.8-27B-Perplexing-Pegasus-NVFP4";
+
+for (const build of ['chrome', 'firefox']) {
+ if (build === 'firefox') test('Firefox: settled DraftJS write proof rejects unsupported reconciliation', async t => {
+ for (const action of ['type_ax', 'set_field']) await t.test(action, async () => {
+ let attempts = 0;
+ const current = { editor: draft([''], { raw: '\n' }), onInsert(editor, value) {
+ attempts++;
+ const typed = draft([value]); editor.childNodes = typed.childNodes; editor.innerText = value;
+ const suffix = leaf(' hidden suffix'); suffix.style.display = 'none';
+ editor.firstElementChild.firstElementChild.firstElementChild.childNodes.push(suffix);
+ } }, h = contentHarness(build, current);
+ const result = await h.call(action, { ref_id: 'ref_42', text: 'body', clear: false });
+ assert.equal(attempts, 1); assert.equal(result.success, false); assert.equal(result.verified, false);
+ assert.equal(result.dispatched, true); assert.equal(result.recoveryRequired, 'verify_or_restore_field');
+ assert.equal(h.read(current.editor), 'body', 'The visible matching prefix remains observation-only');
+ });
+ });
+
+ test(`${build}: generic single caret placeholders are empty without losing real breaks or spaces`, async () => {
+ const current = { editor: caret() }, h = contentHarness(build, current);
+ for (const wrappers of [[], ['DIV'], ['P'], ['SPAN'], ['DIV', 'SPAN']]) {
+ current.editor = caret(wrappers);
+ assert.equal(h.read(current.editor), '');
+ const verification = await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: '' });
+ assert.equal(verification.verified, true);
+ const digest = await h.call('field_value_digest', { ref_id: 'ref_42', expected: '' });
+ assert.equal(digest.verified, true); assert.equal(digest.valueLength, 0);
+ assert.equal(digest.valueSha256, createHash('sha256').update('').digest('hex'));
+ if (build === 'chrome') {
+ const before = await h.call('type_ax', { ref_id: 'ref_42', text: 'abc', clear: false });
+ assert.equal(before._expectedValue, 'abc');
+ }
+ }
+ for (const kind of ['two-breaks', 'two-blocks', 'space', 'text-newline', 'hidden', 'embed', 'extra-empty-sibling']) {
+ const editor = caret();
+ if (kind === 'two-breaks') { editor.childNodes.push(element('BR')); editor.innerText = '\n\n'; }
+ if (kind === 'two-blocks') { editor.childNodes = [element('DIV', {}, [element('BR')]), element('DIV', {}, [element('BR')])]; editor.innerText = '\n\n\n'; }
+ if (kind === 'space') { editor.childNodes.unshift(textNode(' ')); editor.innerText = ' \n'; }
+ if (kind === 'text-newline') editor.childNodes = [textNode('\n')];
+ if (kind === 'hidden') editor.firstElementChild.style.visibility = 'hidden';
+ if (kind === 'embed') editor.childNodes = [element('IMG')];
+ if (kind === 'extra-empty-sibling') editor.childNodes.push(element('SPAN'));
+ assert.equal(h.read(editor), editor.innerText, kind);
+ }
+ });
+
+ test(`${build}: DraftJS exact field verification and digest use document blocks`, async t => {
+ const current = { editor: draft([''], { raw: '\n' }) }, h = contentHarness(build, current);
+ for (const lines of [[''], ['a'], ['', 'a'], ['a', ''], ['a', '', 'b'], ['a', '', '', 'b'], [' Leading ', 'line ', ''], ['a\nb'], ['â‘ \u00a0b'], [tweet]]) {
+ await t.test(JSON.stringify(lines), async () => {
+ const expected = lines.join('\n'); current.editor = draft(lines, { raw: 'visual spacing differs', styledUrl: expected === tweet });
+ assert.equal(h.read(current.editor), expected);
+ const verified = await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected });
+ assert.equal(verified.verified, true);
+ assert.equal((await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: expected + ' ' })).verified, false);
+ assert.equal((await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: expected.replace(/\n/g, '\r\n') })).verified, true);
+ const digest = await h.call('field_value_digest', { ref_id: 'ref_42', expected });
+ assert.equal(digest.verified, true); assert.equal(digest.valueLength, expected.length);
+ assert.equal(digest.valueSha256, createHash('sha256').update(expected).digest('hex'));
+ });
+ }
+ current.editor = draft([''], { raw: '\n' });
+ assert.equal(h.read(current.editor), '');
+ current.editor = draft(['a', '', 'b'], { raw: 'a\n\n\nb' });
+ assert.equal((await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: 'a\n\n\nb' })).verified, false,
+ 'Semantic blocks must not borrow Chromium visual newline-expansion tolerance');
+ current.editor = draft([' Existing ', '']);
+ const suffix = 'suffix';
+ const expectedAppend = h.read(current.editor) + suffix;
+ if (build === 'chrome') {
+ const initial = await h.call('type_ax', { ref_id: 'ref_42', text: suffix, clear: false });
+ assert.equal(initial._expectedValue, expectedAppend);
+ }
+ current.editor = draft([' Existing ', suffix]);
+ assert.equal((await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: expectedAppend, appendText: suffix })).verified, true);
+ current.editor = draft(['Existing', suffix]);
+ assert.equal((await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: expectedAppend, appendText: suffix })).verified, false,
+ 'A preserved prefix cannot lose literal spaces');
+ current.editor = draft(['â‘ \u00a0b']);
+ assert.equal((await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: '1 b' })).verified, false,
+ 'AX Unicode and whitespace normalization cannot supply exact write evidence');
+ });
+
+ test(`${build}: unknown DraftJS structures retain the rendered fallback`, async t => {
+ const current = { editor: draft(['body']) }, h = contentHarness(build, current);
+ for (const kind of ['embed', 'hidden-leaf', 'hidden-suffix', 'hidden-attribute', 'aria-hidden', 'noneditable', 'shadow', 'mixed-br', 'generic-text', 'unknown-block', 'depth-budget', 'node-budget', 'leading-sibling', 'wrapped-contents', 'mixed-prosemirror']) {
+ await t.test(kind, async () => {
+ const editor = draft(['body'], { raw: 'rendered fallback' });
+ const body = editor.firstElementChild.firstElementChild.firstElementChild;
+ if (kind === 'embed') body.childNodes.push(element('IMG', { alt: 'attachment' }));
+ if (kind === 'hidden-leaf') body.firstElementChild.style.visibility = 'hidden';
+ if (kind === 'hidden-suffix') { const suffix = leaf(' hidden suffix'); suffix.style.display = 'none'; body.childNodes.push(suffix); }
+ if (kind === 'hidden-attribute') body.firstElementChild.hidden = true;
+ if (kind === 'aria-hidden') body.childNodes.push(element('SPAN', { 'aria-hidden': 'TRUE' }, [leaf('hidden')]));
+ if (kind === 'noneditable') body.childNodes.push(element('SPAN', { contenteditable: 'FALSE' }, [leaf('entity')]));
+ if (kind === 'shadow') body.firstElementChild.shadowRoot = {};
+ if (kind === 'mixed-br') body.childNodes.push(element('BR', { 'data-text': 'true' }));
+ if (kind === 'generic-text') body.childNodes.push(textNode('unstructured'));
+ if (kind === 'unknown-block') editor.firstElementChild.childNodes.push(element('P', {}, [leaf('unexpected')]));
+ if (kind === 'depth-budget') for (let i = 0; i < 34; i++) body.childNodes = [element('SPAN', {}, body.childNodes)];
+ if (kind === 'node-budget') body.childNodes = Array.from({ length: 4096 }, () => leaf('x'));
+ if (kind === 'leading-sibling') editor.childNodes.unshift(element('SPAN', {}, [textNode('before contents')]));
+ if (kind === 'wrapped-contents') {
+ editor.classList = { contains: name => name === 'public-DraftEditor-content' };
+ editor.childNodes = [element('DIV', {}, editor.childNodes)];
+ }
+ if (kind === 'mixed-prosemirror') {
+ editor.classList = { contains: name => ['public-DraftEditor-content', 'ProseMirror'].includes(name) };
+ editor.childNodes = [element('P', {}, [textNode('rendered fallback')])];
+ }
+ assert.equal(h.semantic(editor), null); assert.equal(h.read(editor), 'rendered fallback');
+ current.editor = editor;
+ const verified = await h.call('ax_verify_field_value', { ref_id: 'ref_42', expected: editor.innerText });
+ assert.equal(verified.verified, false, 'Rendered fallback cannot establish exact text evidence');
+ const digest = await h.call('field_value_digest', { ref_id: 'ref_42', expected: editor.innerText });
+ assert.equal(digest.success, false); assert.equal(digest.valueSha256, undefined);
+ for (const action of ['type_ax', 'set_field']) for (const bidi of [false, true]) {
+ const typed = await h.call(action, { ref_id: 'ref_42', text: editor.innerText, clear: true, ...(bidi ? { _bidiPrepare: {} } : {}) });
+ assert.equal(typed.noDispatch, true, `${action}/${bidi}`); assert.equal(typed._expectedValue, undefined);
+ }
+ });
+ }
+ });
+
+ test(`${build}: publication uses the same exact DraftJS body`, () => {
+ const source = fs.readFileSync(`src/${build}/src/agent/agent.js`, 'utf8');
+ const start = source.indexOf('const publicationEditorText = editor => {');
+ const end = source.indexOf('\n const publicationComposerSnapshot', start);
+ const snapshotEnd = source.indexOf('\n const transactionOrderSite', end);
+ const { read, snapshot: capture } = vm.runInNewContext(`(() => {
+ const host = 'x.com', url = 'https://x.com/compose/post', isVisible = () => true;
+ ${functionSource(source, 'readProseMirrorText')}; ${functionSource(source, 'readEmptyCaretText')}; ${functionSource(source, 'isDraftJsEditor')}; ${functionSource(source, 'readDraftJsText')};
+ ${source.slice(start, snapshotEnd)}; return { read: publicationEditorText, snapshot: publicationComposerSnapshot }; })()`);
+ const snapshot = editor => {
+ const root = { querySelectorAll: selector => selector.startsWith('textarea,') ? [editor] : [], querySelector: () => null };
+ editor.parentElement = root; editor.contains = () => false;
+ return capture(root, { complete: true, identity: 'twitter:alice' });
+ };
+ assert.equal(read(draft([''], { raw: '\n' })), '');
+ for (const wrappers of [[], ['DIV', 'SPAN']]) assert.equal(read(caret(wrappers)), '');
+ assert.equal(read(draft([' Leading ', '', 'line ', ''], { raw: 'visual spacing' })), ' Leading \n\nline \n');
+ assert.equal(read(draft([tweet], { styledUrl: true })), tweet);
+ const publishedBody = snapshot(draft([tweet], { styledUrl: true }));
+ assert.equal(publishedBody.complete, true); assert.equal(publishedBody.posts[0].bodyText, tweet);
+ const unknown = draft(['body'], { raw: 'rendered embed' });
+ unknown.firstElementChild.firstElementChild.firstElementChild.childNodes.push(element('IMG'));
+ assert.equal(read(unknown), null, 'Unknown embeds cannot become publication-body evidence');
+ assert.equal(snapshot(unknown).complete, false);
+ const hidden = draft(['body'], { raw: 'body' });
+ const suffix = leaf(' hidden suffix'); suffix.style.display = 'none';
+ hidden.firstElementChild.firstElementChild.firstElementChild.childNodes.push(suffix);
+ assert.equal(read(hidden), null, 'A matching visible prefix cannot hide unverified document text');
+ assert.equal(snapshot(hidden).complete, false);
+ const overBudget = draft(['body'], { raw: 'body' });
+ overBudget.firstElementChild.firstElementChild.firstElementChild.childNodes = Array.from({ length: 4096 }, () => leaf('x'));
+ assert.equal(read(overBudget), null);
+ assert.equal(snapshot(overBudget).complete, false);
+ const mixed = draft(['body'], { raw: 'body' });
+ mixed.classList = { contains: name => ['public-DraftEditor-content', 'ProseMirror'].includes(name) };
+ mixed.childNodes = [element('P', {}, [textNode('body')])];
+ assert.equal(read(mixed), null); assert.equal(snapshot(mixed).complete, false);
+ });
+}
+
+test('Chrome: empty caret appends complete one trusted insertion without text debt', async t => {
+ for (const mode of ['draftjs', 'direct-caret', 'wrapped-caret']) await t.test(mode, async () => {
+ const current = { editor: mode === 'draftjs' ? draft([''], { raw: '\n' }) : caret(mode === 'direct-caret' ? [] : ['DIV', 'SPAN']) }, h = contentHarness('chrome', current);
+ const args = { ref_id: 'ref_42', text: tweet, clear: false };
+ const oldMessage = api.tabs.sendMessage, oldAttach = cdpClient.attach, oldSend = cdpClient.sendCommand;
+ const agent = new Agent({}); const commands = [];
+ agent._lastAxScopes.set(41, { documentToken: 'doc', pageUrl: 'https://x.com/compose/post' });
+ api.tabs.sendMessage = async (_tab, message) => {
+ if (message.action === 'ax_prepare_field_for_trusted_type') return { success: true, contentEditable: true, rect: { x: 10, y: 20, w: 300, h: 90 } };
+ const result = await h.call(message.action, message.params);
+ return { ...result, documentToken: 'doc', refScopeUrl: 'https://x.com/compose/post' };
+ };
+ cdpClient.attach = async () => ({});
+ cdpClient.sendCommand = async (_tab, method, params) => {
+ commands.push(method);
+ if (method === 'Input.insertText') {
+ if (mode === 'draftjs') current.editor = draft([params.text], { styledUrl: true });
+ else typeIntoCaret(current.editor, params.text);
+ }
+ return {};
+ };
+ try {
+ const initial = await h.call('type_ax', args);
+ assert.equal(initial.noDispatch, true); assert.equal(initial._expectedValue, tweet,
+ 'The empty caret BR must not become an append prefix');
+ const typed = await agent._maybeFallbackFieldWithCdp(41, 'type_ax', args, initial);
+ assert.equal(typed.success, true); assert.equal(typed.verified, true);
+ const finalized = await agent._finalizeTextMutationResult(41, 'type_ax', args, typed);
+ assert.equal(finalized.success, true); assert.equal(agent._uncertainTextMutations.has(41), false);
+ assert.equal(commands.filter(method => method === 'Input.insertText').length, 1);
+ assert.equal(h.read(current.editor), tweet);
+ } finally { api.tabs.sendMessage = oldMessage; cdpClient.attach = oldAttach; cdpClient.sendCommand = oldSend; }
+ });
+});
+
+test('Chrome: CDP selector and node readback preserve DraftJS blocks and exact append signatures', async () => {
+ let editor = draft([''], { raw: '\n' });
+ const originalEvaluate = cdpClient.evaluate, originalSend = cdpClient.sendCommand;
+ const evaluate = code => vm.runInNewContext(code, { document: { querySelector: () => editor }, NodeFilter: { SHOW_ELEMENT: 1 } });
+ cdpClient.evaluate = async (_tab, code) => ({ result: { value: evaluate(code) } });
+ cdpClient.sendCommand = async (_tab, method, params) => {
+ if (method === 'DOM.enable' || method === 'Runtime.releaseObject') return {};
+ if (method === 'DOM.resolveNode') return { object: { objectId: 'editor' } };
+ if (method === 'Runtime.callFunctionOn') return { result: { value: vm.runInNewContext(`(${params.functionDeclaration})`)
+ .call(editor, ...(params.arguments || []).map(argument => argument.value)) } };
+ throw new Error(method);
+ };
+ try {
+ for (const target of [{ selector: '#editor' }, { nodeId: 1 }]) {
+ for (const wrappers of [[], ['DIV', 'SPAN']]) {
+ editor = caret(wrappers);
+ const emptySignature = await cdpClient.textEntrySignature(41, target);
+ assert.equal(emptySignature, '0:811c9dc5');
+ assert.equal(await cdpClient.verifyTextEntry(41, { ...target, text: '', clear: true }), true);
+ typeIntoCaret(editor, 'abc');
+ assert.equal(await cdpClient.verifyTextEntry(41, { ...target, text: 'abc', beforeSignature: emptySignature }), true);
+ }
+ editor = draft([''], { raw: '\n' }); const beforeSignature = await cdpClient.textEntrySignature(41, target);
+ assert.equal(beforeSignature, '0:811c9dc5');
+ editor = draft([tweet], { styledUrl: true });
+ assert.equal(await cdpClient.verifyTextEntry(41, { ...target, text: tweet, beforeSignature }), true);
+ editor = draft([' Leading ', '', 'line ', ''], { raw: 'visual spacing' });
+ const expected = ' Leading \n\nline \n';
+ assert.equal(await cdpClient.verifyTextEntry(41, { ...target, text: expected, clear: true }), true);
+ assert.equal(await cdpClient.verifyTextEntry(41, { ...target, text: expected + ' ', clear: true }), null);
+ const signature = await cdpClient.textEntrySignature(41, target);
+ editor = draft([' Leading ', '', 'line ', ' suffix']);
+ assert.equal(await cdpClient.verifyTextEntry(41, { ...target, text: ' suffix', beforeSignature: signature }), true);
+ for (const kind of ['embed', 'hidden-suffix', 'over-budget', 'leading-sibling', 'wrapped-contents', 'mixed-prosemirror']) {
+ editor = draft(['body'], { raw: 'body' });
+ const body = editor.firstElementChild.firstElementChild.firstElementChild;
+ if (kind === 'embed') body.childNodes.push(element('IMG'));
+ if (kind === 'hidden-suffix') { const suffix = leaf(' hidden suffix'); suffix.style.display = 'none'; body.childNodes.push(suffix); }
+ if (kind === 'over-budget') body.childNodes = Array.from({ length: 4096 }, () => leaf('x'));
+ if (kind === 'leading-sibling') editor.childNodes.unshift(element('SPAN', {}, [textNode('before contents')]));
+ if (kind === 'wrapped-contents') {
+ editor.classList = { contains: name => name === 'public-DraftEditor-content' };
+ editor.childNodes = [element('DIV', {}, editor.childNodes)];
+ }
+ if (kind === 'mixed-prosemirror') {
+ editor.classList = { contains: name => ['public-DraftEditor-content', 'ProseMirror'].includes(name) };
+ editor.childNodes = [element('P', {}, [textNode('body')])];
+ }
+ assert.equal(await cdpClient.textEntrySignature(41, target), null, kind);
+ assert.equal(await cdpClient.verifyTextEntry(41, { ...target, text: 'body', clear: true }), null, kind);
+ }
+ }
+ } finally { cdpClient.evaluate = originalEvaluate; cdpClient.sendCommand = originalSend; }
+});
diff --git a/test/page-monitor-dialog.mjs b/test/page-monitor-dialog.mjs
index 22fa154d2..49a4bc41a 100644
--- a/test/page-monitor-dialog.mjs
+++ b/test/page-monitor-dialog.mjs
@@ -111,6 +111,218 @@ for (const build of ['chrome', 'firefox']) {
} finally { await context.close(); }
});
+ await t.test('real X structure: deep editor, dangling dialog label and account avatar are certified together', async () => {
+ const { context, page } = await fixture(browser, build);
+ try {
+ await page.evaluate(() => {
+ const composer = document.getElementById('composer');
+ composer.setAttribute('aria-labelledby', 'modal-header');
+ const avatar = document.createElement('div');
+ avatar.id = 'account-avatar'; avatar.setAttribute('aria-label', 'Emre Sokullu');
+ avatar.style.cssText = 'width:40px;height:40px';
+ avatar.innerHTML = '<div><img alt="Emre Sokullu" style="width:40px;height:40px"></div>';
+ composer.prepend(avatar);
+ let child = document.getElementById('editor');
+ for (let depth = 0; depth < 40; depth++) {
+ const wrapper = document.createElement('div');
+ child.before(wrapper); wrapper.append(child); child = wrapper;
+ }
+ const placeholder = document.createElement('div');
+ placeholder.id = 'draft-placeholder'; placeholder.textContent = 'What’s happening?';
+ composer.append(placeholder);
+ document.getElementById('editor').setAttribute('aria-describedby', placeholder.id);
+ });
+ await page.locator('#editor').focus();
+ const snapshot = await capture(page);
+ assert.equal(snapshot.focusedTargetAvailable, true);
+ assert.match(snapshot.page.pageContent, /visible identity "Emre Sokullu"/);
+ assert.equal((await validate(page, snapshot)).ready, true);
+ assert.equal((await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.postRef })).ready, true);
+ await page.evaluate(() => document.getElementById('counter').textContent = '16');
+ await page.waitForTimeout(180);
+ assert.equal((await validate(page, snapshot)).ready, true);
+ await page.evaluate(() => document.getElementById('account-avatar').setAttribute('aria-label', 'Another account'));
+ await page.waitForTimeout(180);
+ assert.equal((await validate(page, snapshot)).ready, false);
+ assert.equal((await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.postRef })).ready, false);
+ } finally { await context.close(); }
+ });
+
+ for (const change of ['reference-appears', 'duplicate-reference', 'ancestor-limit']) await t.test(`${change}: deep dialog context remains bounded and exact`, async () => {
+ const { context, page } = await fixture(browser, build);
+ try {
+ await page.evaluate(() => document.getElementById('composer').setAttribute('aria-labelledby', 'missing-header'));
+ const snapshot = await capture(page);
+ assert.equal((await validate(page, snapshot)).ready, true);
+ await page.evaluate(change => {
+ if (change === 'ancestor-limit') {
+ let child = document.getElementById('editor');
+ for (let index = 0; index < 70; index++) {
+ const wrapper = document.createElement('div'); child.before(wrapper); wrapper.append(child); child = wrapper;
+ }
+ } else {
+ for (let index = 0; index < (change === 'duplicate-reference' ? 2 : 1); index++) {
+ const label = document.createElement('div'); label.id = 'missing-header'; label.textContent = 'Another destination';
+ document.getElementById('composer').append(label);
+ }
+ }
+ }, change);
+ await page.waitForTimeout(180);
+ assert.equal((await validate(page, snapshot)).ready, false);
+ if (change !== 'reference-appears') {
+ const current = await capture(page);
+ assert.equal((await validate(page, current)).ready, false);
+ }
+ } finally { await context.close(); }
+ });
+
+ for (const labelLength of [160, 2200]) await t.test(`generic account label of ${labelLength} characters is fully observed or stays uncertified`, async () => {
+ const { context, page } = await fixture(browser, build);
+ try {
+ const label = 'Account ' + 'A'.repeat(labelLength);
+ await page.evaluate(label => {
+ const avatar = document.createElement('div'); avatar.setAttribute('aria-label', label);
+ avatar.style.cssText = 'width:40px;height:40px'; document.getElementById('composer').prepend(avatar);
+ }, label);
+ const snapshot = await capture(page);
+ const result = await validate(page, snapshot);
+ if (labelLength === 160) {
+ assert.ok(snapshot.page.pageContent.includes(`visible identity ${JSON.stringify(label)}`));
+ assert.equal(result.ready, true);
+ } else assert.equal(result.ready, false);
+ } finally { await context.close(); }
+ });
+
+ for (const variant of ['image', 'aria-label', 'title', 'labelledby', 'describedby', 'reference-chain', 'reference-cycle', 'reference-order',
+ 'oversized-label', 'evidence-budget', 'duplicate-reference', 'dangling-reference', 'separate-form', 'sidebar',
+ 'editable', 'hidden-visible-child']) await t.test(`${variant}: nested account identities omitted by AX are fully exposed or stay uncertified`, async () => {
+ const { context, page } = await fixture(browser, build);
+ try {
+ const expected = await page.evaluate(variant => {
+ const wrapper = document.createElement('div'); wrapper.id = 'account-wrapper';
+ wrapper.setAttribute('aria-label', 'Account avatar'); wrapper.style.cssText = 'width:200px;height:44px';
+ const label = document.createElement(variant === 'image' ? 'img' : 'span'); label.id = 'nested-account';
+ label.style.cssText = 'display:inline-block;width:28px;height:28px';
+ const expected = variant === 'oversized-label' ? 'Alice ' + 'A'.repeat(600)
+ : variant === 'aria-label' ? 'Alice ' + 'A'.repeat(160) : 'Alice';
+ label.setAttribute(variant === 'image' ? 'alt' : variant === 'title' ? 'title' : 'aria-label', expected);
+ wrapper.append(label); document.getElementById('composer').prepend(wrapper);
+ const addReference = (id, text) => {
+ const reference = document.createElement('div'); reference.id = id; reference.textContent = text;
+ reference.style.cssText = 'position:absolute;left:600px;top:520px;width:180px;height:24px';
+ document.body.append(reference); return reference;
+ };
+ if (['labelledby', 'describedby', 'reference-chain', 'reference-cycle', 'reference-order', 'duplicate-reference', 'dangling-reference'].includes(variant)) {
+ const reference = addReference('account-label', 'Alice');
+ if (variant === 'labelledby') {
+ label.removeAttribute('aria-label'); label.setAttribute('aria-labelledby', reference.id);
+ } else label.setAttribute('aria-describedby', reference.id);
+ if (variant === 'reference-chain' || variant === 'reference-cycle' || variant === 'reference-order') {
+ const destination = addReference('account-destination', variant === 'reference-order' ? 'Alice' : 'Workspace one');
+ reference.setAttribute('aria-describedby', destination.id);
+ if (variant === 'reference-cycle') destination.setAttribute('aria-describedby', reference.id);
+ if (variant === 'reference-order') {
+ reference.textContent = 'Profile'; label.setAttribute('aria-label', 'Avatar');
+ document.getElementById('editor').setAttribute('aria-describedby', reference.id);
+ }
+ } else if (variant === 'duplicate-reference') {
+ addReference('account-label', 'Bob');
+ } else if (variant === 'dangling-reference') {
+ label.removeAttribute('aria-label'); label.setAttribute('aria-labelledby', 'missing-account');
+ label.removeAttribute('aria-describedby'); reference.remove();
+ }
+ } else if (variant === 'evidence-budget') {
+ label.setAttribute('aria-label', 'Alice ' + 'A'.repeat(400));
+ for (let index = 0; index < 9; index++) {
+ const extra = label.cloneNode(); extra.id = `additional-account-${index}`; wrapper.append(extra);
+ }
+ } else if (variant === 'separate-form' || variant === 'sidebar') {
+ const excluded = document.createElement(variant === 'separate-form' ? 'form' : 'aside');
+ wrapper.append(excluded); excluded.append(label);
+ } else if (variant === 'editable') {
+ label.setAttribute('contenteditable', 'true'); label.textContent = 'Private draft';
+ } else if (variant === 'hidden-visible-child') {
+ label.style.visibility = 'hidden';
+ label.innerHTML = '<span style="visibility:visible">Alice</span>';
+ }
+ // Exercise complete public evidence independently of whether the
+ // regular AX formatter happens to include an image/generic label.
+ const omitted = [...wrapper.querySelectorAll('*'), wrapper,
+ ...document.querySelectorAll('#account-label,#account-destination')];
+ const omittedRefs = new Set(omitted.map(node => __wb_ax_ref(node)));
+ const originalTree = window.__generateAccessibilityTree;
+ window.__generateAccessibilityTree = (...args) => {
+ const tree = originalTree(...args);
+ return { ...tree, pageContent: tree.pageContent.split('\n')
+ .filter(line => ![...omittedRefs].some(ref => line.includes(`[${ref}]`))).join('\n') };
+ };
+ return expected;
+ }, variant);
+ const snapshot = await capture(page);
+ const editor = await validate(page, snapshot);
+ const post = await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.postRef });
+ if (['image', 'aria-label', 'title', 'labelledby', 'describedby', 'reference-chain', 'reference-cycle', 'reference-order'].includes(variant)) {
+ assert.equal(editor.ready, true, JSON.stringify(editor));
+ assert.equal(post.ready, true, JSON.stringify(post));
+ const evidence = snapshot.page.pageContent.split('[CURRENT VISIBLE ACTION IDENTITY]')[1];
+ assert.ok(evidence.includes(`visible identity ${JSON.stringify(expected)}`), evidence);
+ assert.ok(evidence.includes('visible identity "Account avatar"'), evidence);
+ if (variant === 'reference-chain' || variant === 'reference-cycle')
+ assert.ok(evidence.includes('visible identity "Workspace one"'), evidence);
+ await page.evaluate(variant => {
+ const node = document.getElementById(variant === 'reference-chain' || variant === 'reference-cycle' || variant === 'reference-order'
+ ? 'account-destination' : variant === 'labelledby' || variant === 'describedby' ? 'account-label' : 'nested-account');
+ if (node.id !== 'nested-account') node.textContent = 'Bob';
+ else node.setAttribute(variant === 'image' ? 'alt' : variant === 'title' ? 'title' : 'aria-label', 'Bob');
+ }, variant);
+ await page.waitForTimeout(180);
+ assert.equal((await validate(page, snapshot)).ready, false);
+ assert.equal((await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.postRef })).ready, false);
+ } else {
+ assert.equal(editor.ready, false, JSON.stringify(editor));
+ assert.equal(post.ready, false, JSON.stringify(post));
+ }
+ } finally { await context.close(); }
+ });
+
+ for (const placement of ['direct-owner', 'owned-form', 'direct-form']) await t.test(`${placement}: plain destination text is fully observed without publishing editable values as identity`, async () => {
+ const { context, page } = await fixture(browser, build);
+ try {
+ await page.evaluate(placement => {
+ const owner = document.getElementById('composer');
+ const editor = document.getElementById('editor'); editor.textContent = 'Private draft';
+ if (placement === 'direct-owner') owner.prepend(document.createTextNode('Replying to Alice'));
+ else {
+ const form = document.createElement('form');
+ if (placement === 'direct-form') {
+ form.append(document.createTextNode('Replying to Alice'), document.getElementById('post'));
+ owner.append(form);
+ } else {
+ const label = document.createElement('span'); label.textContent = 'Replying to Alice';
+ editor.before(form); form.append(label, editor, document.getElementById('post'));
+ }
+ }
+ }, placement);
+ const snapshot = await capture(page);
+ // A separate form belongs to its own Post action, so an editor
+ // outside it remains conservative while the Post proof binds its text.
+ if (placement !== 'direct-form') assert.equal((await validate(page, snapshot)).ready, true);
+ assert.equal((await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.postRef })).ready, true);
+ const identities = snapshot.page.pageContent.split('[CURRENT VISIBLE ACTION IDENTITY]')[1];
+ assert.match(identities, /Replying to Alice/);
+ assert.ok(!identities.includes('Private draft'), 'Additional identity evidence must exclude the editable payload');
+ await page.evaluate(placement => {
+ const owner = document.getElementById('composer');
+ if (placement === 'direct-owner') owner.firstChild.data = 'Replying to Bob';
+ else if (placement === 'direct-form') owner.querySelector('form').firstChild.data = 'Replying to Bob';
+ else owner.querySelector('form > span').textContent = 'Replying to Bob';
+ }, placement);
+ await page.waitForTimeout(180);
+ assert.equal((await validate(page, snapshot)).ready, false);
+ assert.equal((await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.postRef })).ready, false);
+ } finally { await context.close(); }
+ });
+
for (const variant of ['control-display', 'control-visibility', 'reference-display', 'reference-visibility',
'readonly-inside-display', 'readonly-inside-visibility', 'readonly-reference-display', 'readonly-reference-visibility']) {
await t.test(`${variant}: rendered audience changes invalidate an earlier Post certificate despite identical textContent`, async () => {
@@ -188,12 +400,31 @@ for (const build of ['chrome', 'firefox']) {
} finally { await context.close(); }
});
- for (const kind of ['nested-text', 'generic-label', 'display-contents', 'open-shadow', 'separate-form', 'sidebar-identity', 'nav-control-identity', 'nav-control-shadow']) await t.test(`${kind}: uncovered destination identity stays uncertified`, async () => {
+ for (const kind of ['nested-text', 'generic-label', 'display-contents', 'display-contents-label', 'hidden-label-visible-child', 'label-with-editor', 'label-with-shadow', 'label-with-excluded-control', 'open-shadow', 'separate-form', 'labelled-separate-form', 'labelled-sidebar-control', 'separate-article', 'sidebar-identity', 'nav-control-identity', 'nav-control-shadow']) await t.test(`${kind}: destination identity is completely observed or stays uncertified`, async () => {
const { context, page } = await fixture(browser, build);
try {
await page.evaluate(kind => {
const destination = document.createElement('p'); destination.id = 'destination';
- if (kind === 'nested-text' || kind === 'display-contents') {
+ if (kind === 'display-contents-label' || kind === 'hidden-label-visible-child') {
+ destination.setAttribute('aria-label', 'Replying to Alice');
+ destination.style.cssText = kind === 'display-contents-label' ? 'display:contents' : 'visibility:hidden';
+ destination.innerHTML = '<span style="visibility:visible">Replying to Alice</span>';
+ } else if (kind === 'label-with-editor') {
+ destination.setAttribute('aria-label', 'Replying to Alice');
+ destination.innerHTML = '<div contenteditable="true">Existing message</div>';
+ } else if (kind === 'label-with-shadow') {
+ destination.setAttribute('aria-label', 'Replying to Alice');
+ destination.attachShadow({ mode: 'open' }).innerHTML = '<span>Replying to Alice</span>';
+ } else if (kind === 'label-with-excluded-control') {
+ destination.setAttribute('aria-label', 'Replying to Alice');
+ destination.innerHTML = '<aside><input type="checkbox"></aside>';
+ } else if (kind === 'labelled-separate-form') {
+ destination.innerHTML = '<form><button aria-label="Replying to Alice" type="button"></button></form>';
+ } else if (kind === 'labelled-sidebar-control') {
+ destination.innerHTML = '<aside><button aria-label="Replying to Alice" type="button"></button></aside>';
+ } else if (kind === 'separate-article') {
+ destination.innerHTML = '<article><span>Replying to Alice</span></article>';
+ } else if (kind === 'nested-text' || kind === 'display-contents') {
destination.innerHTML = '<span>Replying to Alice</span>';
if (kind === 'display-contents') destination.style.display = 'contents';
} else if (kind === 'open-shadow') {
@@ -219,8 +450,15 @@ for (const build of ['chrome', 'firefox']) {
await page.waitForTimeout(180);
const snapshot = await capture(page);
const original = await validate(page, snapshot);
- assert.equal(original.ready, false);
- assert.equal(original.uncertified, true);
+ if (['generic-label', 'nested-text', 'display-contents'].includes(kind)) {
+ assert.equal(original.ready, true);
+ assert.match(snapshot.page.pageContent, /visible identity "Replying to Alice"/);
+ } else {
+ assert.equal(original.ready, false);
+ if (kind === 'display-contents-label' || kind === 'hidden-label-visible-child')
+ assert.equal(original.reason, 'target_uncovered', 'A private footprint without complete public identity evidence cannot certify the target');
+ else assert.equal(original.uncertified, true);
+ }
await page.evaluate(kind => {
const destination = document.getElementById('destination');
if (kind === 'nested-text' || kind === 'display-contents') destination.firstChild.textContent = 'Replying to Bob';
diff --git a/test/page-monitor-ui.mjs b/test/page-monitor-ui.mjs
index 37d7104b4..d9535d2d8 100644
--- a/test/page-monitor-ui.mjs
+++ b/test/page-monitor-ui.mjs
@@ -233,6 +233,9 @@ test('Chrome controlled-field trusted typing survives its focus-created formatti
window._fieldMeta = el => ({ tag: 'div', contentEditable: true, ariaLabel: el.getAttribute('aria-label') });
window._editableTextValue = el => el.innerText.replace(/\n$/, '');
window.readProseMirrorText = () => null;
+ window.isDraftJsEditor = () => false;
+ window.readDraftJsText = () => null;
+ window.readEmptyCaretText = () => null;
window._stableFieldSelector = el => '#' + el.id;
window._setFieldValueMatches = (actual, prefix, text, clear) => actual === (clear ? '' : prefix) + text;
});
diff --git a/test/run.js b/test/run.js
index 835500891..dd2e2935b 100644
--- a/test/run.js
+++ b/test/run.js
@@ -81293,7 +81293,7 @@ test('set_field waits for reconciliation and verifies the complete value', () =>
const readbackIndex = branch.search(/(?:const|let) actual = el\.isContentEditable/);
assert.ok(settleIndex >= 0 && readbackIndex > settleIndex, `${label}: verification must happen after controlled-input reconciliation`);
assert.match(branch, /(?:const|let) actual = el\.isContentEditable \? _editableTextValue\(el\)/, `${label}: rich-editor verification must use the editor text reader`);
- assert.match(branch, /_setFieldValueMatches\(actual, prevValue, text, clear, el\.isContentEditable, readProseMirrorText\(el\) !== null\)/, `${label}: visual newline normalization must remain limited to contenteditables without semantic paragraph readback`);
+ assert.match(branch, /_setFieldValueMatches\(actual, prevValue, text, clear, el\.isContentEditable, \(readProseMirrorText\(el\) !== null \|\| readDraftJsText\(el\) !== null \|\| readEmptyCaretText\(el\) !== null\)\)/, `${label}: visual newline normalization must remain limited to contenteditables without semantic document readback`);
assert.match(branch, /await new Promise\(resolve => setTimeout\(resolve, SET_FIELD_VERIFY_DELAY_MS\)\);\s*if \(actionDeadlineExpired\(\)\) return deadlineFailure\(\);/, `${label}: set_field can continue after its verification wait expires`);
assert.match(branch, /if \(usesNativeSubmit\)[\s\S]*if \(actionDeadlineExpired\(\)\) return deadlineFailure\(\);\s*submissionDispatched = true;\s*try \{\s*form\.requestSubmit\(\)/, `${label}: native set_field submission is not guarded at the mutation boundary`);
assert.match(branch, /await new Promise\(r => setTimeout\(r, 80\)\);\s*if \(actionDeadlineExpired\(\)\) return deadlineFailure\(\);[\s\S]*await new Promise\(r => setTimeout\(r, 30\)\);\s*if \(actionDeadlineExpired\(\)\) return deadlineFailure\(\);[\s\S]*if \(actionDeadlineExpired\(\)\) return deadlineFailure\(\);\s*const enterResult = dispatchKeySequence\('Enter', 13, true\);\s*submissionDispatched = enterResult\.dispatched;\s*if \(!enterResult\.completedWithinDeadline\)/, `${label}: page-owned set_field submission can resume after its deadline`);