Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

fix(ego-browser): validate wheel deltas and close e2e coverage gaps

0x0798462c6363e
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs
index 1209e39..95e417a 100644
--- a/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/cases/pointer.mjs
@@ -76,9 +76,11 @@ export function scrollHelpersCase() {
await resetHome();
console.log(JSON.stringify({ pointerStep: "scroll ready" }));
- // wheel() routes through CDP only while the tab is visible AND focused; an
- // unfocused tab falls back to a synthetic WheelEvent that does not move native
- // scrollbars, so gate the native-scroll assertions on the CDP path.
+ // wheel() routes through CDP while the tab is visible AND focused; otherwise it
+ // falls back to a synthetic WheelEvent plus window.scrollBy, which moves the page
+ // but not nested scroll containers. So the page-scroll assertion runs on both
+ // paths; the nested-container assertion stays gated on the CDP path (and logs a
+ // visible skip otherwise, rather than silently passing).
const wheelUsesCdp = await evaluate(
"return document.visibilityState === 'visible' && document.hasFocus();"
);
@@ -109,6 +111,8 @@ export function scrollHelpersCase() {
"document.querySelector('#inner-scroll').scrollTop > 0",
"wheel targets nested scroll containers"
);
+ } else {
+ console.log(JSON.stringify({ scrollSkip: { assertion: "wheel targets nested scroll containers", reason: "synthetic path scrolls the window, not nested containers", wheelUsesCdp, innerWheelDispatched } }));
}
await resetHome();
@@ -120,7 +124,9 @@ export function scrollHelpersCase() {
const wheelDispatched = await allowWheelDispatch("wheel page", () =>
wheel(0, 300, { x: wheelPoint.x, y: wheelPoint.y })
);
- if (wheelUsesCdp && wheelDispatched) {
+ if (wheelDispatched) {
+ // Asserted on both paths: CDP wheel and the synthetic WheelEvent + window.scrollBy
+ // fallback both move the page, so a backgrounded/unfocused tab is covered too.
await waitForJsCondition(
"scrollY > " + JSON.stringify(beforeWheel.sy),
"wheel moves the page down"
@@ -174,6 +180,11 @@ export function pointerValidationCase() {
"invalid mouse offset",
"wheel validates numeric viewport coordinates"
);
+ await assertRejects(
+ () => wheel(0, "bad"),
+ "invalid mouse offset",
+ "wheel validates numeric scroll deltas"
+ );
`;
}
diff --git a/package/ego-browser/scripts/real-browser-e2e/runner.mjs b/package/ego-browser/scripts/real-browser-e2e/runner.mjs
index f70898d..d21f860 100644
--- a/package/ego-browser/scripts/real-browser-e2e/runner.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/runner.mjs
@@ -64,13 +64,17 @@ export async function runRealBrowserE2e() {
console.log(`-- ${name}`);
const startedAt = Date.now();
const marker = `EGO_NODEJS_BRIDGE_SMOKE_${Date.now()}`;
+ // The output channel is the overridden console.log. typeof console.log is always
+ // "function" (it is a Node built-in), so it cannot prove the SDK wired its sink.
+ // Two real signals cover it instead: the marker round-trip below proves console.log
+ // output reaches stdout, and helperCount > 0 proves installEgoSdk ran (it sets the
+ // console.log override and ego.helpers in the same call), so the override ran too.
const source = `
console.log(${JSON.stringify(marker)});
console.log(JSON.stringify({
egoType: typeof globalThis.ego,
hasSendCDPMessage: typeof globalThis.ego?.sendCDPMessage,
processVersion: process.version,
- consoleLogType: typeof globalThis.console?.log,
helperCount: Object.keys(globalThis.ego?.helpers || {}).length
}));
`;
@@ -90,7 +94,6 @@ export async function runRealBrowserE2e() {
if (
probe.egoType !== "object" ||
probe.hasSendCDPMessage !== "function" ||
- probe.consoleLogType !== "function" ||
typeof probe.processVersion !== "string" ||
probe.helperCount <= 0
) {
@@ -99,9 +102,9 @@ export async function runRealBrowserE2e() {
);
}
const durationMs = Date.now() - startedAt;
- recordResult(name, "pass", durationMs, 5);
+ recordResult(name, "pass", durationMs, 4);
console.log(
- `-- ${name} passed (${formatDuration(durationMs)}, 5 assertions)`,
+ `-- ${name} passed (${formatDuration(durationMs)}, 4 assertions)`,
);
} catch (error) {
const durationMs = Date.now() - startedAt;
diff --git a/package/ego-browser/src/driver/pointer.test.mjs b/package/ego-browser/src/driver/pointer.test.mjs
index 4a2e917..241d96c 100644
--- a/package/ego-browser/src/driver/pointer.test.mjs
+++ b/package/ego-browser/src/driver/pointer.test.mjs
@@ -174,6 +174,13 @@ test("wheel propagates user-control errors from the CDP dispatch", async () => {
}
});
+test("wheel rejects non-numeric deltas before dispatching", async () => {
+ // Regression: only the x/y viewport point was validated; a bad deltaX/deltaY
+ // flowed straight to CDP (string) or became a null no-op on the synthetic path.
+ await assert.rejects(() => wheel("bad"), /invalid mouse offset/);
+ await assert.rejects(() => wheel(0, "bad"), /invalid mouse offset/);
+});
+
test("click triggers probe fallback when CDP click is not trusted", async () => {
const originalEgo = globalThis.ego;
globalThis.ego = { sendCDPMessage: () => {} };
diff --git a/package/ego-browser/src/driver/pointer.ts b/package/ego-browser/src/driver/pointer.ts
index 83b36b3..388cdfc 100644
--- a/package/ego-browser/src/driver/pointer.ts
+++ b/package/ego-browser/src/driver/pointer.ts
@@ -447,16 +447,18 @@ export async function wheel(
) {
const x = numberValue(options.x ?? 0);
const y = numberValue(options.y ?? 0);
+ const dx = numberValue(deltaX);
+ const dy = numberValue(deltaY);
if (await isVisibleAndFocused()) {
await browserCdp(
"Input.dispatchMouseEvent",
- { type: "mouseWheel", x, y, deltaX, deltaY },
+ { type: "mouseWheel", x, y, deltaX: dx, deltaY: dy },
undefined,
1000,
);
return;
}
- await dispatchSyntheticWheel(x, y, deltaX, deltaY);
+ await dispatchSyntheticWheel(x, y, dx, dy);
}
/**