Skip to content

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

fix: detect ARIA toolbars and ignore modal-open page state

Barack Sokullucf6656c03576
diff --git a/src/chrome/src/content/accessibility-tree.js b/src/chrome/src/content/accessibility-tree.js
index bb1e8f4a0..d3c8eb580 100644
--- a/src/chrome/src/content/accessibility-tree.js
+++ b/src/chrome/src/content/accessibility-tree.js
@@ -1635,7 +1635,7 @@
'[data-overlay]',
'.modal.show',
'.modal-overlay',
- '[class*="modal"][class*="open"]',
+ '.modal.open',
'[class*="DialogContent"]',
'[class*="ModalContent"]',
'[data-state="open"][role="dialog"]',
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index 149395bf9..3e27219f0 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -340,7 +340,7 @@
if (!targetInTopDock) top = Math.max(top, parsePadding(bodyStyle.scrollPaddingTop));
if (!targetInBottomDock) bottom = Math.max(bottom, parsePadding(bodyStyle.scrollPaddingBottom));
}
- const candidates = doc.querySelectorAll('header, nav, [role="banner"], [role="navigation"], [class*="header" i], [class*="navbar" i], [class*="toolbar" i]');
+ const candidates = doc.querySelectorAll('header, nav, [role="banner"], [role="navigation"], [role="toolbar"], [class*="header" i], [class*="navbar" i], [class*="toolbar" i]');
const vw = view.innerWidth || 800;
const vh = view.innerHeight || 600;
const topRects = [];
diff --git a/src/firefox/src/content/accessibility-tree.js b/src/firefox/src/content/accessibility-tree.js
index bb1e8f4a0..d3c8eb580 100644
--- a/src/firefox/src/content/accessibility-tree.js
+++ b/src/firefox/src/content/accessibility-tree.js
@@ -1635,7 +1635,7 @@
'[data-overlay]',
'.modal.show',
'.modal-overlay',
- '[class*="modal"][class*="open"]',
+ '.modal.open',
'[class*="DialogContent"]',
'[class*="ModalContent"]',
'[data-state="open"][role="dialog"]',
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 9dca2c54b..3f32c9835 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -599,7 +599,7 @@
if (!targetInTopDock) top = Math.max(top, parsePadding(bodyStyle.scrollPaddingTop));
if (!targetInBottomDock) bottom = Math.max(bottom, parsePadding(bodyStyle.scrollPaddingBottom));
}
- const candidates = doc.querySelectorAll('header, nav, [role="banner"], [role="navigation"], [class*="header" i], [class*="navbar" i], [class*="toolbar" i]');
+ const candidates = doc.querySelectorAll('header, nav, [role="banner"], [role="navigation"], [role="toolbar"], [class*="header" i], [class*="navbar" i], [class*="toolbar" i]');
const vw = view.innerWidth || 800;
const vh = view.innerHeight || 600;
const topRects = [];
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index 497028251..f44949ad9 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -1628,16 +1628,22 @@ function assertGmailComposeRecipientTree(tree, label) {
async function assertNestedModalHoistedOnce(page, sourcePath, label) {
await setupAccessibilityTreeHtml(page, `<!doctype html>
- <div class="modal-overlay" style="position:fixed;inset:0;background:rgba(0,0,0,.3)">
- <div role="dialog" aria-label="Review dialog" style="background:white;padding:20px">
- <button>Confirm layered action</button>
+ <body class="modal-open">
+ <button>Background control</button>
+ <div class="modal-overlay" style="position:fixed;inset:0;background:rgba(0,0,0,.3)">
+ <div role="dialog" aria-label="Review dialog" style="background:white;padding:20px">
+ <button>Confirm layered action</button>
+ </div>
</div>
- </div>`, sourcePath);
+ </body>`, sourcePath);
const tree = await page.evaluate(() => window.__generateAccessibilityTree('all', 10, null, null, 1));
const content = String(tree?.pageContent || '');
const matches = content.match(/button "Confirm layered action"/g) || [];
- if (!content.includes('[open overlays') || matches.length !== 1) {
- throw new Error(`${label}: nested modal should appear once in the hoisted tree: ${content}`);
+ const dialogAt = content.indexOf('dialog "Review dialog"');
+ const backgroundAt = content.indexOf('button "Background control"');
+ if (!content.includes('[open overlays') || matches.length !== 1
+ || dialogAt < 0 || backgroundAt < 0 || dialogAt > backgroundAt) {
+ throw new Error(`${label}: body.modal-open must not displace or duplicate the dialog: ${content}`);
}
}
@@ -2385,16 +2391,16 @@ async function assertStackedDockedBars(page, browserKind) {
<style>
body { margin: 0; height: 2000px; }
header { position: fixed; top: 0; width: 100%; height: 64px; background: white; }
- nav { position: fixed; top: 64px; width: 100%; height: 48px; background: white; }
+ .secondary-bar { position: fixed; top: 64px; width: 100%; height: 48px; background: white; }
.toolbar-lower { position: fixed; bottom: 0; width: 100%; height: 50px; background: white; }
- .toolbar-upper { position: fixed; bottom: 50px; width: 100%; height: 50px; background: white; }
+ .upper-bar { position: fixed; bottom: 50px; width: 100%; height: 50px; background: white; }
#top-target { position: absolute; top: 376px; left: 30px; height: 30px; }
#bottom-target { position: absolute; top: calc(300px + 100vh - 80px); left: 30px; height: 30px; }
</style>
<header>Primary header</header>
- <nav><button id="secondary-control" onclick="window.__secondaryClicked = true">Secondary control</button></nav>
+ <div class="secondary-bar" role="toolbar"><button id="secondary-control" onclick="window.__secondaryClicked = true">Secondary control</button></div>
<div class="toolbar-lower">Lower toolbar</div>
- <div class="toolbar-upper"><button id="upper-control" onclick="window.__upperClicked = true">Upper control</button></div>
+ <div class="upper-bar" role="toolbar"><button id="upper-control" onclick="window.__upperClicked = true">Upper control</button></div>
<button id="top-target" onclick="window.__topTargetClicked = true">Covered by secondary header</button>
<button id="bottom-target" onclick="window.__bottomTargetClicked = true">Covered by upper toolbar</button>
`, browserKind);