Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix: preserve framework-owned rich-text editors
Barack Sokulluf556affbee09
diff --git a/docs/rich-text-input.md b/docs/rich-text-input.mdnew file mode 100644index 000000000..c7cdb664c--- /dev/null+++ b/docs/rich-text-input.md@@ -0,0 +1,41 @@+# Rich-text input++DraftJS is a React rich-text editor. Its application document owns the rendered+text nodes, so inserting an HTML wrapper or replacing `textContent` can corrupt+the editor or show the same text twice while the saved document differs.++The October 11 regression came from `50c8d73ad`, which moved `type_ax` and+`set_field` from trusted input to generic HTML insertion for editors that were+not recognized as ProseMirror. DraftJS reached that path. Its old test fixture+rebuilt the DOM on input, masking the conflict with React-owned document nodes.++WebBrain identifies managed editors by their editor markup, independently of the+site: DraftJS, ProseMirror, Slate, Lexical, Quill, CKEditor, TinyMCE and CodeMirror.+These editors bypass generic HTML insertion and DOM replacement. Chrome uses+ref-bound browser input; iframe preparation and verification stay in the original+frame. Legacy iframe setters refuse managed editors instead of changing their DOM.++DraftJS multiline edits use its public plain-text paste handling. A single paste+lets the editor create its own document blocks, preserving blank lines and literal+markup without sending Enter or changing the system clipboard. Both replacement+and append require exact full-document readback in the original element and scope.+Cancelled, ignored, changed or unavailable results never trigger a second write.+Focus preparation and the paste use the existing task-bound monitor fences;+the internal AX paste route shares `type_ax` input ownership.++Firefox trusted automation uses the same strict DraftJS and ProseMirror document+readers before and after input, including empty caret placeholders and paragraph+boundaries. Without a supported transport, WebBrain leaves the draft intact and+explains how to enable trusted automation.++Regression tests use the actual React/DraftJS libraries and compare application+EditorState, rendered document blocks and saved POST data. They cover replacement,+append, clear, multiline text, Unicode, literal markup, iframe ownership and lost+responses. Additional fixtures check that managed editors cannot reach legacy DOM+setters and that ordinary editors preserve their exact text and formatting.++Run the focused suite with:++```sh+node --test test/rich-text-frameworks.mjs test/firefox-rich-text-readback.mjs test/draftjs-text.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/contenteditable-beforeinput.mjs+```diff --git a/firefox-companion/session.mjs b/firefox-companion/session.mjsindex ad1afe80c..3393d65e0 100644--- a/firefox-companion/session.mjs+++ b/firefox-companion/session.mjs@@ -2,6 +2,86 @@ import { mkdtemp, writeFile, rm } from 'node:fs/promises';import { tmpdir } from 'node:os';import { join, basename } from 'node:path';+// Keep these document readers equivalent to the content/CDP readers. A rendered+// prefix cannot certify an unsupported DraftJS document, and paragraph spacing+// in innerText is not the document's authored line breaks.+function readProseMirrorText(el) {+ if (!el?.isContentEditable || !el.classList?.contains('ProseMirror')) return null;+ const read = node => {+ if (node.nodeType === 3) return node.nodeValue || '';+ if (node.nodeType !== 1) return '';+ if (node.tagName === 'BR') return node.classList?.contains('ProseMirror-trailingBreak') ? '' : '\n';+ return Array.from(node.childNodes).map(read).join('');+ };+ const children = Array.from(el.childNodes);+ if (!children.every(node => node.nodeType === 1 && node.tagName === 'P')) return null;+ return children.map(read).join('\n');+}++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;+ 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 readRichTextFieldValue(el, semanticKind = '') {+ if (!el?.isConnected) return null;+ const draftJs = semanticKind === 'draftjs' || isDraftJsEditor(el);+ const semantic = draftJs ? readDraftJsText(el) : readProseMirrorText(el);+ if ((draftJs || semanticKind === 'prosemirror') && semantic === null) return null;+ return semantic !== null ? semantic : (el.isContentEditable ? el.innerText : el.value);+}++const FIELD_TEXT_READBACK_SOURCE = [readProseMirrorText, isDraftJsEditor, readDraftJsText, readRichTextFieldValue]+ .map(fn => fn.toString()).join('\n');+const sipMask = (1n << 64n) - 1n;const sipRotate = (value, bits) => ((value << BigInt(bits)) | (value >> BigInt(64 - bits))) & sipMask;function pageActionSignature(secret, data) {@@ -281,7 +361,7 @@ export class BidiSession {const match = await this.locate(payload.token, payload.url, run.context);assertLive();let nativeSequence = 0;- const markNativeDispatch = async (kind, { rebindFocus = false } = {}) => {+ const markNativeDispatch = async (kind, { rebindFocus = false, domDispatch = false } = {}) => {assertLive();const guard = payload.pageFeedbackGuard;if (!guard) return; // Compatibility with clients without page monitoring.@@ -290,6 +370,9 @@ export class BidiSession {const error = new Error('Page changed during native preparation; no further input sent');error.code = 'page_feedback_pending'; throw error;}+ // A public framework event uses the existing prepared DOM phase gate.+ // It cannot consume a trusted-event marker or advance its native sequence.+ if (domDispatch) return;const marker = createNativeActionMarker(guard, kind, ++nativeSequence);const checked = await this.call(match, `(el, marker, kind, action) => {if (!el.isConnected) return false;@@ -404,7 +487,20 @@ export class BidiSession {if (checkable && (!['checkbox', 'radio'].includes(checkable.inputType) || typeof checkable.desiredChecked !== 'boolean')) {throw new Error('Invalid checkable target metadata');}- const before = typing ? await this.call(match, '(el) => el.isContentEditable ? el.innerText : el.value') : null;+ const before = typing ? await this.call(match, `(el) => {+ ${FIELD_TEXT_READBACK_SOURCE}+ const value = readRichTextFieldValue(el);+ if (value === null) return null;+ const semanticKind = isDraftJsEditor(el) ? 'draftjs'+ : readProseMirrorText(el) !== null ? 'prosemirror' : '';+ return { value, semanticKind };+ }`) : null;+ if (typing && (before.result?.type === 'null' || before.result?.value === null)) {+ throw new Error('The rich-text editor structure cannot establish its exact document text; no text sent');+ }+ const beforeReadback = typing ? unpackRemoteObjectValue(before.result?.type ? before.result : before.result?.value) : null;+ const beforeSnapshot = beforeReadback && typeof beforeReadback === 'object' && Object.hasOwn(beforeReadback, 'value')+ ? beforeReadback : { value: before?.result?.value, semanticKind: '' };const assertFocus = async () => {assertLive();const focused = await this.call(match, '(el) => el.isConnected && !el.disabled && el.getRootNode().activeElement === el');@@ -493,12 +589,22 @@ export class BidiSession {const platform = await this.call(match, '() => navigator.platform');await press('a', /Mac/.test(platform.result?.value || '') ? '\uE03D' : '\uE009');await press('\uE003');+ if (beforeSnapshot.semanticKind === 'draftjs') {+ const cleared = await this.call(match, `(el) => {+ ${FIELD_TEXT_READBACK_SOURCE}+ return readRichTextFieldValue(el, 'draftjs') === '';+ }`);+ if (cleared.result?.value !== true) throw new Error('DraftJS clearing did not establish an empty document; no further text sent');+ }} else {const positioned = await this.call(match, `(el) => {if (!el.isConnected || el.getRootNode().activeElement !== el) return false;if (el.isContentEditable) {const selection = getSelection(); const range = document.createRange();- range.selectNodeContents(el); range.collapse(false);+ let container = el;+ while (container.lastChild?.nodeType === 1 && container.lastChild.isContentEditable+ && container.lastChild.nodeName !== 'BR') container = container.lastChild;+ range.selectNodeContents(container); range.collapse(false);selection.removeAllRanges(); selection.addRange(range);} else if (typeof el.setSelectionRange === 'function') {const end = el.value.length; el.setSelectionRange(end, end);@@ -507,24 +613,76 @@ export class BidiSession {}`);if (positioned.result?.value !== true) throw new Error('Could not position caret for append; no text sent');}- // One character per dispatch bounds work after Stop and catches focus changes between keys.- for (const char of payload.text) {- if (char === '\n' || char === '\r') {- await assertFocus();- // Enter is a submit shortcut on many editors, even with Shift. Insert a literal- // newline through the editing command instead; never synthesize a submit key.- const marker = await markNativeDispatch('input');- let inserted;- try {- dispatch.started = true;- inserted = await this.call(match, `(el, text) => {- if (!el.isConnected || el.getRootNode().activeElement !== el) return false;- return document.execCommand('insertText', false, text);- }`, [{ type: 'string', value: char }]);- } finally { await clearNativeDispatch(marker); }- if (inserted.result?.value !== true) throw new Error('Editor rejected literal newline insertion');- assertLive();- } else await press(char);+ if (beforeSnapshot.semanticKind === 'draftjs' && /[\r\n]/.test(payload.text)) {+ // DraftJS treats literal LF editing commands inconsistently. Its public paste+ // handler accepts a whole plain-text document without using a submit shortcut.+ const positioned = await this.call(match, `(el, clear) => {+ if (!el.isConnected || el.getRootNode().activeElement !== el) return false;+ const leaves = el.querySelectorAll('[data-text="true"]');+ const leaf = leaves[clear ? 0 : leaves.length - 1];+ if (!leaf) return false;+ const range = el.ownerDocument.createRange();+ if (leaf.nodeName === 'BR') range.setStartBefore(leaf);+ else {+ const text = clear ? leaf.firstChild : leaf.lastChild;+ if (text?.nodeType !== 3) return false;+ range.setStart(text, clear ? 0 : text.nodeValue.length);+ }+ range.collapse(true);+ const selection = el.ownerDocument.defaultView.getSelection();+ selection.removeAllRanges(); selection.addRange(range);+ return true;+ }`, [{ type: 'boolean', value: clear }]);+ if (positioned.result?.value !== true) throw new Error('Could not position the DraftJS caret; no further text sent');+ // Let the browser's selectionchange reach the framework before the paste.+ await new Promise(resolve => setTimeout(resolve, 30));+ await assertFocus();+ const marker = await markNativeDispatch('input', { domDispatch: true });+ try {+ dispatch.started = true;+ const pasted = await this.call(match, `(el, text, guardJson) => {+ ${FIELD_TEXT_READBACK_SOURCE}+ if (!el.isConnected || el.getRootNode().activeElement !== el || readDraftJsText(el) === null) return false;+ const view = el.ownerDocument.defaultView;+ const data = new view.DataTransfer(); data.setData('text/plain', text);+ const event = new view.ClipboardEvent('paste', { bubbles: true, cancelable: true, composed: true, clipboardData: data });+ // Firefox drops the constructor's clipboardData. Preserve the public+ // plain-text payload without reading or writing the OS clipboard.+ if (event.clipboardData?.getData('text/plain') !== text)+ Object.defineProperty(event, 'clipboardData', { value: data });+ const guard = JSON.parse(guardJson);+ if (guard && !el.dispatchEvent(new view.CustomEvent('webbrain-agent-dom-dispatch', {+ detail: JSON.stringify({ ...guard, dispatchPhase: 'input' }), bubbles: true, composed: true, cancelable: true,+ }))) return false;+ el.dispatchEvent(event);+ // Cancellation can mean the framework consumed the paste. Only the+ // settled exact document readback below establishes its outcome.+ return true;+ }`, [{ type: 'string', value: payload.text.replace(/\r\n?/g, '\n') },+ { type: 'string', value: JSON.stringify(payload.pageFeedbackGuard || null) }]);+ if (pasted.result?.value !== true) throw new Error('DraftJS paste dispatch could not be established; inspect before another write');+ } finally { await clearNativeDispatch(marker); }+ assertLive();+ } else {+ // One character per dispatch bounds work after Stop and catches focus changes between keys.+ for (const char of payload.text.replace(/\r\n?/g, '\n')) {+ if (char === '\n' || char === '\r') {+ await assertFocus();+ // Enter is a submit shortcut on many editors, even with Shift. Insert a literal+ // newline through the editing command instead; never synthesize a submit key.+ const marker = await markNativeDispatch('input');+ let inserted;+ try {+ dispatch.started = true;+ inserted = await this.call(match, `(el, text) => {+ if (!el.isConnected || el.getRootNode().activeElement !== el) return false;+ return document.execCommand('insertText', false, text);+ }`, [{ type: 'string', value: char }]);+ } finally { await clearNativeDispatch(marker); }+ if (inserted.result?.value !== true) throw new Error('Editor rejected literal newline insertion');+ assertLive();+ } else await press(char);+ }}} else if (action === 'key') {const keys = { Enter: '\uE007', Tab: '\uE004', Escape: '\uE00C', Backspace: '\uE003', Delete: '\uE017', ArrowLeft: '\uE012', ArrowRight: '\uE014', ArrowUp: '\uE013', ArrowDown: '\uE015', Home: '\uE011', End: '\uE010' };@@ -537,8 +695,15 @@ export class BidiSession {if (typing) {await new Promise(resolve => setTimeout(resolve, 100));assertLive();- const expected = clear ? payload.text : String(before.result?.value || '') + payload.text;- const verified = await this.call(match, '(el, expected) => el.isConnected && (el.isContentEditable ? el.innerText : el.value) === expected', [{ type: 'string', value: expected }]);+ const expected = clear ? payload.text : String(beforeSnapshot.value || '') + payload.text;+ const verified = await this.call(match, `(el, expected, semanticKind) => {+ ${FIELD_TEXT_READBACK_SOURCE}+ const actual = readRichTextFieldValue(el, semanticKind);+ if (actual === null) return false;+ if (!el.isContentEditable) return actual === expected;+ const normalize = value => String(value).replace(/\\r\\n?/g, '\\n');+ return normalize(actual) === normalize(expected);+ }`, [{ type: 'string', value: expected }, { type: 'string', value: beforeSnapshot.semanticKind || '' }]);if (verified.result?.value !== true) return { success: false, dispatched: true, verified: false, submitted: false, outcomeUnknown: true, retryable: false, error: 'Trusted typing did not match the requested value; inspect before another write.' };if (action === 'field' && payload.submit === true) {assertLive();diff --git a/package-lock.json b/package-lock.jsonindex 815b1b99b..e31312f6f 100644--- a/package-lock.json+++ b/package-lock.json@@ -10,7 +10,11 @@"license": "GPL-3.0-or-later","devDependencies": {"c8": "^12.0.0",+ "draft-js": "0.11.7",+ "immutable": "3.8.4","playwright": "^1.48.0",+ "react": "18.2.0",+ "react-dom": "18.2.0","tldts": "7.4.10"}},@@ -95,6 +99,13 @@"url": "https://github.com/chalk/ansi-styles?sponsor=1"}},+ "node_modules/asap": {+ "version": "2.0.6",+ "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",+ "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==",+ "dev": true,+ "license": "MIT"+ },"node_modules/balanced-match": {"version": "4.0.4","resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz",@@ -192,6 +203,31 @@"dev": true,"license": "MIT"},+ "node_modules/core-js": {+ "version": "3.50.0",+ "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.50.0.tgz",+ "integrity": "sha512-BRWgOLKkFeCgRudR6zrs8p9XJZcE14grzKMMssoYrk6krtuEZ7MTKPIY5RzOnqsEKIR9kst7wNzphttraT+Yqw==",+ "dev": true,+ "hasInstallScript": true,+ "license": "MIT",+ "engines": {+ "node": "*"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/core-js"+ }+ },+ "node_modules/cross-fetch": {+ "version": "3.2.0",+ "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.2.0.tgz",+ "integrity": "sha512-Q+xVJLoGOeIMXZmbUK4HYk+69cQH6LudR0Vu/pRm2YlU/hDV9CiS0gKUMaWY5f2NeUH9C1nV3bsTlCo0FsTV1Q==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "node-fetch": "^2.7.0"+ }+ },"node_modules/cross-spawn": {"version": "7.0.6","resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",@@ -207,6 +243,22 @@"node": ">= 8"}},+ "node_modules/draft-js": {+ "version": "0.11.7",+ "resolved": "https://registry.npmjs.org/draft-js/-/draft-js-0.11.7.tgz",+ "integrity": "sha512-ne7yFfN4sEL82QPQEn80xnADR8/Q6ALVworbC5UOSzOvjffmYfFsr3xSZtxbIirti14R7Y33EZC5rivpLgIbsg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "fbjs": "^2.0.0",+ "immutable": "~3.7.4",+ "object-assign": "^4.1.1"+ },+ "peerDependencies": {+ "react": ">=0.14.0",+ "react-dom": ">=0.14.0"+ }+ },"node_modules/emoji-regex": {"version": "10.6.0","resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.6.0.tgz",@@ -224,6 +276,30 @@"node": ">=6"}},+ "node_modules/fbjs": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-2.0.0.tgz",+ "integrity": "sha512-8XA8ny9ifxrAWlyhAbexXcs3rRMtxWcs3M0lctLfB49jRDHiaxj+Mo0XxbwE7nKZYzgCFoq64FS+WFd4IycPPQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "core-js": "^3.6.4",+ "cross-fetch": "^3.0.4",+ "fbjs-css-vars": "^1.0.0",+ "loose-envify": "^1.0.0",+ "object-assign": "^4.1.0",+ "promise": "^7.1.1",+ "setimmediate": "^1.0.5",+ "ua-parser-js": "^0.7.18"+ }+ },+ "node_modules/fbjs-css-vars": {+ "version": "1.0.2",+ "resolved": "https://registry.npmjs.org/fbjs-css-vars/-/fbjs-css-vars-1.0.2.tgz",+ "integrity": "sha512-b2XGFAFdWZWg0phtAWLHCk836A1Xann+I+Dgd3Gk64MHKZO44FfoD1KxyvbSh0qZsIoXQGGlVztIY+oitJPpRQ==",+ "dev": true,+ "license": "MIT"+ },"node_modules/find-up": {"version": "5.0.0","resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz",@@ -331,6 +407,16 @@"dev": true,"license": "MIT"},+ "node_modules/immutable": {+ "version": "3.8.4",+ "resolved": "https://registry.npmjs.org/immutable/-/immutable-3.8.4.tgz",+ "integrity": "sha512-ZQv17KolYrYmsDoDB8N67zhIKsNi9mGYlk96y/yuxyAqJB2hLzSGSM7k/sB0/ZvO4kx27U9+fBeD/XlLGh/uXQ==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=0.10.0"+ }+ },"node_modules/isexe": {"version": "2.0.0","resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",@@ -377,6 +463,13 @@"node": ">=8"}},+ "node_modules/js-tokens": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",+ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",+ "dev": true,+ "license": "MIT"+ },"node_modules/locate-path": {"version": "6.0.0","resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",@@ -393,6 +486,19 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/loose-envify": {+ "version": "1.4.0",+ "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",+ "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "js-tokens": "^3.0.0 || ^4.0.0"+ },+ "bin": {+ "loose-envify": "cli.js"+ }+ },"node_modules/lru-cache": {"version": "11.5.3","resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.3.tgz",@@ -445,6 +551,37 @@"node": ">=16 || 14 >=14.17"}},+ "node_modules/node-fetch": {+ "version": "2.7.0",+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",+ "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "whatwg-url": "^5.0.0"+ },+ "engines": {+ "node": "4.x || >=6.0.0"+ },+ "peerDependencies": {+ "encoding": "^0.1.0"+ },+ "peerDependenciesMeta": {+ "encoding": {+ "optional": true+ }+ }+ },+ "node_modules/object-assign": {+ "version": "4.1.1",+ "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",+ "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=0.10.0"+ }+ },"node_modules/p-limit": {"version": "3.1.0","resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz",@@ -546,6 +683,53 @@"node": ">=18"}},+ "node_modules/promise": {+ "version": "7.3.1",+ "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",+ "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "asap": "~2.0.3"+ }+ },+ "node_modules/react": {+ "version": "18.2.0",+ "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",+ "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "loose-envify": "^1.1.0"+ },+ "engines": {+ "node": ">=0.10.0"+ }+ },+ "node_modules/react-dom": {+ "version": "18.2.0",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",+ "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.0"+ },+ "peerDependencies": {+ "react": "^18.2.0"+ }+ },+ "node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/semver": {"version": "7.8.5","resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",@@ -559,6 +743,13 @@"node": ">=10"}},+ "node_modules/setimmediate": {+ "version": "1.0.5",+ "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",+ "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==",+ "dev": true,+ "license": "MIT"+ },"node_modules/shebang-command": {"version": "2.0.0","resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",@@ -676,6 +867,40 @@"dev": true,"license": "MIT"},+ "node_modules/tr46": {+ "version": "0.0.3",+ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",+ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/ua-parser-js": {+ "version": "0.7.41",+ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.41.tgz",+ "integrity": "sha512-O3oYyCMPYgNNHuO7Jjk3uacJWZF8loBgwrfd/5LE/HyZ3lUIOdniQ7DNXJcIgZbwioZxk0fLfI4EVnetdiX5jg==",+ "dev": true,+ "funding": [+ {+ "type": "opencollective",+ "url": "https://opencollective.com/ua-parser-js"+ },+ {+ "type": "paypal",+ "url": "https://paypal.me/faisalman"+ },+ {+ "type": "github",+ "url": "https://github.com/sponsors/faisalman"+ }+ ],+ "license": "MIT",+ "bin": {+ "ua-parser-js": "script/cli.js"+ },+ "engines": {+ "node": "*"+ }+ },"node_modules/v8-to-istanbul": {"version": "9.3.0","resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz",@@ -691,6 +916,24 @@"node": ">=10.12.0"}},+ "node_modules/webidl-conversions": {+ "version": "3.0.1",+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",+ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",+ "dev": true,+ "license": "BSD-2-Clause"+ },+ "node_modules/whatwg-url": {+ "version": "5.0.0",+ "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",+ "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "tr46": "~0.0.3",+ "webidl-conversions": "^3.0.0"+ }+ },"node_modules/which": {"version": "2.0.2","resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",diff --git a/package.json b/package.jsonindex e1aed9086..53585ca41 100644--- a/package.json+++ b/package.json@@ -55,8 +55,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-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/cdp-clear-receipt.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.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/draftjs-native-editor.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/chat-steering.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.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/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/chat-steering-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs",- "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/draftjs-text.mjs test/draftjs-native-editor.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.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/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.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-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/cdp-clear-receipt.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.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/rich-text-frameworks.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/chat-steering.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.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/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/chat-steering-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs",+ "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.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/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.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",@@ -87,7 +87,7 @@"test:chat-draft-recovery": "node --test test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs && node test/quality/native-chat-presubmit-mv3.mjs","test:upload-owner": "node --test test/page-monitor-upload-owner.mjs","test:shard:quick": "npm run test:cms && npm run test:markdown && npm run test:generative-media && npm run test:systemone && npm run test:systemone:fast && node --test test/browser-dialogs.mjs test/capsolver-cloud-broker.mjs test/captcha-providers.mjs test/captcha-weighted-fallback.mjs test/captcha-hcaptcha-providers.mjs test/captcha-native-providers.mjs test/captcha-runtime-policy.mjs test/captcha-callback-bridge.mjs test/captcha-bridge-registration.mjs test/captcha-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.mjs test/feedback-traces.mjs && npm run test:firefox-bidi && npm run test:billing-notice && npm run test:compass-quota && npm run test:provider-limits && npm run test:provider-catalog && npm run test:provider-instances:ui && npm run test:openrouter-capabilities && npm run test:anthropic && npm run test:accessibility-tree-benchmark && npm run test:toolbar-guard && npm run test:cloud-bridge-approval && npm run test:discord && npm run test:pdf-read && npm run test:pdf-selection && npm run test:social-contract && npm run test:safesocial && npm run test:build-unpacked && npm run test:attachment-drop && npm run test:workflow-editor && node --test test/profile-sync-stats.mjs && node --test test/memcode-recall.mjs",- "test:shard:runtime-unit": "node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/cdp-clear-receipt.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.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/draftjs-native-editor.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/chat-steering.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.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/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.mjs",+ "test:shard:runtime-unit": "node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/cdp-clear-receipt.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.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/rich-text-frameworks.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/chat-steering.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.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/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.mjs","test:shard:browser-a": "node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/chat-steering-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs","test:shard:browser-b1": "node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs","test:shard:browser-b2": "node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs",@@ -96,9 +96,16 @@},"devDependencies": {"c8": "^12.0.0",+ "draft-js": "0.11.7",+ "immutable": "3.8.4","playwright": "^1.48.0",+ "react": "18.2.0",+ "react-dom": "18.2.0","tldts": "7.4.10"},+ "overrides": {+ "draft-js": { "immutable": "$immutable" }+ },"repository": {"type": "git","url": "https://github.com/webbrain-one/webbrain.git"diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 6a7625fb6..82533501f 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -29978,7 +29978,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai...params,...(typeof expected === 'string' ? { expected } : {}),},- });+ }, Number.isInteger(target.frameId) ? { frameId: target.frameId } : undefined);if (response?.success !== true|| !Number.isInteger(response.valueLength)|| response.valueLength < 0@@ -41572,7 +41572,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaidispatched = true;markEarlyCdpDispatched();try {- const response = await chrome.tabs.sendMessage(tabId, {+ let response = await chrome.tabs.sendMessage(tabId, {target: 'content',action: 'type',params: {@@ -41583,6 +41583,12 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaidispatchBinding: binding,},}, { frameId: targetFrameId });+ if (response?.trustedTypeRequired === true && response.noDispatch === true+ && response.dispatched !== true && typeof response.ref_id === 'string') {+ response = await this._maybeFallbackFieldWithCdp(tabId, 'type_ax', {+ ref_id: response.ref_id, text, clear,+ }, response, {}, earlyCdpAbortSignal, targetFrameId);+ }return {...(response || { success: false, dispatched: false, noDispatch: true, error: 'Iframe type returned no response' }),frameId: targetFrameId,@@ -45153,6 +45159,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agairesponse,messageRecipientContext = {},upstreamAbortSignal = null,+ frameId = 0,) {if (CONTENT_ACTION_SIGNAL_DEADLINES.has(upstreamAbortSignal)) {return this._maybeFallbackFieldWithCdpImpl(@@ -45162,6 +45169,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agairesponse,messageRecipientContext,upstreamAbortSignal,+ frameId,);}try {@@ -45173,6 +45181,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agairesponse,messageRecipientContext,abortSignal,+ frameId,),toolName,this._contentActionDeadlineMs(toolName, args),@@ -45193,6 +45202,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agairesponse,messageRecipientContext = {},abortSignal = null,+ frameId = 0,) {if (!response || (toolName !== 'type_ax' && toolName !== 'set_field')) return response;const expected = typeof response._expectedValue === 'string' ? response._expectedValue : null;@@ -45232,7 +45242,11 @@ If the user has already named or confirmed this exact recipient, do NOT ask agailet trustedDispatched = false;let trustedTextAttempted = false;let beforePreparation = null;- const digestTarget = { locatorType: 'ax', refId: args.ref_id };+ const digestTarget = { locatorType: 'ax', refId: args.ref_id, frameId };+ const actionDeadlineAt = Number(CONTENT_ACTION_SIGNAL_DEADLINES.get(abortSignal)?.deadlineAt) || 0;+ const sendContent = message => chrome.tabs.sendMessage(tabId, {+ ...message, ...(actionDeadlineAt > 0 ? { actionDeadlineAt } : {}),+ }, { frameId });const finishPreparationFailure = async failure => {if (!trustedDispatched || trustedTextAttempted || !beforePreparation?.documentToken || abortSignal?.aborted) return failure;const afterPreparation = await this._textMutationValueDigest(tabId, digestTarget);@@ -45257,7 +45271,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaithis._throwIfAborted(abortSignal);beforePreparation = await this._textMutationValueDigest(tabId, digestTarget);this._throwIfAborted(abortSignal);- let prepared = await chrome.tabs.sendMessage(tabId, {+ let prepared = await sendContent({target: 'content',action: 'ax_prepare_field_for_trusted_type',params: { ref_id: args.ref_id, selectionMode: contentEditableSelectionMode },@@ -45273,7 +45287,9 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaiawait cdpClient.attach(tabId);this._throwIfAborted(abortSignal);- if (prepared.contentEditable && prepared.rect?.w > 0 && prepared.rect?.h > 0) {+ // Child-frame rectangles are frame-relative. Focus/selection are already+ // bound to the exact editor there; do not click them as top-frame points.+ if (frameId === 0 && prepared.contentEditable && prepared.rect?.w > 0 && prepared.rect?.h > 0) {const x = prepared.rect.x + prepared.rect.w / 2;const y = prepared.rect.y + prepared.rect.h / 2;this._throwIfAborted(abortSignal);@@ -45293,7 +45309,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai// same ref and restore the requested selection immediately before// dispatch: replacement selects all; append collapses at the end so// existing rich-editor markup and spacing survive unchanged.- const reselected = await chrome.tabs.sendMessage(tabId, {+ const reselected = await sendContent({target: 'content',action: 'ax_prepare_field_for_trusted_type',params: { ref_id: args.ref_id, selectionMode: contentEditableSelectionMode },@@ -45319,29 +45335,43 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai// A lost response can precede a delayed applied write. After this// boundary an unchanged sample cannot make the text command retry-safe.trustedTextAttempted = true;- if (trustedText || appendingContentEditable) {- await cdpClient.sendCommand(tabId, 'Input.insertText', { text: trustedText });- } else {- await cdpClient.sendCommand(tabId, 'Input.dispatchKeyEvent', {- type: 'keyDown', key: 'Delete', code: 'Delete', windowsVirtualKeyCode: 46,+ const pageHandledPaste = prepared.editorKind === 'draftjs' && /[\r\n]/.test(trustedText);+ let verification;+ if (pageHandledPaste) {+ verification = await sendContent({+ target: 'content', action: 'ax_paste_draft',+ params: { ref_id: args.ref_id, text: trustedText, clear: clearsExisting },});- await cdpClient.sendCommand(tabId, 'Input.dispatchKeyEvent', {- type: 'keyUp', key: 'Delete', code: 'Delete', windowsVirtualKeyCode: 46,+ this._throwIfAborted(abortSignal);+ if (!verification?.success || verification.verified !== true) {+ return verification || { ...failed, dispatched: true, noDispatch: false,+ outcomeUnknown: true, retryable: false, error: 'The editor paste result is unknown. Check the draft before retrying.' };+ }+ } else {+ if (trustedText || appendingContentEditable) {+ await cdpClient.sendCommand(tabId, 'Input.insertText', { text: trustedText });+ } else {+ await cdpClient.sendCommand(tabId, 'Input.dispatchKeyEvent', {+ type: 'keyDown', key: 'Delete', code: 'Delete', windowsVirtualKeyCode: 46,+ });+ await cdpClient.sendCommand(tabId, 'Input.dispatchKeyEvent', {+ type: 'keyUp', key: 'Delete', code: 'Delete', windowsVirtualKeyCode: 46,+ });+ }+ this._throwIfAborted(abortSignal);+ await new Promise(resolve => setTimeout(resolve, 120));+ this._throwIfAborted(abortSignal);+ verification = await sendContent({+ target: 'content',+ action: 'ax_verify_field_value',+ params: {+ ref_id: args.ref_id,+ expected,+ ...(appendingContentEditable ? { appendText: trustedText } : {}),+ },});+ this._throwIfAborted(abortSignal);}- this._throwIfAborted(abortSignal);- await new Promise(resolve => setTimeout(resolve, 120));- this._throwIfAborted(abortSignal);- const verification = await chrome.tabs.sendMessage(tabId, {- target: 'content',- action: 'ax_verify_field_value',- params: {- ref_id: args.ref_id,- expected,- ...(appendingContentEditable ? { appendText: trustedText } : {}),- },- });- this._throwIfAborted(abortSignal);if (!verification?.success || verification.verified !== true) {return {...failed,@@ -45358,11 +45388,12 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai...response,success: true,dispatched: true,- trusted: true,+ trusted: !pageHandledPaste,verified: true,method: `${toolName}_cdp_fallback`,fallbackAttempted: true,- trustedFallback: true,+ trustedFallback: !pageHandledPaste,+ ...(pageHandledPaste ? { pageHandledPaste: true } : {}),fieldMeta: verification.fieldMeta || prepared.fieldMeta || response.fieldMeta,};delete recovered.error;@@ -45390,7 +45421,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaithis._throwIfAborted(abortSignal);}if (messageRecipientContext.messageRecipientGuardRequired === true) {- const recipientValidation = await chrome.tabs.sendMessage(tabId, {+ const recipientValidation = await sendContent({target: 'content',action: 'consume_message_recipient_dispatch_binding',params: {diff --git a/src/chrome/src/agent/rich-text-toolbar-probe.js b/src/chrome/src/agent/rich-text-toolbar-probe.jsindex 77225cd08..0f89f3eb6 100644--- a/src/chrome/src/agent/rich-text-toolbar-probe.js+++ b/src/chrome/src/agent/rich-text-toolbar-probe.js@@ -307,6 +307,13 @@ export class RichTextToolbarProbe {}[el] = marked;if (deadlineExpired()) return deadlineFailure();+ if (el.isContentEditable && (el.classList.contains('public-DraftEditor-content')+ || ['ProseMirror', 'ql-editor', 'cke_editable', 'mce-content-body', 'cm-content'].some(name => el.classList.contains(name))+ || el.getAttribute('data-slate-editor') === 'true' || el.getAttribute('data-lexical-editor') === 'true'+ || Array.from(el.children).some(child => child.getAttribute('data-contents') === 'true'))) {+ return { ok: false, dispatched: false, trustedTypeRequired: true,+ error: 'This rich-text editor requires trusted browser typing. Read its current accessibility tree and use type_ax with the editor reference.' };+ }// Preparation only binds a marker. Focus belongs after this frame's// dispatch fence so it cannot invalidate its own authorized write.window.__wbPageMonitor?.beforeLocalDispatch({ preparation: true, kind: 'focus', target: el });@@ -361,7 +368,8 @@ export class RichTextToolbarProbe {return {success: false,...(result?.dispatched ? { dispatched: true } : { dispatched: false, noDispatch: true }),- retryable: true,+ retryable: result?.trustedTypeRequired !== true,+ ...(result?.trustedTypeRequired ? { trustedTypeRequired: true } : {}),error: result?.error || 'The iframe target changed before typing. Re-read the iframe and retry.',};} finally {diff --git a/src/chrome/src/cdp/cdp-client.js b/src/chrome/src/cdp/cdp-client.jsindex 6f0996e50..e062c5c2d 100644--- a/src/chrome/src/cdp/cdp-client.js+++ b/src/chrome/src/cdp/cdp-client.js@@ -61,10 +61,123 @@ function readEmptyCaretText(el) {&& el.innerText === '' && el.textContent === '' ? '' : null;}+async function pasteDraftJsText(el, text, clear, readDocument, options = {}) {+ const doc = el?.ownerDocument, view = doc?.defaultView, root = el?.getRootNode(), url = doc?.URL;+ let dispatched = false;+ const failure = (error, extra = {}) => ({+ success: false, verified: false, dispatched,+ ...(dispatched+ ? { mutationMayHaveOccurred: true, outcomeUnknown: true, retryable: false, recoveryRequired: 'verify_or_restore_field' }+ : { noDispatch: true, outcomeUnknown: false, retryable: false }),+ error, ...extra,+ });+ const expired = () => options.deadlineExpired?.() === true;+ const deadlineFailure = () => failure('The page action deadline expired during rich-text entry.', { deadlineExpired: true });+ const current = () => !!el?.isConnected && el.ownerDocument === doc && doc.defaultView === view+ && view.document === doc && el.getRootNode() === root && doc.URL === url;+ const active = () => {+ let target = root?.activeElement || doc?.activeElement;+ while (target?.shadowRoot?.activeElement) target = target.shadowRoot.activeElement;+ return target;+ };+ const selection = () => root?.getSelection?.() || view?.getSelection();+ const range = () => { const selected = selection(); return selected?.rangeCount === 1 ? selected.getRangeAt(0) : null; };+ const within = selected => !!selected && el.contains(selected.startContainer) && el.contains(selected.endContainer);+ const wait = () => new Promise(resolve => view.setTimeout(resolve, 30));+ const fence = phase => {+ if (options.beforeDispatch?.(phase) === false) {+ throw Object.assign(new Error('Browser changed during action preparation. Re-observe before acting.'), { code: 'page_feedback_pending' });+ }+ };+ try {+ if (expired()) return deadlineFailure();+ if (!current() || !el.isContentEditable || typeof readDocument !== 'function') return failure('The editable target is no longer available.');+ text = String(text).replace(/\r\n?/g, '\n');+ const previous = readDocument(el), htmlBefore = el.innerHTML;+ if (typeof previous !== 'string') return failure('The DraftJS document could not be read completely.', { recoveryRequired: 'fresh_tree' });+ if (!text.includes('\n')) return failure('This page-handled path requires multiline DraftJS text.');+ fence('focus');+ if (expired()) return deadlineFailure();+ el.focus({ preventScroll: true });+ await wait();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed while preparing plain-text paste. No paste was sent.');+ }+ if (expired()) return deadlineFailure();+ if (active() !== el) return failure('The editor focus changed before plain-text paste.');+ // DraftJS maps marked text leaves to its public DOM selection. Selecting+ // the root or replacing its nodes can leave the model selection stale.+ const leaves = Array.from(el.querySelectorAll('[data-text="true"]'));+ const first = leaves[0], last = leaves[leaves.length - 1], selected = doc.createRange();+ if (!first || !last) return failure('The DraftJS text selection could not be established.');+ if (first.tagName === 'BR') selected.setStartBefore(first);+ else if (first.firstChild?.nodeType === 3) selected.setStart(first.firstChild, 0);+ else return failure('The DraftJS text selection could not be established.');+ if (last.tagName === 'BR') selected.setEndBefore(last);+ else if (last.lastChild?.nodeType === 3) selected.setEnd(last.lastChild, last.lastChild.nodeValue.length);+ else return failure('The DraftJS text selection could not be established.');+ if (!clear) selected.collapse(false);+ const selectedText = selection();+ if (!selectedText) return failure('The text selection is unavailable.');+ selectedText.removeAllRanges(); selectedText.addRange(selected);+ const prepared = range()?.cloneRange();+ await wait();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed while preparing plain-text paste. No paste was sent.');+ }+ if (expired()) return deadlineFailure();+ const liveRange = range();+ if (active() !== el || !within(liveRange) || !prepared+ || liveRange.startContainer !== prepared.startContainer || liveRange.startOffset !== prepared.startOffset+ || liveRange.endContainer !== prepared.endContainer || liveRange.endOffset !== prepared.endOffset) {+ return failure('The editor focus or selection changed before plain-text paste.');+ }+ const transfer = new view.DataTransfer();+ transfer.setData('text/plain', text);+ const event = new view.ClipboardEvent('paste', { bubbles: true, composed: true, cancelable: true, clipboardData: transfer });+ // Firefox drops ClipboardEventInit.clipboardData. This event-local payload+ // is plain text only and never reads or writes the system clipboard.+ if (event.clipboardData?.getData('text/plain') !== text) Object.defineProperty(event, 'clipboardData', { value: transfer });+ if (event.clipboardData?.getData('text/plain') !== text) return failure('The plain-text paste payload could not be established.');+ fence('input');+ if (expired()) return deadlineFailure();+ const fencedRange = range();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed during the paste dispatch fence. No paste was sent.');+ }+ if (active() !== el || !within(fencedRange)+ || fencedRange.startContainer !== prepared.startContainer || fencedRange.startOffset !== prepared.startOffset+ || fencedRange.endContainer !== prepared.endContainer || fencedRange.endOffset !== prepared.endOffset) {+ return failure('The editor focus or selection changed at the paste dispatch fence.');+ }+ const invoke = () => { dispatched = true; return el.dispatchEvent(event); };+ const accepted = options.dispatch ? options.dispatch(invoke) : invoke();+ await wait(); await wait();+ if (expired()) return deadlineFailure();+ if (!current() || active() !== el || !within(range())) return failure('The editor scope changed during plain-text paste.');+ const value = readDocument(el), expected = (clear ? '' : previous) + text;+ if (accepted || typeof value !== 'string' || value !== expected) {+ return failure('The complete settled DraftJS value could not be verified after plain-text paste. No additional text was sent.');+ }+ return { success: true, verified: true, dispatched: true, outcomeUnknown: false,+ pageHandledPaste: true, method: 'contenteditable-page-handled-paste', value: value.slice(0, 100) };+ } catch (error) {+ return failure(error?.message || String(error), error?.code === 'page_feedback_pending' ? { pageFeedbackPending: true } : {});+ }+}+// This private object exists only around one native SelectAll/Delete operation.// A caret BR without this exact event/node history remains an authored LF.function nativeTextClearReceipt(el) {if (!el?.isConnected || !el.isContentEditable) return null;+ // Semantic document readers prove these editors empty. Their framework+ // legitimately rerenders text/caret nodes after deletion, whereas this+ // receipt only certifies an ordinary browser-created, unmarked caret BR.+ if (el.classList?.contains('public-DraftEditor-content') || el.classList?.contains('ProseMirror')+ || Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true')) return null;const doc = el.ownerDocument, view = doc.defaultView, root = el.getRootNode(), url = doc.URL;const parent = node => node.parentNode || (node.nodeType === 11 ? node.host : null);const ancestors = []; for (let node = parent(el); node; node = parent(node)) ancestors.push(node);@@ -5394,21 +5507,117 @@ export class CDPClient {} catch {}}+ // Multiline DraftJS input must pass through its public paste handler. A+ // single native multiline insertion can duplicate the framework's DOM.+ async _pasteDraftJsText(tabId, selector, info, text, clear, options = {}) {+ let objectId = null, objectGroup = null, originalSnapshotId = null, attempted = false;+ const failure = error => ({ success: false, verified: false, dispatched: attempted,+ ...(attempted ? { outcomeUnknown: true, mutationMayHaveOccurred: true, recoveryRequired: 'verify_or_restore_field' } : { noDispatch: true }),+ retryable: false, error });+ try {+ if (info.nodeId) objectId = (await this.sendCommand(tabId, 'DOM.resolveNode', { nodeId: info.nodeId }))?.object?.objectId;+ else {+ const found = await this.querySelectorPierce(tabId, selector);+ objectGroup = found?.objectGroup;+ if (found?.objectIds?.length === 1) objectId = found.objectIds[0];+ }+ if (!objectId) return failure('The original rich-text target could not be preserved.');+ const draft = await this.sendCommand(tabId, 'Runtime.callFunctionOn', {+ objectId, returnByValue: true,+ functionDeclaration: `function () { return !!this.isContentEditable && (this.classList.contains('public-DraftEditor-content')+ || Array.from(this.children).some(child => child.getAttribute('data-contents') === 'true')); }`,+ });+ if (draft?.result?.value !== true) return null;+ if (options.abortSignal?.aborted) return failure('Text entry was aborted before plain-text paste.');+ // Keep DOM object identities in the renderer across the separate focus+ // and input fences. A focus handler cannot become a new append baseline.+ const snapshot = await this.sendCommand(tabId, 'Runtime.callFunctionOn', {+ objectId,+ functionDeclaration: `function () {+ return { element: this, doc: this.ownerDocument, view: this.ownerDocument.defaultView,+ root: this.getRootNode(), url: this.ownerDocument.URL,+ value: (${readDraftJsText.toString()})(this), html: this.innerHTML };+ }`,+ });+ originalSnapshotId = snapshot?.result?.objectId || null;+ if (!originalSnapshotId || snapshot.exceptionDetails) return failure('The original DraftJS document could not be preserved.');+ const target = hasPageAgentDispatchOwner(tabId) ? await this._pageAgentObjectTarget(tabId, objectId) : {};+ const focusGuard = await beforePageAgentDispatch(globalThis.chrome, tabId, {+ kind: 'click', tool: 'type_text', eventTypes: ['focus', 'focusin', 'blur', 'focusout'],+ navigationCandidate: false, fenceOnly: true, prepareMonitor: true, ...target,+ });+ if (options.abortSignal?.aborted) return failure('Text entry was aborted before plain-text paste.');+ if (typeof options.beforeDispatch === 'function') options.beforeDispatch();+ attempted = true;+ const focused = await this.sendCommand(tabId, 'Runtime.callFunctionOn', {+ objectId, returnByValue: true, userGesture: true,+ functionDeclaration: `function (deadlineAt, targetToken, focusGuard, original) {+ ${PAGE_AGENT_DOM_ACTION_SOURCE}+ if (deadlineAt > 0 && Date.now() >= deadlineAt) return { success: false, noDispatch: true, dispatched: false, deadlineExpired: true };+ if (!this.isConnected || original.element !== this || this.ownerDocument !== original.doc+ || original.doc.defaultView !== original.view || original.view.document !== original.doc+ || this.getRootNode() !== original.root || original.doc.URL !== original.url+ || typeof original.value !== 'string' || (${readDraftJsText.toString()})(this) !== original.value || this.innerHTML !== original.html+ || (targetToken && this[Symbol.for('webbrain.dispatchBinding')] !== targetToken)+ || !beforePageAgentDomAction(focusGuard, 'focus', this))+ return { success: false, noDispatch: true, dispatched: false, pageFeedbackPending: true };+ this.focus({ preventScroll: true });+ return { success: true };+ }`,+ arguments: [...[Number(options.deadlineAt) || 0, String(options.dispatchBindingToken || ''), focusGuard || null].map(value => ({ value })), { objectId: originalSnapshotId }],+ });+ if (focused?.exceptionDetails || !focused?.result?.value) return failure('The editor focus response became unavailable. No paste was sent.');+ if (focused.result.value.success !== true) return { ...focused.result.value, verified: false, retryable: false, error: 'The editor could not be focused before plain-text paste.' };+ const pageGuard = await beforePageAgentDispatch(globalThis.chrome, tabId, {+ kind: 'input', tool: 'type_text', eventTypes: ['paste', 'beforeinput', 'input', 'change'], fenceOnly: true, prepareMonitor: true, ...target,+ });+ if (options.abortSignal?.aborted) return failure('Text entry was aborted before plain-text paste.');+ if (typeof options.beforeDispatch === 'function') options.beforeDispatch();+ attempted = true;+ const pasted = await this.sendCommand(tabId, 'Runtime.callFunctionOn', {+ objectId, returnByValue: true, awaitPromise: true, userGesture: true,+ functionDeclaration: `async function (text, clear, deadlineAt, targetToken, pageGuard, original) {+ ${PAGE_AGENT_DOM_ACTION_SOURCE}+ const el = this;+ const originalScope = () => el.isConnected && original.element === el && el.ownerDocument === original.doc+ && original.doc.defaultView === original.view && original.view.document === original.doc+ && el.getRootNode() === original.root && original.doc.URL === original.url;+ const originalFocused = () => {+ let active = original.root.activeElement || original.doc.activeElement;+ while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;+ return active === el;+ };+ if (!originalScope() || !originalFocused() || typeof original.value !== 'string'+ || (${readDraftJsText.toString()})(el) !== original.value || el.innerHTML !== original.html)+ return { success: false, verified: false, dispatched: true, mutationMayHaveOccurred: true,+ outcomeUnknown: true, retryable: false, recoveryRequired: 'verify_or_restore_field',+ error: 'The original editor changed during focus preparation. No paste was sent.' };+ return await (${pasteDraftJsText.toString()})(el, text, clear, (${readDraftJsText.toString()}), {+ deadlineExpired: () => deadlineAt > 0 && Date.now() >= deadlineAt,+ beforeDispatch: phase => originalScope() && originalFocused()+ && (!targetToken || el[Symbol.for('webbrain.dispatchBinding')] === targetToken)+ && (phase === 'focus' || beforePageAgentDomAction(pageGuard, phase, el)),+ });+ }`,+ arguments: [...[text, clear, Number(options.deadlineAt) || 0, String(options.dispatchBindingToken || ''), pageGuard || null].map(value => ({ value })), { objectId: originalSnapshotId }],+ });+ const result = pasted?.result?.value;+ if (!result || pasted.exceptionDetails) return failure('The plain-text paste response became unavailable. No additional text was sent.');+ return { ...result, tag: info.tag, rect: { x: Math.round(info.x - (info.width || 1) / 2),+ y: Math.round(info.y - (info.height || 1) / 2), w: Math.round(info.width || 1), h: Math.round(info.height || 1) } };+ } catch (error) {+ return { ...failure(error?.message || String(error)), ...(error?.code === 'page_feedback_pending' ? { pageFeedbackPending: true } : {}) };+ } finally {+ if (originalSnapshotId) this.releaseObject(tabId, originalSnapshotId);+ if (objectGroup) await this.releaseObjectGroup(tabId, objectGroup);+ else if (objectId) this.releaseObject(tabId, objectId);+ }+ }+/**- * Type text into an element.- *- * Robust path:- * 1. Resolve via shared shadow-piercing resolver (open + closed roots).- * 2. Focus via real mouse click at the element's coordinates so the page- * sees a trusted focus event (matters for contenteditable, rich editors,- * and Google-style search boxes).- * 3. Optionally clear existing value.- * 4. Type via Input.insertText — this generates an actual `beforeinput` /- * `input` event that frameworks accept, and works for both <input>,- * <textarea>, and contenteditable.- * 5. Falls back to a JS-level value setter if Input.insertText is rejected- * (e.g. element isn't focusable through CDP because it's in a closed- * shadow root with no usable hit point).+ * Resolve and verify the original target before text entry. DraftJS multiline+ * text uses the page's plain-text paste handler; other text uses trusted+ * Input.insertText after focus and optional native selection/deletion.*/async typeText(tabId, selector, text, clear = false, expectedBackendNodeId = null, resolveOptions = {}) {const abortSignal = resolveOptions?.abortSignal || null;@@ -5582,6 +5791,11 @@ export class CDPClient {if (!info) return { success: false, dispatched: false, noDispatch: true, error: 'Element not found' };if (info.error) return { success: false, dispatched: false, noDispatch: true, error: info.error };const dispatchBindingToken = String(resolveOptions?.dispatchBindingToken || '');+ if (/[\r\n]/.test(String(text ?? ''))) {+ const pasted = await this._pasteDraftJsText(tabId, selector, info, text, clear, resolveOptions);+ if (pasted) return pasted;+ throwIfAborted();+ }// Empty appends mutate nothing on text-entry controls: inserting zero// characters cannot change any value, so report a proven no-op withoutdiff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex e16252cae..ba43cc6bc 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -2301,7 +2301,123 @@return callback();}+ async function pasteDraftJsText(el, text, clear, readDocument, options = {}) {+ const doc = el?.ownerDocument, view = doc?.defaultView, root = el?.getRootNode(), url = doc?.URL;+ let dispatched = false;+ const failure = (error, extra = {}) => ({+ success: false, verified: false, dispatched,+ ...(dispatched+ ? { mutationMayHaveOccurred: true, outcomeUnknown: true, retryable: false, recoveryRequired: 'verify_or_restore_field' }+ : { noDispatch: true, outcomeUnknown: false, retryable: false }),+ error, ...extra,+ });+ const expired = () => options.deadlineExpired?.() === true;+ const deadlineFailure = () => failure('The page action deadline expired during rich-text entry.', { deadlineExpired: true });+ const current = () => !!el?.isConnected && el.ownerDocument === doc && doc.defaultView === view+ && view.document === doc && el.getRootNode() === root && doc.URL === url;+ const active = () => {+ let target = root?.activeElement || doc?.activeElement;+ while (target?.shadowRoot?.activeElement) target = target.shadowRoot.activeElement;+ return target;+ };+ const selection = () => root?.getSelection?.() || view?.getSelection();+ const range = () => { const selected = selection(); return selected?.rangeCount === 1 ? selected.getRangeAt(0) : null; };+ const within = selected => !!selected && el.contains(selected.startContainer) && el.contains(selected.endContainer);+ const wait = () => new Promise(resolve => view.setTimeout(resolve, 30));+ const fence = phase => {+ if (options.beforeDispatch?.(phase) === false) {+ throw Object.assign(new Error('Browser changed during action preparation. Re-observe before acting.'), { code: 'page_feedback_pending' });+ }+ };+ try {+ if (expired()) return deadlineFailure();+ if (!current() || !el.isContentEditable || typeof readDocument !== 'function') return failure('The editable target is no longer available.');+ text = String(text).replace(/\r\n?/g, '\n');+ const previous = readDocument(el), htmlBefore = el.innerHTML;+ if (typeof previous !== 'string') return failure('The DraftJS document could not be read completely.', { recoveryRequired: 'fresh_tree' });+ if (!text.includes('\n')) return failure('This page-handled path requires multiline DraftJS text.');+ fence('focus');+ if (expired()) return deadlineFailure();+ el.focus({ preventScroll: true });+ await wait();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed while preparing plain-text paste. No paste was sent.');+ }+ if (expired()) return deadlineFailure();+ if (active() !== el) return failure('The editor focus changed before plain-text paste.');+ // DraftJS maps marked text leaves to its public DOM selection. Selecting+ // the root or replacing its nodes can leave the model selection stale.+ const leaves = Array.from(el.querySelectorAll('[data-text="true"]'));+ const first = leaves[0], last = leaves[leaves.length - 1], selected = doc.createRange();+ if (!first || !last) return failure('The DraftJS text selection could not be established.');+ if (first.tagName === 'BR') selected.setStartBefore(first);+ else if (first.firstChild?.nodeType === 3) selected.setStart(first.firstChild, 0);+ else return failure('The DraftJS text selection could not be established.');+ if (last.tagName === 'BR') selected.setEndBefore(last);+ else if (last.lastChild?.nodeType === 3) selected.setEnd(last.lastChild, last.lastChild.nodeValue.length);+ else return failure('The DraftJS text selection could not be established.');+ if (!clear) selected.collapse(false);+ const selectedText = selection();+ if (!selectedText) return failure('The text selection is unavailable.');+ selectedText.removeAllRanges(); selectedText.addRange(selected);+ const prepared = range()?.cloneRange();+ await wait();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed while preparing plain-text paste. No paste was sent.');+ }+ if (expired()) return deadlineFailure();+ const liveRange = range();+ if (active() !== el || !within(liveRange) || !prepared+ || liveRange.startContainer !== prepared.startContainer || liveRange.startOffset !== prepared.startOffset+ || liveRange.endContainer !== prepared.endContainer || liveRange.endOffset !== prepared.endOffset) {+ return failure('The editor focus or selection changed before plain-text paste.');+ }+ const transfer = new view.DataTransfer();+ transfer.setData('text/plain', text);+ const event = new view.ClipboardEvent('paste', { bubbles: true, composed: true, cancelable: true, clipboardData: transfer });+ // Firefox drops ClipboardEventInit.clipboardData. This event-local payload+ // is plain text only and never reads or writes the system clipboard.+ if (event.clipboardData?.getData('text/plain') !== text) Object.defineProperty(event, 'clipboardData', { value: transfer });+ if (event.clipboardData?.getData('text/plain') !== text) return failure('The plain-text paste payload could not be established.');+ fence('input');+ if (expired()) return deadlineFailure();+ const fencedRange = range();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed during the paste dispatch fence. No paste was sent.');+ }+ if (active() !== el || !within(fencedRange)+ || fencedRange.startContainer !== prepared.startContainer || fencedRange.startOffset !== prepared.startOffset+ || fencedRange.endContainer !== prepared.endContainer || fencedRange.endOffset !== prepared.endOffset) {+ return failure('The editor focus or selection changed at the paste dispatch fence.');+ }+ const invoke = () => { dispatched = true; return el.dispatchEvent(event); };+ const accepted = options.dispatch ? options.dispatch(invoke) : invoke();+ await wait(); await wait();+ if (expired()) return deadlineFailure();+ if (!current() || active() !== el || !within(range())) return failure('The editor scope changed during plain-text paste.');+ const value = readDocument(el), expected = (clear ? '' : previous) + text;+ if (accepted || typeof value !== 'string' || value !== expected) {+ return failure('The complete settled DraftJS value could not be verified after plain-text paste. No additional text was sent.');+ }+ return { success: true, verified: true, dispatched: true, outcomeUnknown: false,+ pageHandledPaste: true, method: 'contenteditable-page-handled-paste', value: value.slice(0, 100) };+ } catch (error) {+ return failure(error?.message || String(error), error?.code === 'page_feedback_pending' ? { pageFeedbackPending: true } : {});+ }+ }+async function _insertContentEditableText(el, text, clear, actionDeadlineExpired = () => false, ownInputScope = null) {+ if (isDraftJsEditor(el) && /[\r\n]/.test(text)) {+ const result = await pasteDraftJsText(el, text, clear, readDraftJsText, {+ deadlineExpired: actionDeadlineExpired,+ beforeDispatch: phase => window.__wbPageMonitor?.beforeLocalDispatch({ preparation: phase === 'focus', kind: 'input', target: el }),+ dispatch: callback => withLocalPageDispatch(callback),+ });+ return { ...result, fieldMeta: _fieldMeta(el) };+ }const doc = el.ownerDocument;let dispatched = false;const failure = (error, extra = {}) => ({@@ -2316,6 +2432,19 @@});const expired = () => failure('The page action deadline expired during rich-text entry.', { deadlineExpired: true });if (actionDeadlineExpired()) return expired();+ if (isModelManagedEditor(el)) {+ if (isDraftJsEditor(el) && readDraftJsText(el) === null) {+ return failure('The editor document could not be read completely. Refresh the page observation before typing.',+ { recoveryRequired: 'fresh_tree', retryable: false });+ }+ // These editors own their DOM. Even plain execCommand insertion can+ // replace framework-owned nodes; never attempt it before trusted input.+ const ref_id = window.__wb_ax_ref?.(el);+ return failure('This rich-text editor requires trusted browser typing.', {+ trustedTypeRequired: true, ref_id, fieldMeta: _fieldMeta(el),+ _expectedValue: (clear ? '' : _editableTextValue(el)) + text,+ });+ }if (typeof doc.execCommand !== 'function') {return failure('This editor has no supported native text insertion path. No content was changed.');}@@ -4788,6 +4917,14 @@|| Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true'));}+ function isModelManagedEditor(el) {+ return !!el?.isContentEditable && (isDraftJsEditor(el)+ || ['ProseMirror', 'ql-editor', 'cke_editable', 'mce-content-body', 'cm-content']+ .some(name => el.classList?.contains(name))+ || el.getAttribute('data-slate-editor') === 'true'+ || el.getAttribute('data-lexical-editor') === 'true');+ }+function readDraftJsText(el) {if (!el?.isContentEditable || !el.childNodes) return null;const roots = Array.from(el.childNodes);@@ -8804,7 +8941,7 @@let selectExpected = null;if (el.isContentEditable) {previous = _editableTextValue(el);- if (readProseMirrorText(el) === null) {+ if (!isModelManagedEditor(el) || (isDraftJsEditor(el) && /[\r\n]/.test(text))) {const native = await _insertContentEditableText(el, text, !!clear, actionDeadlineExpired);return { ...native, ref_id, rect: typeRect, fieldMeta };}@@ -9033,15 +9170,17 @@);let prevValue = '';let pageHandledBeforeInput = false;+ let pageHandledPaste = false;if (recoveringDraft) {prevValue = _editableTextValue(el);} else if (el.isContentEditable) {prevValue = _editableTextValue(el);- if (readProseMirrorText(el) === null) {+ if (!isModelManagedEditor(el) || (isDraftJsEditor(el) && /[\r\n]/.test(text))) {const native = await _insertContentEditableText(el, text, clear, actionDeadlineExpired, originalRecipient?.nativeDraftOwnInputs);if (!native.success) return { ...native, ref_id, rect, fieldMeta };dispatched = native.dispatched === true;pageHandledBeforeInput = native.pageHandledBeforeInput === true;+ pageHandledPaste = native.pageHandledPaste === true;} else {return failure('Contenteditable fields require trusted browser typing. Attempting one ref-bound Chrome typing pass.',@@ -9270,6 +9409,7 @@dispatched,method: 'set_field',...(pageHandledBeforeInput ? { dispatched: true, pageHandledBeforeInput: true, nativeBeforeInputCancelled: true } : {}),+ ...(pageHandledPaste ? { pageHandledPaste: true } : {}),ref_id,rect,verified: true,@@ -9289,6 +9429,15 @@// Internal Chrome recovery helpers. The background resolves the exact// ref again, prepares either replacement or append selection, sends// trusted CDP text, then asks this content script for settled readback.+ 'ax_paste_draft': async () => {+ const { ref_id, text, clear = true } = msg.params || {};+ const el = typeof ref_id === 'string' && window.__wb_ax_lookup?.(ref_id);+ if (!el?.isConnected || !isDraftJsEditor(el) || typeof text !== 'string' || !/[\r\n]/.test(text)) {+ return { success: false, verified: false, dispatched: false, noDispatch: true, retryable: false,+ error: 'The original DraftJS editor or multiline text is unavailable.' };+ }+ return { ...await _insertContentEditableText(el, text, clear, actionDeadlineExpired), ref_id };+ },'ax_prepare_field_for_trusted_type': () => {try {const { ref_id, selectionMode = 'all' } = msg.params || {};@@ -9324,6 +9473,7 @@fieldMeta: _fieldMeta(el),isCombobox,contentEditable: !!el.isContentEditable,+ ...(isDraftJsEditor(el) ? { editorKind: 'draftjs' } : {}),selectionMode: el.isContentEditable && selectionMode === 'end' ? 'end' : 'all',rect: {x: Math.round(rect.x),diff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.jsindex 7488e522b..c5f94f130 100644--- a/src/chrome/src/content/page-monitor.js+++ b/src/chrome/src/content/page-monitor.js@@ -2506,6 +2506,9 @@'hover', 'drag_drop', 'patch_element', 'revert_patch', 'highlight_element', 'execute_js','ax_prepare_field_for_trusted_type', 'ax_resolve_two_rects', 'ax_resolve_rect']);function beginContentAction(action, params = {}) {+ // Internal DraftJS paste is the same ref-bound input operation as type_ax.+ // Keep its focus and synchronous editor changes inside the normal input owner.+ if (action === 'ax_paste_draft') action = 'type_ax';if (!active || !localMutations.has(action)|| (action === 'ax_resolve_rect' && params.observeOnly === true && params.forClickFallback === true)) return () => {};const operationId = `local-${randomToken()}`;diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex a8b2cbd03..375c12ddd 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -38462,7 +38462,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout ddispatched = true;markContentPipelineDispatched();try {- const response = await browser.tabs.sendMessage(tabId, {+ const response = await firefoxBidi.sendContent(tabId, {target: 'content',action: 'type',params: {diff --git a/src/firefox/src/agent/rich-text-toolbar-probe.js b/src/firefox/src/agent/rich-text-toolbar-probe.jsindex 5b1d55780..01b827e61 100644--- a/src/firefox/src/agent/rich-text-toolbar-probe.js+++ b/src/firefox/src/agent/rich-text-toolbar-probe.js@@ -317,6 +317,13 @@ export class RichTextToolbarProbe {}el = marked[0];if (deadlineExpired()) return deadlineFailure();+ if (el.isContentEditable && (el.classList.contains('public-DraftEditor-content')+ || ['ProseMirror', 'ql-editor', 'cke_editable', 'mce-content-body', 'cm-content'].some(name => el.classList.contains(name))+ || el.getAttribute('data-slate-editor') === 'true' || el.getAttribute('data-lexical-editor') === 'true'+ || Array.from(el.children).some(child => child.getAttribute('data-contents') === 'true'))) {+ return { ok: false, dispatched: false, trustedTypeRequired: true,+ error: 'This rich-text editor requires Firefox trusted automation. Enable it in Settings → General → Advanced and retry.' };+ }// Preparation only binds a marker. Focus belongs after this frame's// dispatch fence and must retain the exact marked target.window.__wbPageMonitor?.beforeLocalDispatch({ preparation: true, kind: 'focus', target: el });@@ -376,7 +383,8 @@ export class RichTextToolbarProbe {return {success: false,...(result?.dispatched ? { dispatched: true } : { dispatched: false, noDispatch: true }),- retryable: true,+ retryable: result?.trustedTypeRequired !== true,+ ...(result?.trustedTypeRequired ? { trustedTypeRequired: true } : {}),error: result?.error || 'The iframe target changed before typing. Re-read the iframe and retry.',};} finally {diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex 9c483d05f..6c682c091 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -2622,7 +2622,123 @@return callback();}+ async function pasteDraftJsText(el, text, clear, readDocument, options = {}) {+ const doc = el?.ownerDocument, view = doc?.defaultView, root = el?.getRootNode(), url = doc?.URL;+ let dispatched = false;+ const failure = (error, extra = {}) => ({+ success: false, verified: false, dispatched,+ ...(dispatched+ ? { mutationMayHaveOccurred: true, outcomeUnknown: true, retryable: false, recoveryRequired: 'verify_or_restore_field' }+ : { noDispatch: true, outcomeUnknown: false, retryable: false }),+ error, ...extra,+ });+ const expired = () => options.deadlineExpired?.() === true;+ const deadlineFailure = () => failure('The page action deadline expired during rich-text entry.', { deadlineExpired: true });+ const current = () => !!el?.isConnected && el.ownerDocument === doc && doc.defaultView === view+ && view.document === doc && el.getRootNode() === root && doc.URL === url;+ const active = () => {+ let target = root?.activeElement || doc?.activeElement;+ while (target?.shadowRoot?.activeElement) target = target.shadowRoot.activeElement;+ return target;+ };+ const selection = () => root?.getSelection?.() || view?.getSelection();+ const range = () => { const selected = selection(); return selected?.rangeCount === 1 ? selected.getRangeAt(0) : null; };+ const within = selected => !!selected && el.contains(selected.startContainer) && el.contains(selected.endContainer);+ const wait = () => new Promise(resolve => view.setTimeout(resolve, 30));+ const fence = phase => {+ if (options.beforeDispatch?.(phase) === false) {+ throw Object.assign(new Error('Browser changed during action preparation. Re-observe before acting.'), { code: 'page_feedback_pending' });+ }+ };+ try {+ if (expired()) return deadlineFailure();+ if (!current() || !el.isContentEditable || typeof readDocument !== 'function') return failure('The editable target is no longer available.');+ text = String(text).replace(/\r\n?/g, '\n');+ const previous = readDocument(el), htmlBefore = el.innerHTML;+ if (typeof previous !== 'string') return failure('The DraftJS document could not be read completely.', { recoveryRequired: 'fresh_tree' });+ if (!text.includes('\n')) return failure('This page-handled path requires multiline DraftJS text.');+ fence('focus');+ if (expired()) return deadlineFailure();+ el.focus({ preventScroll: true });+ await wait();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed while preparing plain-text paste. No paste was sent.');+ }+ if (expired()) return deadlineFailure();+ if (active() !== el) return failure('The editor focus changed before plain-text paste.');+ // DraftJS maps marked text leaves to its public DOM selection. Selecting+ // the root or replacing its nodes can leave the model selection stale.+ const leaves = Array.from(el.querySelectorAll('[data-text="true"]'));+ const first = leaves[0], last = leaves[leaves.length - 1], selected = doc.createRange();+ if (!first || !last) return failure('The DraftJS text selection could not be established.');+ if (first.tagName === 'BR') selected.setStartBefore(first);+ else if (first.firstChild?.nodeType === 3) selected.setStart(first.firstChild, 0);+ else return failure('The DraftJS text selection could not be established.');+ if (last.tagName === 'BR') selected.setEndBefore(last);+ else if (last.lastChild?.nodeType === 3) selected.setEnd(last.lastChild, last.lastChild.nodeValue.length);+ else return failure('The DraftJS text selection could not be established.');+ if (!clear) selected.collapse(false);+ const selectedText = selection();+ if (!selectedText) return failure('The text selection is unavailable.');+ selectedText.removeAllRanges(); selectedText.addRange(selected);+ const prepared = range()?.cloneRange();+ await wait();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed while preparing plain-text paste. No paste was sent.');+ }+ if (expired()) return deadlineFailure();+ const liveRange = range();+ if (active() !== el || !within(liveRange) || !prepared+ || liveRange.startContainer !== prepared.startContainer || liveRange.startOffset !== prepared.startOffset+ || liveRange.endContainer !== prepared.endContainer || liveRange.endOffset !== prepared.endOffset) {+ return failure('The editor focus or selection changed before plain-text paste.');+ }+ const transfer = new view.DataTransfer();+ transfer.setData('text/plain', text);+ const event = new view.ClipboardEvent('paste', { bubbles: true, composed: true, cancelable: true, clipboardData: transfer });+ // Firefox drops ClipboardEventInit.clipboardData. This event-local payload+ // is plain text only and never reads or writes the system clipboard.+ if (event.clipboardData?.getData('text/plain') !== text) Object.defineProperty(event, 'clipboardData', { value: transfer });+ if (event.clipboardData?.getData('text/plain') !== text) return failure('The plain-text paste payload could not be established.');+ fence('input');+ if (expired()) return deadlineFailure();+ const fencedRange = range();+ if (!current() || readDocument(el) !== previous || el.innerHTML !== htmlBefore) {+ dispatched = true;+ return failure('The editor changed during the paste dispatch fence. No paste was sent.');+ }+ if (active() !== el || !within(fencedRange)+ || fencedRange.startContainer !== prepared.startContainer || fencedRange.startOffset !== prepared.startOffset+ || fencedRange.endContainer !== prepared.endContainer || fencedRange.endOffset !== prepared.endOffset) {+ return failure('The editor focus or selection changed at the paste dispatch fence.');+ }+ const invoke = () => { dispatched = true; return el.dispatchEvent(event); };+ const accepted = options.dispatch ? options.dispatch(invoke) : invoke();+ await wait(); await wait();+ if (expired()) return deadlineFailure();+ if (!current() || active() !== el || !within(range())) return failure('The editor scope changed during plain-text paste.');+ const value = readDocument(el), expected = (clear ? '' : previous) + text;+ if (accepted || typeof value !== 'string' || value !== expected) {+ return failure('The complete settled DraftJS value could not be verified after plain-text paste. No additional text was sent.');+ }+ return { success: true, verified: true, dispatched: true, outcomeUnknown: false,+ pageHandledPaste: true, method: 'contenteditable-page-handled-paste', value: value.slice(0, 100) };+ } catch (error) {+ return failure(error?.message || String(error), error?.code === 'page_feedback_pending' ? { pageFeedbackPending: true } : {});+ }+ }+async function _insertContentEditableText(el, text, clear, actionDeadlineExpired = () => false, ownInputScope = null) {+ if (isDraftJsEditor(el) && /[\r\n]/.test(text)) {+ const result = await pasteDraftJsText(el, text, clear, readDraftJsText, {+ deadlineExpired: actionDeadlineExpired,+ beforeDispatch: phase => window.__wbPageMonitor?.beforeLocalDispatch({ preparation: phase === 'focus', kind: 'input', target: el }),+ dispatch: callback => withLocalPageDispatch(callback),+ });+ return { ...result, fieldMeta: _fieldMeta(el) };+ }const doc = el.ownerDocument;let dispatched = false;const failure = (error, extra = {}) => ({@@ -2637,6 +2753,12 @@});const expired = () => failure('The page action deadline expired during rich-text entry.', { deadlineExpired: true });if (actionDeadlineExpired()) return expired();+ if (isModelManagedEditor(el)) {+ // Framework editors own their DOM. Native BiDi input bypasses this+ // fallback; without it, leave the draft intact instead of corrupting it.+ return failure('This rich-text editor requires Firefox trusted automation. Enable it in Settings → General → Advanced and retry.',+ { trustedTypeRequired: true, recoveryRequired: 'trusted_input', retryable: false });+ }if (typeof doc.execCommand !== 'function') {return failure('This editor has no supported native text insertion path. No content was changed.');}@@ -4056,6 +4178,14 @@|| Array.from(el.children || []).some(child => child.getAttribute('data-contents') === 'true'));}+ function isModelManagedEditor(el) {+ return !!el?.isContentEditable && (isDraftJsEditor(el)+ || ['ProseMirror', 'ql-editor', 'cke_editable', 'mce-content-body', 'cm-content']+ .some(name => el.classList?.contains(name))+ || el.getAttribute('data-slate-editor') === 'true'+ || el.getAttribute('data-lexical-editor') === 'true');+ }+function readDraftJsText(el) {if (!el?.isContentEditable || !el.childNodes) return null;const roots = Array.from(el.childNodes);@@ -8046,6 +8176,7 @@}let prevValue = '';let pageHandledBeforeInput = false;+ let pageHandledPaste = false;if (actionDeadlineExpired()) return deadlineFailure();window.__wbPageMonitor?.beforeLocalDispatch();dispatched = true;@@ -8056,7 +8187,8 @@const native = await _insertContentEditableText(el, text, clear, actionDeadlineExpired, originalRecipient?.nativeDraftOwnInputs);if (!native.success) return { ...native, ref_id, rect, fieldMeta: _fieldMeta(el) };dispatched = native.dispatched === true;- pageHandledBeforeInput = native.pageHandledBeforeInput === true;+ pageHandledBeforeInput = native.pageHandledBeforeInput === true;+ pageHandledPaste = native.pageHandledPaste === true;} else {prevValue = el.value || '';const proto = el.tagName === 'TEXTAREA'@@ -8267,6 +8399,7 @@dispatched,method: 'set_field',...(pageHandledBeforeInput ? { dispatched: true, pageHandledBeforeInput: true, nativeBeforeInputCancelled: true } : {}),+ ...(pageHandledPaste ? { pageHandledPaste: true } : {}),ref_id,rect,verified: true,diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.jsindex 7488e522b..c5f94f130 100644--- a/src/firefox/src/content/page-monitor.js+++ b/src/firefox/src/content/page-monitor.js@@ -2506,6 +2506,9 @@'hover', 'drag_drop', 'patch_element', 'revert_patch', 'highlight_element', 'execute_js','ax_prepare_field_for_trusted_type', 'ax_resolve_two_rects', 'ax_resolve_rect']);function beginContentAction(action, params = {}) {+ // Internal DraftJS paste is the same ref-bound input operation as type_ax.+ // Keep its focus and synchronous editor changes inside the normal input owner.+ if (action === 'ax_paste_draft') action = 'type_ax';if (!active || !localMutations.has(action)|| (action === 'ax_resolve_rect' && params.observeOnly === true && params.forClickFallback === true)) return () => {};const operationId = `local-${randomToken()}`;diff --git a/test/draftjs-native-editor.mjs b/test/draftjs-native-editor.mjsdeleted file mode 100644index d8c8844b9..000000000--- a/test/draftjs-native-editor.mjs+++ /dev/null@@ -1,65 +0,0 @@-import assert from 'node:assert/strict';-import { readFile } from 'node:fs/promises';-import { test } from 'node:test';-import { chromium, firefox } from 'playwright';--for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {- test(`${build}: native DraftJS edits retain literal application data and reject unsupported settled text`, async () => {- const browser = await engine.launch({ headless: true });- try {- const page = await browser.newPage();- const posts = [];- await page.route('https://owned-editor.invalid/**', async route => {- if (route.request().method() === 'POST') {- posts.push(route.request().postDataJSON()); await route.fulfill({ contentType: 'application/json', body: '{"saved":true}' });- } else await route.fulfill({ contentType: 'text/html', body: '<!doctype html><h1>Owned DraftJS editor</h1><div id="editor" role="textbox" aria-label="Owned editor" contenteditable="true" class="public-DraftEditor-content"></div><button id="save">Save owned draft</button>' });- });- await page.goto('https://owned-editor.invalid/editor');- await page.evaluate(build => {- window[build === 'firefox' ? 'browser' : 'chrome'] = { runtime: { getURL: value => value, onMessage: { addListener: handler => { window.qaHandler = handler; } } } };- window.qaCall = (action, params) => new Promise(resolve => qaHandler({ target: 'content', action, params }, {}, resolve));- window.qaModel = ''; window.qaEvents = []; window.qaUnsupported = false;- const editor = document.querySelector('#editor');- const render = value => {- const root = document.createElement('div'); root.dataset.contents = 'true';- value.split('\n').forEach((line, index) => {- const block = document.createElement('div'); block.dataset.block = 'true'; block.dataset.offsetKey = `${index}-0-0`;- const body = document.createElement('div'); body.className = 'public-DraftStyleDefault-block'; body.dataset.offsetKey = `${index}-0-0`;- const carrier = document.createElement('span'); carrier.dataset.offsetKey = `${index}-0-0`;- const leaf = document.createElement(line ? 'span' : 'br'); leaf.dataset.text = 'true'; if (line) leaf.textContent = line;- carrier.append(leaf); body.append(carrier); block.append(body); root.append(block);- });- editor.replaceChildren(root);- };- render('');- editor.addEventListener('input', event => {- qaEvents.push(event.isTrusted);- // This owned app reads the browser's native insertion, then renders- // the same strongly marked document blocks as a model-backed editor.- qaModel = editor.textContent;- render(qaModel);- if (qaUnsupported) {- const hidden = document.createElement('span'); hidden.dataset.text = 'true'; hidden.textContent = ' hidden unverified suffix'; hidden.style.display = 'none';- editor.querySelector('.public-DraftStyleDefault-block').append(hidden);- }- });- document.querySelector('#save').onclick = () => fetch('/save', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ value: qaModel }) });- }, build);- for (const file of ['accessibility-tree.js', 'rich-text-toolbar-heuristic.js', 'content.js']) {- await page.addScriptTag({ content: await readFile(new URL(`../src/${build}/src/content/${file}`, import.meta.url), 'utf8') });- }- const write = text => page.evaluate(text => qaCall('type', { selector: '#editor', text, clear: true }), text);- const literal = 'Literal <b>markup</b> & 🧠 Türkçe ıİşŞğĞüÜöÖçÇ.';- const valid = await write(literal); assert.equal(valid.success, true, JSON.stringify(valid)); assert.equal(valid.verified, true);- await page.locator('#save').click(); await page.waitForFunction(() => qaEvents.length > 0); while (!posts.length) await page.waitForTimeout(10);- assert.equal(posts[0].value, literal, 'Verify real application POST bytes, not the tool\'s normalized readback.');- assert.ok(await page.evaluate(() => qaEvents.every(Boolean)), 'All actual input events remain trusted.');- await page.evaluate(() => { qaUnsupported = true; });- const unknown = await write('matching visible prefix');- assert.equal(unknown.success, false, 'Unknown model document text must not certify only its matching visible prefix.');- assert.equal(unknown.verified, false); assert.equal(unknown.dispatched, true); assert.equal(unknown.outcomeUnknown, true);- assert.equal(unknown.recoveryRequired, 'verify_or_restore_field');- assert.equal(await page.evaluate(() => qaModel), 'matching visible prefix');- } finally { await browser.close(); }- });-}diff --git a/test/draftjs-text.mjs b/test/draftjs-text.mjsindex 8118d0a13..18c2f6133 100644--- a/test/draftjs-text.mjs+++ b/test/draftjs-text.mjs@@ -79,7 +79,7 @@ function contentHarness(build, current) {const source = fs.readFileSync(`src/${build}/src/content/content.js`, 'utf8');const ownInputScope = source.match(/^ let _messageRecipientOwnedInputScope = null;$/m)?.[0];assert.ok(ownInputScope, 'Use the real private production owned-input scope');- const names = ['_setFieldValueMatches', 'readProseMirrorText', 'readEmptyCaretText', 'isDraftJsEditor', 'readDraftJsText',+ const names = ['_setFieldValueMatches', 'readProseMirrorText', 'readEmptyCaretText', 'isDraftJsEditor', 'isModelManagedEditor', 'readDraftJsText','_nativeChatCaretContext', '_sameNativeChatCaretContext', '_singleEditableCaretBreak','_rememberNativeChatEmptyCaret', '_nativeChatCaretValueIsEmpty', '_editableTextValue', '_insertContentEditableText'];if (build === 'chrome') names.unshift('_contentEditableValueMatches');@@ -117,7 +117,7 @@ function contentHarness(build, current) {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 => {+ if (build === 'firefox') test('Firefox: DraftJS leaves its model untouched without trusted automation', 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) {@@ -127,9 +127,9 @@ for (const build of ['chrome', 'firefox']) {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');+ assert.equal(attempts, 0); assert.equal(result.success, false); assert.equal(result.verified, false);+ assert.equal(result.noDispatch, true); assert.equal(result.trustedTypeRequired, true);+ assert.equal(h.read(current.editor), '', 'The existing DraftJS model remains untouched');});});@@ -301,14 +301,14 @@ test('Chrome: native appends preserve strong empty-editor proof and do not retry};try {const initial = await h.call('type_ax', args);- assert.equal(initial.dispatched, true); assert.equal(initial.success, mode === 'draftjs');- assert.equal(nativeInsertions, 1, 'The native insertion runs once.');+ assert.equal(initial.dispatched, mode !== 'draftjs'); assert.equal(initial.success, false);+ assert.equal(nativeInsertions, mode === 'draftjs' ? 0 : 1, 'Framework DOM is untouched before trusted input.');const typed = await agent._maybeFallbackFieldWithCdp(41, 'type_ax', args, initial);assert.equal(typed.success, mode === 'draftjs'); assert.equal(typed.verified, mode === 'draftjs');const finalized = await agent._finalizeTextMutationResult(41, 'type_ax', args, typed);assert.equal(finalized.success, mode === 'draftjs'); assert.equal(agent._uncertainTextMutations.has(41), mode !== 'draftjs');- assert.equal(commands.filter(method => method === 'Input.insertText').length, 0,- 'An already dispatched native write must not be replayed through CDP.');+ assert.equal(commands.filter(method => method === 'Input.insertText').length, mode === 'draftjs' ? 1 : 0,+ 'Only a proven no-dispatch result may send one trusted insertion.');assert.equal(h.read(current.editor), tweet);} finally { api.tabs.sendMessage = oldMessage; cdpClient.attach = oldAttach; cdpClient.sendCommand = oldSend; }});diff --git a/test/firefox-rich-text-readback.mjs b/test/firefox-rich-text-readback.mjsnew file mode 100644index 000000000..489021ad3--- /dev/null+++ b/test/firefox-rich-text-readback.mjs@@ -0,0 +1,342 @@+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { test } from 'node:test';+import { firefox } from 'playwright';+import { BidiSession } from '../firefox-companion/session.mjs';++// Exercise production BiDi declarations against real Firefox DOM and trusted+// keyboard input. The transport shim changes only how native keys are delivered;+// target preparation, selection, readback, and submission gating are production.+async function nativeSession(page, { guard = null, validate = null } = {}) {+ const session = new BidiSession();+ const runId = crypto.randomUUID();+ session.runs.set(runId, { context: 'owned-firefox-editor' });+ session.locate = async () => ({ context: 'owned-firefox-editor', node: { sharedId: 'original-editor' } });+ const commands = [];+ const declarations = [];+ session.call = async (_match, declaration, args = []) => {+ declarations.push(declaration);+ const value = await page.evaluate(({ declaration, args }) => {+ const fn = (0, eval)(`(${declaration})`);+ return fn(window.qaEditor, ...args.map(arg => arg.value ?? null));+ }, { declaration, args });+ if (value && typeof value === 'object') {+ return { result: { type: 'object', value: Object.entries(value).map(([name, item]) => [name, { type: typeof item, value: item }]) } };+ }+ return { result: value === null ? { type: 'null' } : { value } };+ };+ const keys = new Map([['\uE009', 'Control'], ['\uE03D', 'Meta'], ['\uE003', 'Backspace'], ['\uE007', 'Enter']]);+ const held = new Set();+ session.send = async (method, params) => {+ commands.push({ method, params });+ if (method === 'input.releaseActions') {+ for (const key of held) await page.keyboard.up(key);+ held.clear();+ } else if (method === 'input.performActions') {+ for (const action of params.actions[0].actions) {+ const key = keys.get(action.value);+ if (key) {+ if (action.type === 'keyDown') { await page.keyboard.down(key); held.add(key); }+ else { await page.keyboard.up(key); held.delete(key); }+ } else if (action.type === 'keyDown') {+ if (held.has('Control') || held.has('Meta')) await page.keyboard.press(action.value);+ else await page.keyboard.type(action.value);+ }+ }+ }+ return {};+ };+ return {+ commands, declarations,+ async perform(action, payload) {+ const token = crypto.randomUUID();+ await page.evaluate(token => qaEditor.setAttribute('data-webbrain-bidi', token), token);+ return session.perform(runId, action, { token, ...(guard ? { pageFeedbackGuard: guard } : {}), ...payload }, validate);+ },+ };+}++async function loadDraftJs(page, previous = '') {+ await page.evaluate(() => window.__wbPageMonitor?.dispose?.());+ await page.setContent('<style>.public-DraftEditor-content{min-height:60px;white-space:pre-wrap}body{font:16px sans-serif}</style><main id="app"></main>');+ for (const path of ['react/umd/react.development.js', 'react-dom/umd/react-dom.development.js', 'immutable/dist/immutable.js', 'draft-js/dist/Draft.js']) {+ await page.addScriptTag({ content: await readFile(new URL(`../node_modules/${path}`, import.meta.url), 'utf8') });+ }+ await page.evaluate(previous => {+ const { Editor, EditorState, ContentState } = Draft;+ function OwnedEditor() {+ const [state, setState] = React.useState(() => EditorState.createWithContent(ContentState.createFromText(previous)));+ window.qaModel = state.getCurrentContent().getPlainText('\n');+ window.qaSetText = value => setState(EditorState.createWithContent(ContentState.createFromText(value)));+ return React.createElement(Editor, { editorState: state, onChange: setState });+ }+ ReactDOM.render(React.createElement(OwnedEditor), document.querySelector('#app'));+ window.qaEditor = document.querySelector('.public-DraftEditor-content');+ window.qaEvents = [];+ window.qaPastes = [];+ qaEditor.addEventListener('input', event => qaEvents.push({ trusted: event.isTrusted, inputType: event.inputType }));+ qaEditor.addEventListener('paste', event => qaPastes.push(event.clipboardData?.getData('text/plain')));+ }, previous);+}++test('Firefox: production BiDi typing uses exact DraftJS model text for empty appends, replacements and existing multiline documents', async t => {+ const browser = await firefox.launch({ headless: true });+ try {+ const page = await browser.newPage();+ for (const scenario of [+ { name: 'empty append', previous: '', action: 'type', text: 'body', expected: 'body' },+ { name: 'empty replacement', previous: '', action: 'field', text: 'body', expected: 'body' },+ { name: 'replace existing document', previous: 'Existing draft', action: 'field', text: 'Replacement', expected: 'Replacement' },+ { name: 'append inside last leaf', previous: 'First\n\nLast', action: 'type', text: ' suffix', expected: 'First\n\nLast suffix' },+ { name: 'literal Unicode and markup', previous: '', action: 'field', text: ' Türkçe ıİ 🧠 <b>literal</b> & ', expected: ' Türkçe ıİ 🧠 <b>literal</b> & ' },+ ]) await t.test(scenario.name, async () => {+ await loadDraftJs(page, scenario.previous);+ const native = await nativeSession(page);+ const result = await native.perform(scenario.action, { text: scenario.text });+ const facts = await page.evaluate(() => ({ model: qaModel, html: qaEditor.innerHTML }));+ assert.equal(result.success, true, JSON.stringify({ result, facts }));+ assert.equal(result.verified, true);+ assert.equal(await page.evaluate(() => qaModel), scenario.expected, 'The real controlled DraftJS model must hold exactly the requested document.');+ assert.ok(await page.evaluate(() => qaEvents.length > 0 && qaEvents.every(event => event.trusted)));+ assert.equal(await page.locator('b').count(), 0, 'Literal text cannot become markup.');+ assert.equal(native.commands.some(command => command.params?.actions?.[0]?.actions.some(action => action.value === '\uE007')), false, 'Literal line breaks must not send Enter.');+ assert.equal(await page.evaluate(() => qaEditor.childNodes.length), 1, 'Append stays inside the original marked document root.');+ if (scenario.name === 'append inside last leaf') {+ const declaration = native.declarations.find(source => source.includes('const actual = readRichTextFieldValue'));+ const readback = expected => page.evaluate(({ declaration, expected }) => (0, eval)(`(${declaration})`)(qaEditor, expected), { declaration, expected });+ assert.equal(await readback('First\r\n\r\nLast suffix'), true, 'CRLF normalization preserves authored document separators.');+ assert.equal(await readback('First\n\n\nLast suffix'), false, 'Visual spacing cannot excuse an extra authored line break.');+ }+ });+ } finally { await browser.close(); }+});++async function installOwnedMonitor(page) {+ await page.evaluate(() => {+ const heading = document.createElement('h1'); heading.textContent = 'Owned draft';+ document.querySelector('main').prepend(heading);+ // The existing model fence binds field geometry. Fix it here so this test+ // isolates dispatch ownership rather than independent layout invalidation.+ qaEditor.style.height = '180px';+ qaEditor.setAttribute('aria-label', 'Owned draft'); qaEditor.focus();+ window.qaMonitorListeners = []; window.qaFeedback = []; window.qaEnterDocuments = [];+ qaEditor.addEventListener('keydown', event => {+ if (event.key !== 'Enter') return;+ qaEnterDocuments.push(qaModel); event.preventDefault(); event.stopImmediatePropagation();+ });+ window.chrome = window.browser = { runtime: {+ onMessage: { addListener: listener => qaMonitorListeners.push(listener), removeListener() {} },+ async sendMessage(message) {+ if (message.action === 'get_page_monitor_state') return { active: true, runToken: 'owned-rich-text', documentToken: message.documentToken };+ if (message.action === 'page_feedback') { qaFeedback.push(message.feedback); return { accepted: true }; }+ return {};+ },+ } };+ window.qaDeliver = (action, params = {}) => new Promise(resolve => {+ for (const listener of qaMonitorListeners) {+ const asynchronous = listener({ target: 'content', action, params: { runToken: 'owned-rich-text', ...params } }, {}, resolve);+ if (asynchronous === true) break;+ }+ });+ });+ for (const file of ['accessibility-tree.js', 'page-monitor.js']) {+ await page.addScriptTag({ content: await readFile(new URL(`../src/firefox/src/content/${file}`, import.meta.url), 'utf8') });+ }+ await page.waitForFunction(() => window.__wbPageMonitor?.active);+ await page.waitForTimeout(100);+ const fence = await page.evaluate(async () => {+ const snapshot = await qaDeliver('page_monitor_capture_model', { includeTree: true });+ const prepared = await qaDeliver('page_monitor_prepare', {+ operationId: 'owned-multiline-edit', tool: 'type_text', selector: '.public-DraftEditor-content',+ expectedModelSnapshot: snapshot.snapshotToken, allowPassiveRebase: true,+ });+ const fence = await qaDeliver('page_monitor_dispatch', { operationId: 'owned-multiline-edit', kind: 'input', fenceOnly: true });+ qaFeedback = [];+ return { prepared, fence };+ });+ assert.equal(fence.prepared.modelBindingValid, true, JSON.stringify(fence));+ assert.equal(fence.fence.ready, true, JSON.stringify(fence));+ return {+ guard: fence.fence.guard,+ validate: async (_id, guard, kind, rebindFocus) => {+ const result = await page.evaluate(({ guard, kind, rebindFocus }) => qaDeliver('page_monitor_validate', { ...guard, kind, rebindFocus }), { guard, kind, rebindFocus });+ return result.ready === true;+ },+ };+}++test('Firefox: production monitor owns multiline paste and preserves the native submit fence', async t => {+ const browser = await firefox.launch({ headless: true });+ try {+ const page = await browser.newPage();+ for (const replacement of [false, true]) await t.test(replacement ? 'clear, paste and verified submit' : 'append, paste and verified submit', async () => {+ await loadDraftJs(page, 'Existing\nlast');+ const native = await nativeSession(page, await installOwnedMonitor(page));+ const result = await native.perform('field', { text: 'First\n\nLast\n', clear: replacement, submit: true });+ const expected = `${replacement ? '' : 'Existing\nlast'}First\n\nLast\n`;+ const facts = await page.evaluate(() => ({ model: qaModel, feedback: qaFeedback, enters: qaEnterDocuments }));+ assert.equal(result.verified, true, JSON.stringify({ result, facts }));+ assert.equal(result.submitted, true);+ assert.equal(facts.model, expected);+ assert.deepEqual(facts.enters, [expected], 'A single Enter follows exact verification, without losing the native sequence to a synthetic marker.');+ assert.equal(facts.feedback.some(item => item.source !== 'agent'), false, JSON.stringify(facts.feedback));+ assert.equal(native.declarations.filter(source => source.includes("new view.ClipboardEvent('paste'")).length, 1);+ });+ await t.test('a delayed page change after paste prevents the bundled submit', async () => {+ await loadDraftJs(page);+ const native = await nativeSession(page, await installOwnedMonitor(page));+ await page.evaluate(() => qaEditor.addEventListener('paste', () => setTimeout(() => {+ qaEditor.setAttribute('aria-label', 'Different document');+ }, 15), { once: true }));+ await assert.rejects(native.perform('field', { text: 'First\n\nLast', clear: false, submit: true }), error => {+ assert.equal(error.dispatchState.dispatched, true);+ assert.equal(error.dispatchState.outcomeUnknown, true);+ assert.equal(error.dispatchState.retryable, false);+ assert.equal(error.code, 'page_feedback_pending');+ return true;+ });+ assert.equal(await page.evaluate(() => qaModel), 'First\n\nLast');+ assert.deepEqual(await page.evaluate(() => qaEnterDocuments), []);+ assert.equal(native.declarations.filter(source => source.includes("new view.ClipboardEvent('paste'")).length, 1);+ });+ } finally { await browser.close(); }+});++test('Firefox: semantic readback preserves ProseMirror paragraphs and generic rendered field values', async t => {+ const browser = await firefox.launch({ headless: true });+ try {+ const page = await browser.newPage();+ for (const scenario of [+ { name: 'ProseMirror empty caret', html: '<div id="editor" contenteditable class="ProseMirror"><p><br class="ProseMirror-trailingBreak"></p></div>', text: 'body', expected: 'body' },+ { name: 'ProseMirror document separators', html: '<div id="editor" contenteditable class="ProseMirror"><p>First</p><p>Last</p></div>', text: ' suffix', expected: 'First\nLast suffix' },+ { name: 'ordinary visual paragraph spacing', html: '<div id="editor" contenteditable><p>First</p><p>Last</p></div>', text: ' suffix', expected: 'First\n\nLast suffix' },+ { name: 'ordinary authored spaces', html: '<div id="editor" contenteditable style="white-space:pre-wrap"> Existing </div>', text: ' suffix ', expected: ' Existing suffix ' },+ { name: 'plain input value', html: '<input id="editor" value="Existing">', text: ' suffix', expected: 'Existing suffix' },+ ]) await t.test(scenario.name, async () => {+ await page.setContent(scenario.html);+ await page.evaluate(() => { window.qaEditor = document.querySelector('#editor'); });+ const native = await nativeSession(page);+ const result = await native.perform('type', { text: scenario.text });+ assert.equal(result.verified, true, JSON.stringify(result));+ const state = await page.evaluate(() => ({ text: qaEditor.isContentEditable ? qaEditor.innerText : qaEditor.value, children: qaEditor.childNodes.length }));+ if (scenario.name === 'ProseMirror document separators') assert.equal(state.text, 'First\n\nLast suffix');+ else assert.equal(state.text, scenario.expected);+ if (scenario.name === 'ProseMirror empty caret') assert.equal(state.children, 1, 'The caret stays within the ProseMirror paragraph.');+ });+ } finally { await browser.close(); }+});++test('Firefox: unsupported DraftJS preflight sends no text, and unsupported settled documents cannot submit or retry', async t => {+ const browser = await firefox.launch({ headless: true });+ try {+ const page = await browser.newPage();+ await t.test('unsupported before typing', async () => {+ await loadDraftJs(page);+ await page.evaluate(() => {+ const hidden = document.createElement('span'); hidden.dataset.text = 'true'; hidden.textContent = 'unverified'; hidden.hidden = true;+ qaEditor.querySelector('.public-DraftStyleDefault-block').append(hidden);+ });+ const native = await nativeSession(page);+ await assert.rejects(native.perform('field', { text: 'body', submit: true }), error => {+ assert.equal(error.dispatchState.noDispatch, true);+ assert.equal(error.dispatchState.dispatched, false);+ assert.match(error.message, /exact document text/);+ return true;+ });+ assert.equal(native.commands.length, 0);+ assert.equal(await page.evaluate(() => qaModel), '');+ });+ await t.test('a prevented clear cannot append the replacement to the existing document', async () => {+ await loadDraftJs(page, 'Existing draft');+ await page.evaluate(() => qaEditor.addEventListener('keydown', event => {+ if (event.key === 'Backspace') { event.preventDefault(); event.stopImmediatePropagation(); }+ }, { capture: true }));+ const native = await nativeSession(page);+ await assert.rejects(native.perform('field', { text: 'First\nLast', submit: true }), error => {+ assert.equal(error.dispatchState.dispatched, true);+ assert.equal(error.dispatchState.outcomeUnknown, true);+ assert.equal(error.dispatchState.retryable, false);+ assert.match(error.message, /clearing did not establish an empty document/);+ return true;+ });+ assert.equal(await page.evaluate(() => qaModel), 'Existing draft');+ assert.deepEqual(await page.evaluate(() => qaPastes), []);+ assert.equal(native.declarations.some(source => source.includes("new view.ClipboardEvent('paste'")), false);+ });+ for (const mode of ['hidden suffix', 'lost model markers']) await t.test(`unsupported after dispatched input: ${mode}`, async () => {+ await loadDraftJs(page);+ await page.evaluate(mode => qaEditor.addEventListener('input', () => setTimeout(() => {+ if (mode === 'lost model markers') {+ qaEditor.classList.remove('public-DraftEditor-content');+ qaEditor.textContent = qaModel;+ } else {+ const hidden = document.createElement('span'); hidden.dataset.text = 'true'; hidden.textContent = 'unverified'; hidden.hidden = true;+ qaEditor.querySelector('.public-DraftStyleDefault-block').append(hidden);+ }+ }, 15), { once: true }), mode);+ const native = await nativeSession(page);+ const result = await native.perform('field', { text: 'aB', clear: false, submit: true });+ assert.equal(result.success, false);+ assert.equal(result.verified, false);+ assert.equal(result.dispatched, true);+ assert.equal(result.outcomeUnknown, true);+ assert.equal(result.retryable, false);+ assert.equal(result.submitted, false);+ assert.equal(await page.evaluate(() => qaModel), 'aB');+ assert.equal(native.commands.filter(command => command.method === 'input.performActions').length, 2, 'Each character is sent once; verification must not dispatch a second edit.');+ });+ } finally { await browser.close(); }+});++test('Firefox: DraftJS plain-text paste writes a complete multiline document exactly once', async t => {+ const browser = await firefox.launch({ headless: true });+ try {+ const page = await browser.newPage();+ for (const scenario of [+ { name: 'empty append', previous: '', action: 'type', text: 'First\n\nLast' },+ { name: 'empty replacement', previous: '', action: 'field', text: 'First\n\nLast' },+ { name: 'replace old multiline draft', previous: 'Old\n\ndraft', action: 'field', text: 'First\n\nLast' },+ { name: 'append after last marked leaf', previous: 'Existing\n\nlast', action: 'type', text: ' suffix\nNext' },+ { name: 'append to empty last block', previous: 'Existing\n', action: 'type', text: '\nNext\n' },+ { name: 'leading and trailing LF', previous: '', action: 'field', text: '\nFirst\n\nLast\n' },+ { name: 'CRLF document separators', previous: '', action: 'field', text: 'First\r\n\r\nLast\r\n' },+ { name: 'literal multiline Unicode and markup', previous: '', action: 'field', text: ' Türkçe 🧠 <b>literal</b> &\n Next \n' },+ ]) await t.test(scenario.name, async () => {+ await loadDraftJs(page, scenario.previous);+ const native = await nativeSession(page);+ const result = await native.perform(scenario.action, { text: scenario.text });+ const expected = (scenario.action === 'type' ? scenario.previous : '') + scenario.text.replace(/\r\n?/g, '\n');+ const facts = await page.evaluate(() => ({ model: qaModel, html: qaEditor.innerHTML, pastes: qaPastes }));+ assert.equal(result.success, true, JSON.stringify({ result, facts, expected }));+ assert.equal(result.verified, true);+ assert.equal(facts.model, expected, 'The controlled DraftJS model and production semantic reader agree on the whole document.');+ assert.deepEqual(facts.pastes, [scenario.text.replace(/\r\n?/g, '\n')], 'Exactly one public plain-text paste reaches the editor.');+ assert.equal(await page.locator('b').count(), 0, 'A clipboard payload cannot interpret literal markup.');+ assert.equal(native.declarations.filter(source => source.includes("execCommand('insertText'")).length, 0, 'DraftJS multiline edits must not fall back to LF editing commands.');+ const keyDowns = native.commands.filter(command => command.method === 'input.performActions')+ .flatMap(command => command.params.actions[0].actions.filter(action => action.type === 'keyDown').map(action => action.value));+ assert.equal(keyDowns.includes('\uE007'), false, 'A document line break cannot send a submit shortcut.');+ assert.equal(keyDowns.filter(value => !['\uE009', '\uE03D', '\uE003'].includes(value)).join(''), scenario.action === 'field' ? 'a' : '', 'Only trusted clear keys precede the single paste.');+ });+ await t.test('a cancelled and unchanged paste stays uncertain without submit or replay', async () => {+ await loadDraftJs(page);+ await page.evaluate(() => qaEditor.addEventListener('paste', event => {+ event.preventDefault(); event.stopImmediatePropagation();+ }, { capture: true }));+ const native = await nativeSession(page);+ const result = await native.perform('field', { text: 'First\n\nLast', submit: true });+ assert.equal(result.success, false);+ assert.equal(result.verified, false);+ assert.equal(result.dispatched, true);+ assert.equal(result.outcomeUnknown, true);+ assert.equal(result.retryable, false);+ assert.equal(result.submitted, false);+ assert.equal(await page.evaluate(() => qaModel), '');+ const keyDowns = native.commands.filter(command => command.method === 'input.performActions')+ .flatMap(command => command.params.actions[0].actions.filter(action => action.type === 'keyDown').map(action => action.value));+ assert.equal(keyDowns.includes('\uE007'), false, 'Literal LF insertion cannot send a submit shortcut.');+ assert.equal(keyDowns.filter(value => !['\uE009', '\uE03D', '\uE003'].includes(value)).join(''), 'a', 'No characters or submission follow the ambiguous paste.');+ assert.equal(native.declarations.filter(source => source.includes("new view.ClipboardEvent('paste'")).length, 1, 'Verification must not repeat an ambiguous paste.');+ });+ } finally { await browser.close(); }+});diff --git a/test/iframe-preparation-focus.mjs b/test/iframe-preparation-focus.mjsindex ebd39b564..c038d0260 100644--- a/test/iframe-preparation-focus.mjs+++ b/test/iframe-preparation-focus.mjs@@ -3,7 +3,7 @@ import { test } from 'node:test';import { chromium, firefox } from 'playwright';for (const [kind, engine] of [['chrome', chromium], ['firefox', firefox]]) {- test(`${kind}: legacy nested iframe preparation keeps focus inert and respects the final dispatch fence`, async () => {+ test(`${kind}: legacy nested iframe preparation keeps focus inert and respects the final dispatch fence`, async t => {const browser = await engine.launch({ headless: true });const originalChrome = globalThis.chrome, originalBrowser = globalThis.browser;try {@@ -59,6 +59,24 @@ for (const [kind, engine] of [['chrome', chromium], ['firefox', firefox]]) {} });assert.equal(replaced.success, false); assert.equal(replaced.noDispatch, true);assert.equal(await editor.locator('input').inputValue(), '', 'A replacement document never inherits the old marker binding.');+ for (const marker of [+ ['class', 'public-DraftEditor-content'], ['class', 'ProseMirror'], ['class', 'ql-editor'],+ ['class', 'cke_editable'], ['class', 'mce-content-body'], ['class', 'cm-content'],+ ['data-slate-editor', 'true'], ['data-lexical-editor', 'true'],+ ]) await t.test(`${marker.join('=')}: legacy typing preserves the model-owned document`, async () => {+ await editor.evaluate(([attribute, value]) => {+ document.body.innerHTML = '<div id="rich" contenteditable="true">Original <strong>format</strong></div>';+ const el = document.querySelector('#rich'); el.setAttribute(attribute, value);+ window.editorEvents = [];+ for (const name of ['focus', 'beforeinput', 'input']) el.addEventListener(name, () => editorEvents.push(name));+ }, marker);+ const refused = await probe.legacyIframeTypeAllFrames(1, { ...args, selector: '#rich', text: 'Replacement' });+ assert.equal(refused.success, false); assert.equal(refused.noDispatch, true);+ assert.equal(refused.dispatched, false); assert.equal(refused.trustedTypeRequired, true);+ assert.equal(refused.retryable, false);+ assert.equal(await editor.locator('#rich').innerHTML(), 'Original <strong>format</strong>');+ assert.deepEqual(await editor.evaluate(() => editorEvents), []);+ });} finally {globalThis.chrome = originalChrome; globalThis.browser = originalBrowser;await browser.close();diff --git a/test/page-monitor-ui.mjs b/test/page-monitor-ui.mjsindex 1ed55930f..d7cef608c 100644--- a/test/page-monitor-ui.mjs+++ b/test/page-monitor-ui.mjs@@ -94,7 +94,9 @@ test('Chrome AX preparation attributes actual scrolling without claiming field iconst start = source.indexOf(`'${action}': () => {`), end = source.indexOf('\n },', start);assert.ok(start > 0 && end > start); return source.slice(start, end + 8);});- await page.addScriptTag({ content: `window.axHelpers = { ${entries.join(',\n')} };` });+ const draftJsEditor = source.match(/^ function isDraftJsEditor\([\s\S]*?^ }/m)?.[0];+ assert.ok(draftJsEditor, 'Use the production editor classification required by trusted preparation');+ await page.addScriptTag({ content: `${draftJsEditor}\nwindow.axHelpers = { ${entries.join(',\n')} };` });await page.evaluate(() => {for (let i = 1; i <= 3; i++) {const box = document.createElement('div'); box.id = `scroll-box-${i}`;@@ -384,7 +386,7 @@ async function installContentEditableFallback(page, build) {assert.ok(insertion, 'Exercise the real contenteditable fallback with the real monitor');const caretReceipts = source.match(/^ const _nativeChatEmptyCaretReceipts = new WeakMap\(\);$/m)?.[0];assert.ok(caretReceipts, 'Exercise the private production native-chat caret receipt state');- const readers = ['readProseMirrorText', 'readEmptyCaretText', 'isDraftJsEditor', 'readDraftJsText', '_nativeChatCaretContext', '_sameNativeChatCaretContext',+ const readers = ['readProseMirrorText', 'readEmptyCaretText', 'isDraftJsEditor', 'isModelManagedEditor', 'readDraftJsText', '_nativeChatCaretContext', '_sameNativeChatCaretContext','_singleEditableCaretBreak', '_rememberNativeChatEmptyCaret', '_nativeChatCaretValueIsEmpty', '_editableTextValue'].map(name => {const reader = source.match(new RegExp(`^ function ${name}\\([\\s\\S]*?^ }`, 'm'))?.[0];assert.ok(reader, `Exercise the production ${name} readback used by native editor insertion`);@@ -2126,21 +2128,22 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {} finally { await browser.close(); }});- test(`${build}: contenteditable fallback skips remaining insertion after user intervention`, async () => {+ test(`${build}: contenteditable fallback stops after user intervention during a page-handled edit`, async () => {const { browser, page } = await fixture(engine, build);try {await installContentEditableFallback(page, build);await page.evaluate(() => {const editor = document.getElementById('rich-editor');- // Model-backed paragraph editors retain the native delete/insert- // sequence. Ordinary editors now replace in one native operation.- editor.classList.add('ProseMirror'); editor.innerHTML = '<p>Original</p>';+ editor.innerHTML = '<p>Original</p>';+ editor.onbeforeinput = event => {+ event.preventDefault(); editor.append(' page-handled');+ };});await page.waitForTimeout(200);await page.evaluate(() => {feedback = []; const schedule = window.setTimeout;window.setTimeout = (callback, delay, ...args) => {- if (delay === 30) {+ if (delay === SET_FIELD_VERIFY_DELAY_MS) {window.editPaused = true;window.resumeEdit = () => { window.setTimeout = schedule; schedule(callback, 0, ...args); };return 0;@@ -2154,8 +2157,9 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {await page.waitForFunction(() => feedback.some(event => event.source === 'user'));const result = await page.evaluate(async () => { resumeEdit(); return await editResult; });assert.equal(result.success, false, JSON.stringify(result));- assert.equal(result.dispatched, true, 'The completed deletion retains its dispatched outcome');- assert.equal(await page.locator('#rich-editor').textContent(), '');+ assert.equal(result.dispatched, true, 'The page-handled edit retains its dispatched outcome');+ assert.equal(result.mutationMayHaveOccurred, true);+ assert.equal(await page.locator('#rich-editor').textContent(), 'Original page-handled');assert.equal(await page.locator('#field').inputValue(), 'Human intervention');} finally { await browser.close(); }});diff --git a/test/rich-text-frameworks.mjs b/test/rich-text-frameworks.mjsnew file mode 100644index 000000000..c1e0e8271--- /dev/null+++ b/test/rich-text-frameworks.mjs@@ -0,0 +1,466 @@+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { createRequire } from 'node:module';+import path from 'node:path';+import { test } from 'node:test';+import { chromium, firefox } from 'playwright';++// Use real, locally installed React and DraftJS, with no network/CDN fixture.+// An editor-shaped DOM that replaces its children on input cannot reproduce+// React's reconciliation against DraftJS's original text/caret nodes.+const require = createRequire(import.meta.url);+const library = (name, file) => readFile(path.join(path.dirname(require.resolve(`${name}/package.json`)), file), 'utf8');+const scripts = await Promise.all([+ library('react', 'umd/react.development.js'),+ library('react-dom', 'umd/react-dom.development.js'),+ library('immutable', 'dist/immutable.js'),+ library('draft-js', 'dist/Draft.js'),+]);+const css = await library('draft-js', 'dist/Draft.css');+const selector = '#fixture [contenteditable="true"]';+const cases = [+ { name: 'empty replacement', previous: '', text: 'One owned draft.', clear: true },+ { name: 'nonempty replacement', previous: 'Existing draft', text: 'New draft', clear: true },+ { name: 'append', previous: 'Existing draft', text: ' appended once', clear: false },+ { name: 'multiline replacement', previous: 'Old\n\nparagraph', text: 'First\n\nSecond\nThird', clear: true },+ { name: 'multiline append', previous: 'Existing draft', text: '\n\nSecond paragraph', clear: false },+ { name: 'leading and trailing line breaks', previous: '', text: '\nFirst\n\n', clear: true },+ { name: 'only blank lines', previous: '', text: '\n\n', clear: true },+ { name: 'CRLF canonical document breaks', previous: 'Original', text: 'First\r\n\r\nSecond\r\n', clear: true },+ { name: 'empty clear', previous: 'Old\n\nparagraph', text: '', clear: true },+ { name: 'already empty clear', previous: '', text: '', clear: true },+ { name: 'literal markup and unicode', previous: '', text: '<script>window.literalExecuted=true</script> & <b>literal</b> Türkçe ıİşŞğĞüÜöÖçÇ 中文 العربية 🧠 🧑🏽💻 e\u0301', clear: true },+ { name: 'exact whitespace', previous: 'Replace these words', text: ' spaces and\ttab\u00a0nonbreaking ', clear: true },+];++async function fixture(browser, build, { mode = 'concurrent', childFrame = false } = {}) {+ const page = await browser.newPage();+ page.setDefaultTimeout(5000);+ const saves = [], errors = [];+ page.on('pageerror', error => errors.push(error.message));+ await page.route('https://owned-editor.invalid/**', async route => {+ if (route.request().method() === 'POST') {+ saves.push(route.request().postDataJSON());+ await route.fulfill({ contentType: 'application/json', body: '{"saved":true}' });+ } else {+ const outer = childFrame && new URL(route.request().url()).pathname === '/editor';+ await route.fulfill({ contentType: 'text/html', body: outer+ ? '<!doctype html><h1>Owned application</h1><iframe title="Owned draft frame" src="/child" style="width:800px;height:400px;border:0"></iframe>'+ : '<!doctype html><h1>Owned DraftJS application</h1><main id="fixture"></main>' });+ }+ });+ await page.goto('https://owned-editor.invalid/editor');+ const document = childFrame ? await page.locator('iframe').elementHandle().then(handle => handle.contentFrame()) : page;+ await document.waitForSelector('#fixture', { state: 'attached' });+ await document.addStyleTag({ content: `${css}\n#fixture { width: 650px; } .DraftEditor-root { border: 1px solid; min-height: 120px; } .public-DraftEditor-content { min-height: 120px; }` });+ for (const content of scripts) await document.addScriptTag({ content });+ await document.evaluate(({ build, mode }) => {+ const api = { runtime: { getURL: value => value, onMessage: { addListener: handler => { window.qaHandler = handler; } } } };+ window[build === 'firefox' ? 'browser' : 'chrome'] = api;+ window.qaCall = (action, params) => new Promise((resolve, reject) => {+ const timer = setTimeout(() => reject(new Error(`Content handler did not answer ${action}`)), 5000);+ qaHandler({ target: 'content', action, params }, {}, result => { clearTimeout(timer); resolve(result); });+ });+ window.qaEvents = []; window.qaCommands = []; window.qaCorruptPaste = false;+ const host = document.querySelector('#fixture');+ const root = mode === 'concurrent' ? ReactDOM.createRoot(host) : null;+ let revision = 0;+ const App = ({ value }) => {+ const [editorState, setEditorState] = React.useState(() => Draft.EditorState.createWithContent(Draft.ContentState.createFromText(value)));+ window.qaEditorState = editorState;+ window.qaReplaceEditorText = text => setEditorState(Draft.EditorState.createWithContent(Draft.ContentState.createFromText(text)));+ const onChange = next => {+ if (qaCorruptPaste && next.getCurrentContent().getPlainText('\n').includes('\n')) {+ qaCorruptPaste = false;+ next = Draft.EditorState.createWithContent(Draft.ContentState.createFromText(next.getCurrentContent().getPlainText('\n') + '!'));+ }+ window.qaEditorState = next; setEditorState(next);+ };+ return React.createElement(React.Fragment, null,+ React.createElement(Draft.Editor, { editorState, onChange, ariaLabel: 'Owned editor', placeholder: 'Enter owned draft' }),+ React.createElement('button', { id: 'save', onClick: async () => {+ const value = editorState.getCurrentContent().getPlainText('\n');+ await fetch('/save', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ value }) });+ window.qaSavedValue = value;+ } }, 'Save owned draft'));+ };+ window.qaMount = value => {+ const app = React.createElement(App, { key: ++revision, value });+ if (root) ReactDOM.flushSync(() => root.render(app));+ else ReactDOM.render(app, host);+ qaEvents = []; qaCommands = []; qaCorruptPaste = false; window.qaSavedValue = undefined;+ };+ window.qaSnapshot = () => {+ const editor = document.querySelector('#fixture [contenteditable="true"]');+ return { model: qaEditorState.getCurrentContent().getPlainText('\n'), text: editor?.textContent,+ html: editor?.innerHTML, blocks: editor ? [...editor.querySelectorAll('[data-block="true"]')].map(block => block.textContent) : [],+ modelBlocks: qaEditorState.getCurrentContent().getBlocksAsArray().map(block => block.getText()),+ events: qaEvents, commands: qaCommands,+ interpretedMarkup: !!editor?.querySelector('script,b'), executed: !!window.literalExecuted };+ };+ for (const type of ['beforeinput', 'input', 'paste']) host.addEventListener(type, event => {+ qaEvents.push({ type, trusted: event.isTrusted, inputType: event.inputType,+ data: type === 'paste' ? event.clipboardData?.getData('text/plain') : event.data });+ }, true);+ const execCommand = document.execCommand.bind(document);+ document.execCommand = (command, showUI, value) => { qaCommands.push({ command, value }); return execCommand(command, showUI, value); };+ qaMount('');+ }, { build, mode });+ for (const file of ['accessibility-tree.js', 'rich-text-toolbar-heuristic.js', 'content.js']) {+ await document.addScriptTag({ content: await readFile(new URL(`../src/${build}/src/content/${file}`, import.meta.url), 'utf8') });+ }+ return { page, document, saves, errors, frameId: childFrame ? 7 : 0 };+}++async function reference(document) {+ const tree = await document.evaluate(() => qaCall('get_accessibility_tree', { filter: 'all', maxDepth: 15, maxChars: 20000 }));+ const ref = String(tree.pageContent).match(/textbox "Owned editor" \[(ref_\d+)\]/)?.[1];+ assert.ok(ref, JSON.stringify(tree));+ return ref;+}++async function contentWrite(document, action, args) {+ return document.evaluate(({ action, args, selector }) => qaCall(action,+ action === 'type' ? { selector, text: args.text, clear: args.clear } : args), { action, args, selector });+}++async function assertApplication(f, expected) {+ const state = await f.document.evaluate(() => qaSnapshot());+ assert.equal(state.model, expected, 'Compare DraftJS EditorState, independent of the extension readback.');+ assert.deepEqual(state.blocks, state.modelBlocks, 'React-rendered document blocks must match the actual model.');+ assert.equal(state.blocks.join('\n'), expected);+ assert.equal(state.text, state.modelBlocks.join(''), 'The DOM must contain no additional unmarked text outside the model blocks.');+ assert.equal(state.interpretedMarkup, false); assert.equal(state.executed, false);+ assert.deepEqual(f.errors, [], 'Native editing must not corrupt React reconciliation or DraftJS offset keys.');+ const count = f.saves.length;+ await f.document.locator('#save').click();+ await f.document.waitForFunction(expected => qaSavedValue === expected, expected);+ assert.equal(f.saves.length, count + 1);+ assert.equal(f.saves.at(-1).value, expected, 'Compare the application save POST, independent of DOM normalization.');+ return state;+}++for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {+ test(`${build}: actual React/DraftJS uses page-owned multiline edits and rejects unsafe DOM commands`, async t => {+ const browser = await engine.launch({ headless: true });+ try {+ const f = await fixture(browser, build);+ for (const action of ['type', 'type_ax', 'set_field']) for (const item of cases) await t.test(`${action}: ${item.name}`, async () => {+ await f.document.evaluate(previous => qaMount(previous), item.previous);+ const before = await f.document.evaluate(() => qaSnapshot());+ const ref_id = await reference(f.document);+ const result = await contentWrite(f.document, action, { ref_id, text: item.text, clear: item.clear });+ const multiline = /[\r\n]/.test(item.text);+ if (multiline) {+ assert.equal(result.success, true, JSON.stringify(result)); assert.equal(result.verified, true);+ assert.equal(result.pageHandledPaste, true);+ } else {+ assert.equal(result.success, false, JSON.stringify(result));+ assert.equal(result.dispatched, false); assert.equal(result.noDispatch, true);+ assert.notEqual(result.outcomeUnknown, true);+ }+ const expected = multiline ? (item.clear ? '' : item.previous) + item.text.replace(/\r\n?/g, '\n') : item.previous;+ const state = await assertApplication(f, expected);+ if (multiline) {+ assert.equal(state.events.length, 1); assert.equal(state.events[0].type, 'paste');+ assert.equal(state.events[0].data, item.text.replace(/\r\n?/g, '\n'));+ } else {+ assert.equal(state.html, before.html, 'The original DraftJS document nodes survive the failed content write.');+ assert.deepEqual(state.events, [], 'No synthetic beforeinput or native input is sent ahead of trusted typing.');+ }+ assert.deepEqual(state.commands, [], 'No HTML wrapper or plain execCommand mutation enters framework-owned DOM.');+ });+ await t.test('a page-modified paste is uncertain and sends no second mutation', async () => {+ await f.document.evaluate(() => { qaMount(''); qaCorruptPaste = true; });+ const args = { ref_id: await reference(f.document), text: 'First\nSecond', clear: true };+ const result = await contentWrite(f.document, 'type_ax', args);+ assert.equal(result.success, false); assert.equal(result.dispatched, true);+ assert.equal(result.outcomeUnknown, true); assert.equal(result.retryable, false);+ assert.equal(result.recoveryRequired, 'verify_or_restore_field');+ const state = await assertApplication(f, args.text + '!');+ assert.equal(state.events.filter(event => event.type === 'paste').length, 1);+ assert.deepEqual(state.commands, []);+ });+ await t.test('an ignored paste stays uncertain and never falls through to DOM commands', async () => {+ await f.document.evaluate(() => {+ qaMount('Unchanged draft');+ document.querySelector('#fixture').addEventListener('paste', event => event.stopImmediatePropagation(), { capture: true, once: true });+ });+ const args = { ref_id: await reference(f.document), text: 'First\nSecond', clear: true };+ const result = await contentWrite(f.document, 'set_field', args);+ assert.equal(result.success, false); assert.equal(result.dispatched, true);+ assert.notEqual(result.noDispatch, true); assert.equal(result.outcomeUnknown, true); assert.equal(result.retryable, false);+ const state = await assertApplication(f, 'Unchanged draft');+ assert.equal(state.events.filter(event => event.type === 'paste').length, 1);+ assert.deepEqual(state.commands, []);+ });+ } finally { await browser.close(); }+ });+}++test('Chrome: real trusted input updates DraftJS once through production selector, AX and frame routes', async t => {+ const previousChrome = globalThis.chrome, previousBrowser = globalThis.browser;+ const area = { get: async () => ({}), set: async () => {}, remove: async () => {} };+ const api = { storage: { local: area, session: area }, runtime: { getURL: value => value }, tabs: {} };+ globalThis.chrome = 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 originalAttach = cdpClient.attach, originalCommand = cdpClient.sendCommand;+ const browser = await chromium.launch({ headless: true });+ try {+ for (const options of [{ mode: 'concurrent' }, { mode: 'legacy' }, { mode: 'concurrent', childFrame: true }]) {+ const f = await fixture(browser, 'chrome', options);+ const session = await f.page.context().newCDPSession(f.page);+ const agent = new Agent({});+ const commands = [], messages = [];+ let loseResponse = false;+ api.tabs.get = async id => ({ id, url: f.page.url() });+ api.tabs.sendMessage = (_tab, message, target = {}) => {+ messages.push({ action: message.action, frameId: target.frameId || 0 });+ assert.equal(target.frameId || 0, f.frameId, 'Content preparation/readback remains bound to the original document frame.');+ return f.document.evaluate(message => qaCall(message.action, message.params), message);+ };+ cdpClient.attach = async () => {};+ cdpClient.sendCommand = async (_tab, method, params) => {+ commands.push({ method, params });+ const result = await session.send(method, params);+ if (loseResponse && method === 'Input.insertText') { loseResponse = false; throw new Error('Owned input response lost after dispatch'); }+ return result;+ };+ const actions = f.frameId ? ['type_ax', 'set_field'] : ['type_text', 'type_ax', 'set_field'];+ for (const action of actions) for (const item of cases) await t.test(`${options.mode}/${f.frameId ? 'iframe' : 'main'}/${action}: ${item.name}`, async () => {+ await f.document.evaluate(previous => qaMount(previous), item.previous);+ commands.length = 0; messages.length = 0;+ const ref_id = await reference(f.document);+ const args = { ref_id, text: item.text, clear: item.clear };+ let result;+ if (action === 'type_text') result = await cdpClient.typeText(41, selector, item.text, item.clear);+ else {+ const initial = await contentWrite(f.document, action, args);+ if (!/[\r\n]/.test(item.text)) {+ assert.equal(initial.noDispatch, true, JSON.stringify(initial));+ assert.equal(await f.document.evaluate(() => qaEditorState.getCurrentContent().getPlainText('\n')), item.previous);+ }+ result = await agent._maybeFallbackFieldWithCdpImpl(41, action, args, initial, {}, null, f.frameId);+ }+ assert.equal(result.success, true, JSON.stringify({ result, state: await f.document.evaluate(() => qaSnapshot()) })); assert.equal(result.verified, true);+ const expected = (item.clear ? '' : item.previous) + item.text.replace(/\r\n?/g, '\n');+ const state = await assertApplication(f, expected);+ assert.deepEqual(state.commands, []);+ assert.ok(state.events.every(event => event.trusted || event.type === 'paste'), 'Only the explicit page-owned paste event may be synthetic.');+ assert.ok(commands.filter(command => command.method === 'Input.insertText').length <= 1, 'Insert the requested text only once.');+ if (/[\r\n]/.test(item.text)) {+ assert.equal(result.pageHandledPaste, true);+ assert.equal(state.events.filter(event => event.type === 'paste').length, 1);+ assert.equal(commands.filter(command => command.method === 'Input.insertText').length, 0, 'Never follow page-handled paste with native multiline insertion.');+ } else if (item.text) {+ const insertions = commands.filter(command => command.method === 'Input.insertText');+ assert.equal(insertions.length, 1); assert.equal(insertions[0].params.text, item.text);+ }+ if (f.frameId) assert.equal(commands.some(command => command.method === 'Input.dispatchMouseEvent'), false,+ 'Frame-local rectangles must not become a top-document coordinate click.');+ });+ await t.test(`${options.mode}/${f.frameId ? 'iframe' : 'main'}: unknown dispatch never inserts a second copy`, async () => {+ await f.document.evaluate(() => qaMount(''));+ commands.length = 0;+ const args = { ref_id: await reference(f.document), text: 'Exactly one owned draft.', clear: true };+ const initial = await contentWrite(f.document, 'set_field', args);+ loseResponse = true;+ const unknown = await agent._maybeFallbackFieldWithCdpImpl(41, 'set_field', args, initial, {}, null, f.frameId);+ assert.equal(unknown.success, false); assert.equal(unknown.dispatched, true); assert.equal(unknown.noDispatch, false);+ assert.equal(commands.filter(command => command.method === 'Input.insertText').length, 1);+ await assertApplication(f, args.text);+ const retry = await agent._maybeFallbackFieldWithCdpImpl(41, 'set_field', args,+ { ...unknown, _expectedValue: args.text }, {}, null, f.frameId);+ assert.equal(retry.success, false); assert.equal(retry.outcomeUnknown, true); assert.equal(retry.repeatBlocked, true);+ assert.equal(commands.filter(command => command.method === 'Input.insertText').length, 1);+ await assertApplication(f, args.text);+ });+ await t.test(`${options.mode}/${f.frameId ? 'iframe' : 'main'}: a trusted multiline request uses one page-owned paste`, async () => {+ await f.document.evaluate(() => qaMount('Existing draft'));+ commands.length = 0;+ const args = { ref_id: await reference(f.document), text: '\n\nAppend once\n', clear: false };+ // Older content generations can still ask the background for trusted+ // typing. Exercise that production fallback with the actual current+ // preparation and paste handlers, not a synthetic document renderer.+ const initial = { success: false, verified: false, noDispatch: true, dispatched: false,+ _expectedValue: 'Existing draft' + args.text, trustedTypeRequired: true, error: 'Trusted editor input required' };+ const result = await agent._maybeFallbackFieldWithCdpImpl(41, 'type_ax', args, initial, {}, null, f.frameId);+ assert.equal(result.success, true, JSON.stringify(result)); assert.equal(result.verified, true);+ assert.equal(result.pageHandledPaste, true);+ const state = await assertApplication(f, 'Existing draft' + args.text);+ assert.equal(state.events.filter(event => event.type === 'paste').length, 1);+ assert.equal(commands.filter(command => command.method === 'Input.insertText').length, 0);+ });+ if (!f.frameId) await t.test(`${options.mode}: a focus handler cannot become a new multiline append baseline`, async () => {+ await f.document.evaluate(() => {+ qaMount('Original baseline');+ document.querySelector('#fixture [contenteditable="true"]').addEventListener('focus', () => {+ ReactDOM.flushSync(() => qaReplaceEditorText('Changed by application focus'));+ }, { once: true });+ });+ commands.length = 0;+ const result = await cdpClient.typeText(41, selector, '\nNever append', false);+ assert.equal(result.success, false, JSON.stringify(result)); assert.equal(result.dispatched, true);+ assert.equal(result.outcomeUnknown, true); assert.equal(result.retryable, false);+ const state = await assertApplication(f, 'Changed by application focus');+ assert.equal(state.events.filter(event => event.type === 'paste').length, 0);+ assert.equal(commands.some(command => command.method === 'Input.insertText'), false);+ });+ await session.detach(); await f.page.close();+ }+ } finally {+ cdpClient.attach = originalAttach; cdpClient.sendCommand = originalCommand;+ globalThis.chrome = previousChrome; globalThis.browser = previousBrowser;+ await browser.close();+ }+});++test('Chrome: certified production monitor owns actual DraftJS paste and rejects a stale page action', async t => {+ const previousChrome = globalThis.chrome, previousBrowser = globalThis.browser;+ const { installPageFeedback, hasPageAgentDispatchOwner } = await import('../src/chrome/src/agent/page-feedback.js');+ const { cdpClient } = await import('../src/chrome/src/cdp/cdp-client.js');+ const { Agent } = await import('../src/chrome/src/agent/agent.js');+ const originalAttach = cdpClient.attach, originalCommand = cdpClient.sendCommand;+ const browser = await chromium.launch({ headless: true });+ const tabId = 73;+ let f, session, host, entryRoute;+ const priorSession = cdpClient.sessions.get(tabId);+ const compatibilityAgent = new Agent({});+ class Host {+ static STATE_CHANGE_TOOLS = new Set(['type_text', 'type_ax']);+ isRunning() { return true; }+ _checkAbort() { return false; }+ _throwIfAborted() {}+ _persist() {}+ _effectiveRunMode() { return 'act'; }+ _appOwnedUserMessage(content, webbrainAppOwnedKind) { return { role: 'user', content, webbrainAppOwnedKind }; }+ _wrapUntrusted(_kind, content) { return content; }+ _finalizeToolResultOnce(_tab, _name, _args, result) { return result; }+ async executeTool(_tab, name, args, _onUpdate, context) {+ if (name === 'type_text') {+ await cdpClient.attach(tabId);+ return cdpClient.typeText(tabId, args.selector, args.text, args.clear, null, {+ beforeDispatch: () => { context._contentActionDispatchState.started = true; },+ });+ }+ if (entryRoute === 'trusted AX request') return compatibilityAgent._maybeFallbackFieldWithCdpImpl(tabId, name, args,+ { success: false, verified: false, noDispatch: true, dispatched: false, trustedTypeRequired: true,+ _expectedValue: (args.clear ? '' : 'Existing\nlast') + args.text }, context);+ return contentWrite(f.document, name, args);+ }+ }+ installPageFeedback(Host);+ const commands = [], messages = [], feedback = [];+ const api = { runtime: {}, tabs: {+ get: async () => ({ id: tabId, url: f.page.url() }),+ sendMessage: (_tab, message, target = {}) => {+ assert.equal(target.frameId || 0, 0);+ messages.push(message);+ return f.document.evaluate(message => qaCall(message.action, message.params || {}, message), message);+ },+ }, webNavigation: { getAllFrames: async () => [{ frameId: 0, documentId: 'owned-certified-draft', url: f.page.url() }] },+ debugger: { sendCommand: (_target, method, params, callback) => {+ commands.push({ method, params });+ session.send(method, params).then(callback, error => {+ api.runtime.lastError = { message: error.message }; callback(); delete api.runtime.lastError;+ });+ } } };+ globalThis.chrome = globalThis.browser = api;+ try {+ for (const route of ['content', 'CDP selector', 'trusted AX request']) for (const clear of [true, false]) await t.test(`${route}: ${clear ? 'replace' : 'append'}`, async () => {+ f = await fixture(browser, 'chrome');+ entryRoute = route;+ session = await f.page.context().newCDPSession(f.page);+ host = new Host();+ commands.length = 0; messages.length = 0; feedback.length = 0;+ cdpClient.attach = async () => cdpClient.sessions.set(tabId, {});+ cdpClient.sendCommand = originalCommand;+ await f.document.evaluate(() => {+ qaMount('Existing\nlast');+ const editor = document.querySelector('#fixture [contenteditable="true"]');+ // Existing action bindings include geometry. Keep it fixed so this+ // regression exercises dispatch ownership independently of layout.+ editor.style.height = '180px';+ const listeners = [window.qaHandler];+ chrome.runtime.onMessage = { addListener: listener => listeners.push(listener), removeListener: listener => {+ const index = listeners.indexOf(listener); if (index >= 0) listeners.splice(index, 1);+ } };+ chrome.runtime.sendMessage = message => window.qaOwnedBackground(message);+ window.qaCall = (action, params = {}, original = {}) => new Promise((resolve, reject) => {+ const timeout = setTimeout(() => reject(new Error(`Missing certified monitor response ${action}`)), 5000);+ let answered = false;+ const respond = result => { answered = true; clearTimeout(timeout); resolve(result); };+ for (const listener of listeners) {+ const asynchronous = listener({ ...original, target: 'content', action, params }, {}, respond);+ if (answered || asynchronous === true) return;+ }+ clearTimeout(timeout); resolve(undefined);+ });+ });+ await f.page.exposeFunction('qaOwnedBackground', message => {+ const sender = { tab: { id: tabId }, frameId: 0, documentId: 'owned-certified-draft', url: f.page.url() };+ if (message.action === 'get_page_monitor_state') return host.pageMonitorState(sender, message.documentToken);+ if (message.action === 'page_feedback') { feedback.push(message.feedback); return host.observePageFeedback(sender, message.feedback); }+ return {};+ });+ await f.document.addScriptTag({ content: await readFile(new URL('../src/chrome/src/content/page-monitor.js', import.meta.url), 'utf8') });+ await host._beginPageFeedbackRun(tabId, 'certified-draft');+ await f.document.waitForFunction(() => __wbPageMonitor.active);+ await f.page.waitForTimeout(180);+ const run = host._pageFeedbackRuns.get(tabId);+ run.events.clear();+ await host._capturePageFeedbackModelState(tabId, []);+ assert.ok(run.modelState.actionBinding?.snapshotToken, 'Capture the production pre-action document certificate.');+ assert.equal(hasPageAgentDispatchOwner(tabId), true);+ const ref_id = await reference(f.document);+ const name = route === 'CDP selector' ? 'type_text' : 'type_ax';+ const args = { ...(route === 'CDP selector' ? { selector } : { ref_id }), text: 'First\n\nLast\n', clear };+ feedback.length = 0; commands.length = 0; messages.length = 0;+ const result = await host.executeTool(tabId, name, args);+ const expected = (clear ? '' : 'Existing\nlast') + args.text;+ await f.page.waitForTimeout(180);+ const state = await f.document.evaluate(() => qaSnapshot());+ assert.equal(result.success, true, JSON.stringify({ result, state, feedback }));+ assert.equal(result.verified, true); assert.equal(result.pageHandledPaste, true);+ assert.equal(state.model, expected); assert.deepEqual(state.blocks, state.modelBlocks);+ assert.equal(state.text, state.modelBlocks.join('')); assert.deepEqual(state.commands, []);+ assert.equal(state.events.filter(event => event.type === 'paste').length, 1);+ assert.equal(feedback.some(item => item.source !== 'agent'), false, JSON.stringify(feedback));+ assert.equal(run.events.size, 0, 'Target-only paste leaves no intervention or unrelated page feedback pending.');+ assert.equal(commands.some(command => command.method === 'Input.insertText'), false);+ if (route === 'CDP selector') {+ assert.ok(commands.some(command => command.method === 'Runtime.callFunctionOn'+ && command.params.functionDeclaration.includes('beforePageAgentDomAction(pageGuard, phase, el)')),+ 'Run the packaged DOM-action source against the real active owner, rather than a mocked guard.');+ assert.ok(messages.some(message => message.action === 'page_monitor_dispatch' && message.params?.fenceOnly === true));+ }+ if (route === 'trusted AX request') assert.equal(messages.filter(message => message.action === 'ax_paste_draft').length, 1,+ 'Exercise the production internal compatibility handler with its actual monitor action classification.');+ // Certify the updated document before the independent external change.+ // The following rejection must be caused by stale page identity, rather+ // than by reusing the pre-paste editor value or a user save-button click.+ await host._capturePageFeedbackModelState(tabId, []);+ await f.document.evaluate(() => {+ document.querySelector('#fixture [contenteditable="true"]').setAttribute('aria-label', 'Unobserved editor identity');+ });+ await f.page.waitForTimeout(180);+ const blocked = await host.executeTool(tabId, name, { ...args, text: '\nBlocked copy', clear: false });+ assert.equal(blocked.success, false, JSON.stringify(blocked)); assert.equal(blocked.noDispatch, true);+ assert.equal(blocked.dispatched, false);+ assert.equal(await f.document.evaluate(() => qaEditorState.getCurrentContent().getPlainText('\n')), expected);+ assert.equal(await f.document.evaluate(() => qaEvents.filter(event => event.type === 'paste').length), 1);+ assert.ok(feedback.some(item => item.source !== 'agent'), 'An independent page identity change must remain externally attributed.');+ host._finishPageFeedbackRun(tabId);+ await f.document.evaluate(() => __wbPageMonitor.dispose());+ await assertApplication(f, expected);+ await session.detach(); await f.page.close();+ });+ } finally {+ host?._finishPageFeedbackRun(tabId);+ cdpClient.attach = originalAttach; cdpClient.sendCommand = originalCommand;+ if (priorSession) cdpClient.sessions.set(tabId, priorSession); else cdpClient.sessions.delete(tabId);+ globalThis.chrome = previousChrome; globalThis.browser = previousBrowser;+ await browser.close();+ }+});diff --git a/test/run.js b/test/run.jsindex 9f28062b9..efd6cccce 100644--- a/test/run.js+++ b/test/run.js@@ -81826,7 +81826,7 @@ test('Chrome controlled-field fallback is ref-bound, trusted, verified, and subm? content.indexOf("'set_field': async () => {", branchStart): content.indexOf("'ax_prepare_field_for_trusted_type':", branchStart);const branch = content.slice(branchStart, branchEnd);- assert.match(branch, /el\.isContentEditable[\s\S]*readProseMirrorText\(el\) === null[\s\S]*_insertContentEditableText[\s\S]*trustedTypeRequired: true[\s\S]*_expectedValue/, `chrome: ${toolName} ordinary editors use native literal insertion while model-backed editors retain trusted typing`);+ assert.match(branch, /el\.isContentEditable[\s\S]*!isModelManagedEditor\(el\)[\s\S]*_insertContentEditableText[\s\S]*trustedTypeRequired: true[\s\S]*_expectedValue/, `chrome: ${toolName} ordinary editors use native literal insertion while model-backed editors retain trusted typing`);assert.doesNotMatch(branch, /document\.execCommand\('insertText'/, `chrome: ${toolName} must not accept synthetic contenteditable DOM text as verified input`);}});diff --git a/test/ui-content-lifecycle.mjs b/test/ui-content-lifecycle.mjsindex 0bc7beb0c..e84bf180b 100644--- a/test/ui-content-lifecycle.mjs+++ b/test/ui-content-lifecycle.mjs@@ -210,7 +210,7 @@ if (process.argv.includes('--dom')) for (const [engineName, engine] of Object.enconst settleDelay = source.match(/^ const SET_FIELD_VERIFY_DELAY_MS = \d+;$/m)?.[0];assert.ok(settleDelay, 'Use the production page-handler render delay');const functions = [ownInputScope, caretReceipts, settleDelay].join('\n') + '\n' + [- 'readProseMirrorText', 'readEmptyCaretText', 'isDraftJsEditor', 'readDraftJsText',+ 'readProseMirrorText', 'readEmptyCaretText', 'isDraftJsEditor', 'isModelManagedEditor', 'readDraftJsText','_nativeChatCaretContext', '_sameNativeChatCaretContext', '_singleEditableCaretBreak','_rememberNativeChatEmptyCaret', '_nativeChatCaretValueIsEmpty', '_editableTextValue','_insertContentEditableText', '_typeTextInner',@@ -282,14 +282,15 @@ if (process.argv.includes('--dom')) for (const [engineName, engine] of Object.enassert.equal(await page.evaluate(() => window.events.some(event => event.type === 'input')), false);checked++;- // These deletion-phase checks exercise a model-backed paragraph editor.+ // A model-owned document must reach trusted input without a DOM edit.await setup('<p>Original <strong>format</strong></p>', '', true);const replacement = await type({ text: 'New\ntext', clear: true });- assert.equal(replacement.success, true, `${engineName}/${build}: ${JSON.stringify(replacement)}`);- assert.equal(replacement.verified, true);+ assert.equal(replacement.success, false, `${engineName}/${build}: ${JSON.stringify(replacement)}`);+ assert.equal(replacement.noDispatch, true);+ assert.equal(replacement.trustedTypeRequired, true);const gates = await page.evaluate(() => window.events.filter(event => event.type === 'beforeinput'));- assert.equal(gates[0].inputType, 'deleteContentBackward');- assert.ok(gates.find(event => event.inputType === 'insertText' && !event.html.includes('Original')));+ assert.equal(gates.length, 0);+ assert.equal(await page.locator('#editor').innerHTML(), '<p>Original <strong>format</strong></p>');checked++;for (const text of [' leading middle trailing ', 'a\n\nb\n', '\n']) {@@ -308,15 +309,15 @@ if (process.argv.includes('--dom')) for (const [engineName, engine] of Object.enawait setup('<p>Original</p>', 'restore-deletion', true);const restored = await type({ text: 'Never inserted', clear: true });assert.equal(restored.success, false);- assert.equal(restored.mutationMayHaveOccurred, true);- assert.equal(await page.locator('#editor').innerText(), 'Restored');+ assert.equal(restored.noDispatch, true);+ assert.equal(await page.locator('#editor').innerText(), 'Original');assert.equal(await page.evaluate(() => window.events.some(event => event.inputType === 'insertText')), false);checked++;await setup('<p>Original</p>', 'retarget-after-delete', true);const movedAfterDelete = await type({ text: 'Never inserted', clear: true });assert.equal(movedAfterDelete.success, false);- assert.equal(movedAfterDelete.mutationMayHaveOccurred, true, 'clear happened before the target selection changed');+ assert.equal(movedAfterDelete.noDispatch, true, 'model-owned nodes are untouched before trusted input');assert.equal(await page.locator('#other-editor').innerText(), 'Untouched');assert.equal(await page.evaluate(() => window.events.some(event => event.inputType === 'insertText')), false);checked++;