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: clear stacked docked bars during interactions
Barack Sokullu6eb65502b7d4
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 81c835b64..149395bf9 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -331,8 +331,8 @@const style = view.getComputedStyle(node);if (style.position !== 'fixed' && style.position !== 'sticky') continue;const rect = node.getBoundingClientRect();- if (rect.top <= 10 && rect.bottom > 0 && rect.bottom < view.innerHeight * 0.4) targetInTopDock = true;- if (rect.bottom >= view.innerHeight - 10 && rect.top > view.innerHeight * 0.6) targetInBottomDock = true;+ if (rect.top >= -10 && rect.top < view.innerHeight * 0.4 && rect.bottom > 0 && rect.bottom <= view.innerHeight * 0.4) targetInTopDock = true;+ if (rect.bottom <= view.innerHeight + 10 && rect.bottom > view.innerHeight * 0.6 && rect.top >= view.innerHeight * 0.6) targetInBottomDock = true;}if (!targetInTopDock) top = Math.max(top, parsePadding(htmlStyle.scrollPaddingTop));if (!targetInBottomDock) bottom = Math.max(bottom, parsePadding(htmlStyle.scrollPaddingBottom));@@ -343,6 +343,8 @@const candidates = doc.querySelectorAll('header, nav, [role="banner"], [role="navigation"], [class*="header" i], [class*="navbar" i], [class*="toolbar" i]');const vw = view.innerWidth || 800;const vh = view.innerHeight || 600;+ const topRects = [];+ const bottomRects = [];for (const c of candidates) {if (target && _isComposedAncestor(c, target)) continue;if (!c.isConnected || c.offsetWidth <= 0 || c.offsetHeight <= 0) continue;@@ -351,11 +353,24 @@if (cs.display === 'none' || cs.visibility === 'hidden') continue;const r = c.getBoundingClientRect();if (r.width < vw * 0.4) continue;- if (r.top <= 10 && r.bottom > 0 && r.bottom < vh * 0.4) {- if (r.bottom > top) top = r.bottom;- } else if (r.bottom >= vh - 10 && r.top < vh && r.top > vh * 0.6) {- const h = vh - r.top;- if (h > bottom) bottom = h;+ if (r.top < vh * 0.4 && r.bottom > 0 && r.bottom < vh * 0.4) topRects.push(r);+ if (r.bottom > vh * 0.6 && r.top < vh && r.top > vh * 0.6) bottomRects.push(r);+ }+ // Recheck until all contiguous bars are included, regardless of DOM order.+ let changed = true;+ while (changed) {+ changed = false;+ for (const r of topRects) {+ if (r.top <= top + 10 && r.bottom > top) {+ top = r.bottom;+ changed = true;+ }+ }+ for (const r of bottomRects) {+ if (r.bottom >= vh - bottom - 10 && r.top < vh - bottom) {+ bottom = vh - r.top;+ changed = true;+ }}}} catch {}@@ -1991,7 +2006,7 @@// If covered at center, test if scrolling can clear a fixed/sticky headerif (topmost && !_isComposedAncestor(el, topmost) && !_isComposedAncestor(topmost, el)) {const bRect = topmost.getBoundingClientRect();- if (bRect.top <= 10 && bRect.bottom > r.top && bRect.bottom < window.innerHeight * 0.45) {+ if (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);@@ -8018,7 +8033,7 @@if (!hitOk && topmost) {try {const bRect = topmost.getBoundingClientRect();- if (bRect.top <= 10 && bRect.bottom > r.top && bRect.bottom < vh * 0.45) {+ if (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.jsindex 9d69c4127..9dca2c54b 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -590,8 +590,8 @@const style = view.getComputedStyle(node);if (style.position !== 'fixed' && style.position !== 'sticky') continue;const rect = node.getBoundingClientRect();- if (rect.top <= 10 && rect.bottom > 0 && rect.bottom < view.innerHeight * 0.4) targetInTopDock = true;- if (rect.bottom >= view.innerHeight - 10 && rect.top > view.innerHeight * 0.6) targetInBottomDock = true;+ if (rect.top >= -10 && rect.top < view.innerHeight * 0.4 && rect.bottom > 0 && rect.bottom <= view.innerHeight * 0.4) targetInTopDock = true;+ if (rect.bottom <= view.innerHeight + 10 && rect.bottom > view.innerHeight * 0.6 && rect.top >= view.innerHeight * 0.6) targetInBottomDock = true;}if (!targetInTopDock) top = Math.max(top, parsePadding(htmlStyle.scrollPaddingTop));if (!targetInBottomDock) bottom = Math.max(bottom, parsePadding(htmlStyle.scrollPaddingBottom));@@ -602,6 +602,8 @@const candidates = doc.querySelectorAll('header, nav, [role="banner"], [role="navigation"], [class*="header" i], [class*="navbar" i], [class*="toolbar" i]');const vw = view.innerWidth || 800;const vh = view.innerHeight || 600;+ const topRects = [];+ const bottomRects = [];for (const c of candidates) {if (target && _isComposedAncestor(c, target)) continue;if (!c.isConnected || c.offsetWidth <= 0 || c.offsetHeight <= 0) continue;@@ -610,11 +612,24 @@if (cs.display === 'none' || cs.visibility === 'hidden') continue;const r = c.getBoundingClientRect();if (r.width < vw * 0.4) continue;- if (r.top <= 10 && r.bottom > 0 && r.bottom < vh * 0.4) {- if (r.bottom > top) top = r.bottom;- } else if (r.bottom >= vh - 10 && r.top < vh && r.top > vh * 0.6) {- const h = vh - r.top;- if (h > bottom) bottom = h;+ if (r.top < vh * 0.4 && r.bottom > 0 && r.bottom < vh * 0.4) topRects.push(r);+ if (r.bottom > vh * 0.6 && r.top < vh && r.top > vh * 0.6) bottomRects.push(r);+ }+ // Recheck until all contiguous bars are included, regardless of DOM order.+ let changed = true;+ while (changed) {+ changed = false;+ for (const r of topRects) {+ if (r.top <= top + 10 && r.bottom > top) {+ top = r.bottom;+ changed = true;+ }+ }+ for (const r of bottomRects) {+ if (r.bottom >= vh - bottom - 10 && r.top < vh - bottom) {+ bottom = vh - r.top;+ changed = true;+ }}}} catch {}@@ -2290,7 +2305,7 @@// If covered at center, test if scrolling can clear a fixed/sticky headerif (topmost && !_hitTestMatchesTarget(el, topmost)) {const bRect = topmost.getBoundingClientRect();- if (bRect.top <= 10 && bRect.bottom > r.top && bRect.bottom < window.innerHeight * 0.45) {+ if (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.mjsindex 59c45bd34..497028251 100644--- a/test/fixtures/run.mjs+++ b/test/fixtures/run.mjs@@ -2380,6 +2380,69 @@ test('Chrome: controls inside docked bars keep the document scroll position', pafirefoxTest('Firefox: controls inside docked bars keep the document scroll position', page =>assertDockedControlsKeepScroll(page, 'firefox'));+async function assertStackedDockedBars(page, browserKind) {+ await setupContentHtml(page, `<!doctype html>+ <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; }+ .toolbar-lower { position: fixed; bottom: 0; width: 100%; height: 50px; background: white; }+ .toolbar-upper { 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="toolbar-lower">Lower toolbar</div>+ <div class="toolbar-upper"><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);+ await page.evaluate(() => window.scrollTo(0, 300));+ const topClick = await call(page, 'click', { selector: '#top-target' });+ const topState = await page.evaluate(() => ({+ clicked: window.__topTargetClicked === true,+ scrollY: window.scrollY,+ top: document.getElementById('top-target').getBoundingClientRect().top,+ }));+ if (!topClick?.success || !topState.clicked || topState.scrollY >= 300 || topState.top < 112) {+ throw new Error(`${browserKind}: stacked top bars did not clear the target: ${JSON.stringify({ topClick, topState })}`);+ }+ await page.evaluate(() => window.scrollTo(0, 300));+ const bottomClick = await call(page, 'click', { selector: '#bottom-target' });+ const bottomState = await page.evaluate(() => ({+ clicked: window.__bottomTargetClicked === true,+ scrollY: window.scrollY,+ bottom: document.getElementById('bottom-target').getBoundingClientRect().bottom,+ viewportHeight: window.innerHeight,+ }));+ if (!bottomClick?.success || !bottomState.clicked || bottomState.scrollY <= 300+ || bottomState.bottom > bottomState.viewportHeight - 100) {+ throw new Error(`${browserKind}: stacked bottom bars did not clear the target: ${JSON.stringify({ bottomClick, bottomState })}`);+ }+ await page.evaluate(() => {+ document.documentElement.style.scrollPaddingTop = '112px';+ document.documentElement.style.scrollPaddingBottom = '100px';+ });+ const dockedBefore = await page.evaluate(() => ({+ scrollY: window.scrollY,+ secondaryTop: document.getElementById('secondary-control').getBoundingClientRect().top,+ upperBottom: document.getElementById('upper-control').getBoundingClientRect().bottom,+ }));+ for (const [selector, flag] of [['#secondary-control', '__secondaryClicked'], ['#upper-control', '__upperClicked']]) {+ const result = await call(page, 'click', { selector });+ const state = await page.evaluate(name => ({ clicked: window[name] === true, scrollY: window.scrollY }), flag);+ if (!result?.success || !state.clicked || Math.abs(state.scrollY - dockedBefore.scrollY) > 1) {+ throw new Error(`${browserKind}: offset dock control ${selector} scrolled the page: ${JSON.stringify({ dockedBefore, result, state })}`);+ }+ }+}++test('Chrome: stacked docked bars clear targets and preserve docked controls', page =>+ assertStackedDockedBars(page, 'chrome'));+firefoxTest('Firefox: stacked docked bars clear targets and preserve docked controls', page =>+ assertStackedDockedBars(page, 'firefox'));+async function assertTopObstructionScrollDirection(page, browserKind) {await setupContentHtml(page, `<!doctype html><style>