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: press a covered editor unless it already has the focus
Claude03e6ea30d739
diff --git a/docs/page-feedback-monitor.md b/docs/page-feedback-monitor.mdindex 75aab41d4..4b4f403f3 100644--- a/docs/page-feedback-monitor.md+++ b/docs/page-feedback-monitor.md@@ -103,10 +103,14 @@ Steer or grant authorization. Enter and Alt+Enter retain their existing behaviorclick on it is refused as `target_uncovered`. (Without this certificate sucha field had none, and a click on it was judged by the legacy rules, whichcannot see that the click would land on the cover.) Chrome's fallback then- skips its press, because `ax_prepare_field_for_trusted_type` reports the- field as not `pressable` when its centre hit does not reach the field- without crossing an activator, and types into the focused field through the- same receiver checks.+ skips its press: `ax_prepare_field_for_trusted_type` reports whether the+ centre hit reaches the field without crossing an activator (`pressable`),+ whether what is there instead lies outside the field (`centreCovered`), and+ whether the field had the focus before that preparation (`focusedBefore`).+ Only a field that already had the focus and is covered from outside is not+ pressed; it is typed into through the same receiver checks. Any other field+ is pressed as before, and the monitor refuses a press whose receiver is not+ the field itself, such as a native control inside a ProseMirror editor.A recent owned scroll can reconcile one native subpixel visual-viewportnotification within 200 ms when the original target, hit, rectangle, values,document scroll, full-size viewport, scale and DPR remain unchanged. Thisdiff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 2ab37bd00..21a3807d9 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -48227,12 +48227,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis._throwIfAborted(abortSignal);// Child-frame rectangles are frame-relative. Focus/selection are already// bound to the exact editor there; do not click them as top-frame points.- // Nor is an editor pressed where the page covers its centre (X's- // formatting bubble after an earlier click): that press would reach the- // cover. The page monitor lets such an editor take text only when it- // already had keyboard focus when the model chose it.+ // Nor is an editor pressed that already had the focus while something+ // outside it covers its centre (X's formatting bubble after an earlier+ // click): that press would reach the cover, and the focused editor+ // needs none. The page monitor lets such an editor take text only when+ // it had the focus when the model chose it. Any other editor is pressed+ // as before, and the monitor refuses a press whose receiver is not the+ // editor itself (a control inside it, or a cover).+ const coveredWhileFocused = prepared.pressable === false && prepared.centreCovered === true && prepared.focusedBefore === true;if (frameId === 0 && prepared.contentEditable && prepared.rect?.w > 0 && prepared.rect?.h > 0- && prepared.pressable !== false) {+ && !coveredWhileFocused) {const x = prepared.rect.x + prepared.rect.w / 2;const y = prepared.rect.y + prepared.rect.h / 2;this._throwIfAborted(abortSignal);diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 252464b95..c2686b125 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -10355,6 +10355,10 @@if (!el || !el.isConnected) return { success: false, error: `ref_id ${ref_id} is stale` };const typeable = el.isContentEditable || el.tagName === 'INPUT' || el.tagName === 'TEXTAREA';if (!typeable) return { success: false, error: `ref_id ${ref_id} is not a text field` };+ // Whether the field already had the focus before this preparation.+ let focusedBefore = document.activeElement;+ while (focusedBefore?.shadowRoot?.activeElement) focusedBefore = focusedBefore.shadowRoot.activeElement;+ focusedBefore = focusedBefore === el;_withTypingPreparation('scroll', el, () => { try { el.scrollIntoView({ block: 'center', inline: 'center' }); } catch {} });_withTypingPreparation('focus', el, () => { try { el.focus({ preventScroll: true }); } catch {} });window.__wbPageMonitor?.beforeLocalDispatch({ preparation: true, kind: 'focus', target: el });@@ -10376,8 +10380,9 @@|| (el.getAttribute && el.getAttribute('aria-expanded') === 'true');const rect = el.getBoundingClientRect();// Whether a press at the field's centre reaches the field or its- // plain contents, rather than something the page drew over it (X- // draws its formatting bubble where its editor was clicked).+ // plain contents (pressable), and whether what is there instead is+ // outside the field (centreCovered), as the formatting bubble X+ // draws where its editor was clicked, rather than a control inside it.const centreX = rect.left + rect.width / 2, centreY = rect.top + rect.height / 2;let centreHit = document.elementFromPoint(centreX, centreY);for (let depth = 0; depth < 24 && centreHit?.shadowRoot; depth++) {@@ -10385,10 +10390,10 @@if (!inner || inner === centreHit) break;centreHit = inner;}- let pressable = false;+ let pressable = false, insideField = false, crossedActivator = false;for (let node = centreHit, depth = 0; node && depth < 256; node = node.parentElement || node.getRootNode?.().host, depth++) {- if (node === el) { pressable = true; break; }- if (node.matches?.('button,a[href],input,textarea,select,summary,[onclick],[tabindex],[role="button"],[role="link"],[role="checkbox"],[role="radio"],[role="switch"],[role="tab"],[role="menuitem"]')) break;+ if (node === el) { insideField = true; pressable = !crossedActivator; break; }+ if (node.matches?.('button,a[href],input,textarea,select,summary,[onclick],[tabindex],[role="button"],[role="link"],[role="checkbox"],[role="radio"],[role="switch"],[role="tab"],[role="menuitem"]')) crossedActivator = true;}return {success: true,@@ -10397,6 +10402,8 @@isCombobox,contentEditable: !!el.isContentEditable,pressable,+ centreCovered: !insideField,+ focusedBefore,...(isDraftJsEditor(el) ? { editorKind: 'draftjs' } : {}),selectionMode: el.isContentEditable && selectionMode === 'end' ? 'end' : 'all',rect: {