Skip to content

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

fix: clear floating fixed bars above covered targets

Barack Sokulluf106b5dea507
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index 3e27219f0..f417e6e29 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -380,6 +380,21 @@
};
}
+ function _floatingTopBarRect(blocker, view = window) {
+ const vh = view.innerHeight || 600;
+ const vw = view.innerWidth || 800;
+ for (let node = blocker; node; node = _composedParent(node)) {
+ if (node.nodeType !== Node.ELEMENT_NODE) continue;
+ if (node.matches?.('[role="dialog"], [role="alertdialog"], [aria-modal="true"], dialog[open]')) return null;
+ const style = view.getComputedStyle(node);
+ if (style.position !== 'fixed' && style.position !== 'sticky') continue;
+ const rect = node.getBoundingClientRect();
+ if (rect.top > 10 && rect.top < vh * 0.35 && rect.bottom < vh * 0.45
+ && rect.height <= vh * 0.25 && rect.width >= vw * 0.4) return rect;
+ }
+ return null;
+ }
+
function _scrollElementIntoClearView(el) {
if (!el?.isConnected) return;
try {
@@ -2005,8 +2020,10 @@
// If covered at center, test if scrolling can clear a fixed/sticky header
if (topmost && !_isComposedAncestor(el, topmost) && !_isComposedAncestor(topmost, el)) {
- const bRect = topmost.getBoundingClientRect();
- if (bRect.top <= _getViewportDockedInsets(window, el).top + 10 && bRect.bottom > r.top && bRect.bottom < window.innerHeight * 0.45) {
+ const floatingBar = _floatingTopBarRect(topmost);
+ const bRect = floatingBar || topmost.getBoundingClientRect();
+ if ((floatingBar || bRect.top <= _getViewportDockedInsets(window, el).top + 10)
+ && bRect.bottom > r.top && bRect.bottom < window.innerHeight * 0.45) {
window.scrollBy({ top: r.top - bRect.bottom - 20, behavior: 'instant' });
r = el.getBoundingClientRect();
cx = Math.round(r.left + r.width / 2);
@@ -8032,8 +8049,10 @@
}
if (!hitOk && topmost) {
try {
- const bRect = topmost.getBoundingClientRect();
- if (bRect.top <= _getViewportDockedInsets(window, el).top + 10 && bRect.bottom > r.top && bRect.bottom < vh * 0.45) {
+ const floatingBar = _floatingTopBarRect(topmost);
+ const bRect = floatingBar || topmost.getBoundingClientRect();
+ if ((floatingBar || bRect.top <= _getViewportDockedInsets(window, el).top + 10)
+ && bRect.bottom > r.top && bRect.bottom < vh * 0.45) {
window.scrollBy({ top: r.top - bRect.bottom - 20, behavior: 'instant' });
r = el.getBoundingClientRect();
effectiveCx = r.left + r.width / 2;
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 3f32c9835..b6a319393 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -639,6 +639,21 @@
};
}
+ function _floatingTopBarRect(blocker, view = window) {
+ const vh = view.innerHeight || 600;
+ const vw = view.innerWidth || 800;
+ for (let node = blocker; node; node = _composedParent(node)) {
+ if (node.nodeType !== Node.ELEMENT_NODE) continue;
+ if (node.matches?.('[role="dialog"], [role="alertdialog"], [aria-modal="true"], dialog[open]')) return null;
+ const style = view.getComputedStyle(node);
+ if (style.position !== 'fixed' && style.position !== 'sticky') continue;
+ const rect = node.getBoundingClientRect();
+ if (rect.top > 10 && rect.top < vh * 0.35 && rect.bottom < vh * 0.45
+ && rect.height <= vh * 0.25 && rect.width >= vw * 0.4) return rect;
+ }
+ return null;
+ }
+
function _scrollElementIntoClearView(el) {
if (!el?.isConnected) return;
try {
@@ -2304,8 +2319,10 @@
// If covered at center, test if scrolling can clear a fixed/sticky header
if (topmost && !_hitTestMatchesTarget(el, topmost)) {
- const bRect = topmost.getBoundingClientRect();
- if (bRect.top <= _getViewportDockedInsets(window, el).top + 10 && bRect.bottom > r.top && bRect.bottom < window.innerHeight * 0.45) {
+ const floatingBar = _floatingTopBarRect(topmost);
+ const bRect = floatingBar || topmost.getBoundingClientRect();
+ if ((floatingBar || bRect.top <= _getViewportDockedInsets(window, el).top + 10)
+ && bRect.bottom > r.top && bRect.bottom < window.innerHeight * 0.45) {
window.scrollBy({ top: r.top - bRect.bottom - 20, behavior: 'instant' });
r = el.getBoundingClientRect();
cx = Math.round(r.left + r.width / 2);
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index f44949ad9..eeefaf09a 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -2491,6 +2491,47 @@ test('Chrome: top obstruction retry moves targets below the blocker', page =>
firefoxTest('Firefox: top obstruction retry moves targets below the blocker', page =>
assertTopObstructionScrollDirection(page, 'firefox'));
+async function assertFloatingTopBarClearance(page, browserKind) {
+ await setupContentHtml(page, `<!doctype html>
+ <style>
+ body { margin: 0; height: 1700px; }
+ #obstruction { position: fixed; top: 40px; left: 0; width: 100%; height: 80px; z-index: 20; background: white; }
+ #target { position: absolute; top: 350px; left: 60px; width: 120px; height: 40px; }
+ #row { position: absolute; top: 350px; left: 220px; width: 120px; height: 40px; }
+ </style>
+ <button id="target" onclick="window.__targetClicked = true">Covered target</button>
+ <div id="row" role="listitem">Covered row</div>
+ <div id="obstruction">Floating obstruction</div>
+ `, browserKind);
+ await page.evaluate(() => window.scrollTo(0, 300));
+ const click = await call(page, 'click', { selector: '#target' });
+ const afterClick = await page.evaluate(() => ({
+ clicked: window.__targetClicked === true,
+ scrollY: window.scrollY,
+ top: document.getElementById('target').getBoundingClientRect().top,
+ }));
+ if (!click?.success || !afterClick.clicked || afterClick.scrollY >= 300 || afterClick.top < 120) {
+ throw new Error(`${browserKind}: floating top bar did not clear the click target: ${JSON.stringify({ click, afterClick })}`);
+ }
+ if (browserKind === 'chrome') {
+ await page.evaluate(() => window.scrollTo(0, 300));
+ const refId = await page.evaluate(() => window.__wb_ax_ref(document.getElementById('row')));
+ const resolved = await call(page, 'ax_resolve_rect', { ref_id: refId, forClickFallback: true });
+ const afterResolve = await page.evaluate(() => ({
+ scrollY: window.scrollY,
+ top: document.getElementById('row').getBoundingClientRect().top,
+ }));
+ if (!resolved?.success || !resolved.hitOk || afterResolve.scrollY >= 300 || afterResolve.top < 120) {
+ throw new Error(`Chrome floating top bar did not clear rect resolution: ${JSON.stringify({ resolved, afterResolve })}`);
+ }
+ }
+}
+
+test('Chrome: floating top bar clears a fully covered target', page =>
+ assertFloatingTopBarClearance(page, 'chrome'));
+firefoxTest('Firefox: floating top bar clears a fully covered target', page =>
+ assertFloatingTopBarClearance(page, 'firefox'));
+
async function assertInnerScrollerClearance(page, browserKind) {
await setupContentHtml(page, `<!doctype html>
<style>