Skip to content

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

fix: center horizontal scroll targets clear of side rails

Barack Sokullu0ed9d88771a3
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index aeba54c94..585a035eb 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -425,7 +425,7 @@
const fullyVisible = _isFullyVisibleForInteraction(el, insets);
const coveredByFixed = fullyVisible && _isCoveredByFixedNonModalSurface(el, view);
if (!fullyVisible || coveredByFixed) {
- el.scrollIntoView({ block: 'center', inline: coveredByFixed ? 'center' : 'nearest', behavior: 'instant' });
+ el.scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' });
const rAfter = el.getBoundingClientRect();
if (rAfter.top < insets.top) {
view.scrollBy({ top: rAfter.top - insets.top - 16, behavior: 'instant' });
@@ -434,7 +434,7 @@
}
}
} catch {
- try { el.scrollIntoView({ block: 'center', inline: 'nearest' }); } catch {}
+ try { el.scrollIntoView({ block: 'center', inline: 'center' }); } catch {}
}
}
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index b035a0c8f..43cb794ad 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -684,7 +684,7 @@
const fullyVisible = _isFullyVisibleForInteraction(el, insets);
const coveredByFixed = fullyVisible && _isCoveredByFixedNonModalSurface(el, view);
if (!fullyVisible || coveredByFixed) {
- el.scrollIntoView({ block: 'center', inline: coveredByFixed ? 'center' : 'nearest', behavior: 'instant' });
+ el.scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' });
const rAfter = el.getBoundingClientRect();
if (rAfter.top < insets.top) {
view.scrollBy({ top: rAfter.top - insets.top - 16, behavior: 'instant' });
@@ -693,7 +693,7 @@
}
}
} catch {
- try { el.scrollIntoView({ block: 'center', inline: 'nearest' }); } catch {}
+ try { el.scrollIntoView({ block: 'center', inline: 'center' }); } catch {}
}
}
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index e41dc67d4..7e037d763 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -2438,6 +2438,40 @@ test('Chrome: controls inside a fixed side rail keep document scroll position',
firefoxTest('Firefox: controls inside a fixed side rail keep document scroll position', page =>
assertFixedSideRailControlsKeepScroll(page, 'firefox'));
+async function assertHorizontalTargetClearsSideRail(page, browserKind) {
+ await setupContentHtml(page, `<!doctype html>
+ <style>
+ body { margin: 0; }
+ #side { position: fixed; top: 0; left: 0; width: 200px; height: 100vh; z-index: 20; background: white; }
+ #scroller { width: 500px; height: 160px; overflow: auto; margin-top: 120px; }
+ #content { width: 1200px; height: 100px; position: relative; }
+ #target { position: absolute; left: 300px; top: 20px; }
+ </style>
+ <div id="side">Fixed side rail</div>
+ <div id="scroller"><div id="content"><input id="target" type="checkbox" aria-label="Grid checkbox"></div></div>
+ `, browserKind);
+ const before = await page.evaluate(() => {
+ document.getElementById('scroller').scrollLeft = 600;
+ return document.getElementById('target').getBoundingClientRect().left;
+ });
+ if (before >= 0) throw new Error(`${browserKind}: target must start outside the horizontal scrollport: ${before}`);
+ const ref = await page.evaluate(() => window.__wb_ax_ref(document.getElementById('target')));
+ const result = await call(page, 'set_checked', { ref_id: ref, checked: true });
+ const after = await page.evaluate(() => ({
+ checked: document.getElementById('target').checked,
+ left: document.getElementById('target').getBoundingClientRect().left,
+ scrollLeft: document.getElementById('scroller').scrollLeft,
+ }));
+ if (!result?.success || !after.checked || after.left < 200) {
+ throw new Error(`${browserKind}: horizontal target remained behind the side rail: ${JSON.stringify({ before, result, after })}`);
+ }
+}
+
+test('Chrome: horizontal target clears a fixed side rail', page =>
+ assertHorizontalTargetClearsSideRail(page, 'chrome'));
+firefoxTest('Firefox: horizontal target clears a fixed side rail', page =>
+ assertHorizontalTargetClearsSideRail(page, 'firefox'));
+
async function assertUnstuckStickyTargetClearsHeader(page, browserKind) {
await setupContentHtml(page, `<!doctype html>
<style>