Skip to content

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

fix: clear targets covered by unclassified fixed overlays

Barack Sokullua5cee59f0eb8
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index f417e6e29..0305cc4c7 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -395,6 +395,25 @@
return null;
}
+ function _isCoveredByFixedNonModalSurface(el, view = window) {
+ const rect = el.getBoundingClientRect();
+ const cx = rect.left + rect.width / 2;
+ const cy = rect.top + rect.height / 2;
+ if (cx < 0 || cy < 0 || cx >= view.innerWidth || cy >= view.innerHeight) return false;
+ const hit = _shadowAwareElementFromPoint(cx, cy);
+ if (!hit || _isComposedAncestor(el, hit) || _isComposedAncestor(hit, el)) return false;
+ for (let node = hit; node; node = _composedParent(node)) {
+ if (node.nodeType !== Node.ELEMENT_NODE) continue;
+ if (node.matches?.('[role="dialog"], [role="alertdialog"], [aria-modal="true"], dialog[open]')) return false;
+ const style = view.getComputedStyle(node);
+ if (style.position !== 'fixed' && style.position !== 'sticky') continue;
+ const blocker = node.getBoundingClientRect();
+ if (blocker.width >= view.innerWidth * 0.8 && blocker.height >= view.innerHeight * 0.8) return false;
+ return true;
+ }
+ return false;
+ }
+
function _scrollElementIntoClearView(el) {
if (!el?.isConnected) return;
try {
@@ -402,8 +421,10 @@
const insets = _getViewportDockedInsets(view, el);
// A viewport-only rect check misses elements clipped by a scrollable
// ancestor even when their bounding box is inside the viewport.
- if (!_isFullyVisibleForInteraction(el, insets)) {
- el.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
+ const fullyVisible = _isFullyVisibleForInteraction(el, insets);
+ const coveredByFixed = fullyVisible && _isCoveredByFixedNonModalSurface(el, view);
+ if (!fullyVisible || coveredByFixed) {
+ el.scrollIntoView({ block: 'center', inline: coveredByFixed ? 'center' : 'nearest', behavior: 'instant' });
const rAfter = el.getBoundingClientRect();
if (rAfter.top < insets.top) {
view.scrollBy({ top: rAfter.top - insets.top - 16, behavior: 'instant' });
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index b6a319393..a1d10065e 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -654,6 +654,25 @@
return null;
}
+ function _isCoveredByFixedNonModalSurface(el, view = window) {
+ const rect = el.getBoundingClientRect();
+ const cx = rect.left + rect.width / 2;
+ const cy = rect.top + rect.height / 2;
+ if (cx < 0 || cy < 0 || cx >= view.innerWidth || cy >= view.innerHeight) return false;
+ const hit = _shadowAwareElementFromPoint(cx, cy);
+ if (!hit || _isComposedAncestor(el, hit) || _isComposedAncestor(hit, el)) return false;
+ for (let node = hit; node; node = _composedParent(node)) {
+ if (node.nodeType !== Node.ELEMENT_NODE) continue;
+ if (node.matches?.('[role="dialog"], [role="alertdialog"], [aria-modal="true"], dialog[open]')) return false;
+ const style = view.getComputedStyle(node);
+ if (style.position !== 'fixed' && style.position !== 'sticky') continue;
+ const blocker = node.getBoundingClientRect();
+ if (blocker.width >= view.innerWidth * 0.8 && blocker.height >= view.innerHeight * 0.8) return false;
+ return true;
+ }
+ return false;
+ }
+
function _scrollElementIntoClearView(el) {
if (!el?.isConnected) return;
try {
@@ -661,8 +680,10 @@
const insets = _getViewportDockedInsets(view, el);
// A viewport-only rect check misses elements clipped by a scrollable
// ancestor even when their bounding box is inside the viewport.
- if (!_isFullyVisibleForInteraction(el, insets)) {
- el.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
+ const fullyVisible = _isFullyVisibleForInteraction(el, insets);
+ const coveredByFixed = fullyVisible && _isCoveredByFixedNonModalSurface(el, view);
+ if (!fullyVisible || coveredByFixed) {
+ el.scrollIntoView({ block: 'center', inline: coveredByFixed ? 'center' : 'nearest', behavior: 'instant' });
const rAfter = el.getBoundingClientRect();
if (rAfter.top < insets.top) {
view.scrollBy({ top: rAfter.top - insets.top - 16, behavior: 'instant' });
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index eeefaf09a..61b4368c4 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -2532,6 +2532,61 @@ test('Chrome: floating top bar clears a fully covered target', page =>
firefoxTest('Firefox: floating top bar clears a fully covered target', page =>
assertFloatingTopBarClearance(page, 'firefox'));
+async function assertUnclassifiedFixedOverlayClearance(page, browserKind) {
+ await setupContentHtml(page, `<!doctype html>
+ <style>
+ body { margin: 0; height: 1700px; }
+ #cookie-banner { position: fixed; bottom: 0; left: 0; width: 100%; height: 80px; z-index: 20; background: white; }
+ #target { position: absolute; top: calc(300px + 100vh - 60px); left: 60px; width: 120px; height: 40px; }
+ </style>
+ <button id="target" onclick="window.__targetClicked = true">Behind cookie banner</button>
+ <div id="cookie-banner">Cookie notice</div>
+ `, browserKind);
+ await page.evaluate(() => window.scrollTo(0, 300));
+ const bottomClick = await call(page, 'click', { selector: '#target' });
+ const bottomState = await page.evaluate(() => ({
+ clicked: window.__targetClicked === true,
+ scrollY: window.scrollY,
+ bottom: document.getElementById('target').getBoundingClientRect().bottom,
+ viewportHeight: window.innerHeight,
+ }));
+ if (!bottomClick?.success || !bottomState.clicked || bottomState.scrollY <= 300
+ || bottomState.bottom > bottomState.viewportHeight - 80) {
+ throw new Error(`${browserKind}: unclassified bottom banner was not cleared: ${JSON.stringify({ bottomClick, bottomState })}`);
+ }
+
+ await setupContentHtml(page, `<!doctype html>
+ <style>
+ body { margin: 0; width: 2000px; height: 1700px; }
+ #side-panel { position: fixed; top: 0; left: 0; width: 240px; height: 100vh; z-index: 20; background: white; }
+ #target { position: absolute; top: 500px; left: 350px; width: 100px; height: 40px; }
+ </style>
+ <button id="target" onclick="window.__targetClicked = true">Behind side panel</button>
+ <div id="side-panel">Side panel</div>
+ `, browserKind);
+ const beforeSide = await page.evaluate(() => {
+ window.scrollTo(300, 300);
+ return { scrollX: window.scrollX, left: document.getElementById('target').getBoundingClientRect().left };
+ });
+ if (beforeSide.scrollX !== 300 || beforeSide.left >= 240) {
+ throw new Error(`${browserKind}: side panel fixture did not cover the target: ${JSON.stringify(beforeSide)}`);
+ }
+ const sideClick = await call(page, 'click', { selector: '#target' });
+ const sideState = await page.evaluate(() => ({
+ clicked: window.__targetClicked === true,
+ scrollX: window.scrollX,
+ left: document.getElementById('target').getBoundingClientRect().left,
+ }));
+ if (!sideClick?.success || !sideState.clicked || sideState.scrollX >= 300 || sideState.left < 240) {
+ throw new Error(`${browserKind}: unclassified side panel was not cleared: ${JSON.stringify({ sideClick, sideState })}`);
+ }
+}
+
+test('Chrome: unclassified bottom and side overlays clear their targets', page =>
+ assertUnclassifiedFixedOverlayClearance(page, 'chrome'));
+firefoxTest('Firefox: unclassified bottom and side overlays clear their targets', page =>
+ assertUnclassifiedFixedOverlayClearance(page, 'firefox'));
+
async function assertInnerScrollerClearance(page, browserKind) {
await setupContentHtml(page, `<!doctype html>
<style>