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): close unit/naming gaps from the Playwright helper rename

0x08e3ec395ba5d
diff --git a/package/ego-browser/README.md b/package/ego-browser/README.md
index a63bcad..ef058cb 100644
--- a/package/ego-browser/README.md
+++ b/package/ego-browser/README.md
@@ -66,11 +66,11 @@ src/
element-resolver.ts resolves @eN / CSS / XPath / ARIA targets
driver/
pointer.ts click, hover, drag, scroll, scrollBy
- observe.ts snapshot, captureScreenshot, elementCenter
- keyboard.ts insertText, pressKey, fillInput, dispatchKey
- nav.ts tabs, gotoUrl, openOrReuseTab, closeTab
- load.ts waitForLoad and load orchestration
- waits.ts waitForElement, waitForNetworkIdle, wait
+ observe.ts snapshot, screenshot, elementCenter
+ keyboard.ts insertText, press, fill, dispatchKey
+ nav.ts tabs, goto, openOrReuseTab, closeTab
+ load.ts waitForDocumentLoad and load orchestration
+ waits.ts waitForTimeout, waitForLoadState, waitForSelector
files.ts setInputFiles
http.ts serverFetch, browserFetch
cdp-eval.ts cdp() and evaluate() raw eval
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/keyboard.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/keyboard.mjs
index f4cdb53..e2f85e3 100644
--- a/package/ego-browser/scripts/real-browser-e2e/cases/keyboard.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/cases/keyboard.mjs
@@ -12,7 +12,7 @@ export function keyboardCase() {
assertEqual(areaValue, "area text", "fill supports textarea through loc=css");
await evaluate("const el = document.querySelector('#append-input'); el.focus(); el.setSelectionRange(el.value.length, el.value.length); return el.value");
- await fill("#append-input", "-suffix", { clearFirst: false, timeout: 3 });
+ await fill("#append-input", "-suffix", { clearFirst: false, timeout: 3000 });
const appended = await evaluate("return document.querySelector('#append-input').value");
assertEqual(appended, "base-suffix", "fill clearFirst:false preserves existing input value");
diff --git a/package/ego-browser/src/driver/keyboard.test.mjs b/package/ego-browser/src/driver/keyboard.test.mjs
index a19722d..6b126e1 100644
--- a/package/ego-browser/src/driver/keyboard.test.mjs
+++ b/package/ego-browser/src/driver/keyboard.test.mjs
@@ -78,6 +78,41 @@ test("press does not map modified Command+A variants to selectAll", async () =>
assert.equal(calls[0].params.commands, undefined);
});
+test("press parses a literal plus key with modifiers (Shift++)", async () => {
+ const calls = [];
+ const restore = setOverrides({
+ cdpOverride(method, params, sessionId) {
+ calls.push({ method, params, sessionId });
+ return {};
+ },
+ });
+ try {
+ await press("Shift++");
+ } finally {
+ restore();
+ }
+
+ assert.equal(calls.length, 2);
+ assert.deepEqual(calls[0].params, {
+ type: "keyDown",
+ key: "+",
+ code: "+",
+ modifiers: 8,
+ windowsVirtualKeyCode: 43,
+ nativeVirtualKeyCode: 43,
+ text: "+",
+ unmodifiedText: "+",
+ });
+ assert.deepEqual(calls[1].params, {
+ type: "keyUp",
+ key: "+",
+ code: "+",
+ modifiers: 8,
+ windowsVirtualKeyCode: 43,
+ nativeVirtualKeyCode: 43,
+ });
+});
+
test("press leaves ordinary printable keys unchanged", async () => {
const calls = [];
const restore = setOverrides({
diff --git a/package/ego-browser/src/driver/keyboard.ts b/package/ego-browser/src/driver/keyboard.ts
index 13515a9..ff92a3a 100644
--- a/package/ego-browser/src/driver/keyboard.ts
+++ b/package/ego-browser/src/driver/keyboard.ts
@@ -77,7 +77,13 @@ function parseKeyCombo(combo: string) {
const parts = combo.split("+");
let key = parts.pop() ?? combo;
if (key === "" && parts.length > 0) {
- key = "+"; // a trailing "+" means the literal plus key, e.g. "Shift++"
+ // A trailing "+" denotes the literal plus key, e.g. "+", "Shift++". split()
+ // turns that "+" into two empty segments; the pop above consumed one, so
+ // drop the remaining empty slot too instead of reading it as a modifier.
+ key = "+";
+ if (parts[parts.length - 1] === "") {
+ parts.pop();
+ }
}
let modifiers = 0;
for (const name of parts) {
diff --git a/package/ego-browser/src/driver/load.ts b/package/ego-browser/src/driver/load.ts
index d300894..1a3ae81 100644
--- a/package/ego-browser/src/driver/load.ts
+++ b/package/ego-browser/src/driver/load.ts
@@ -3,10 +3,15 @@ import { state } from "../state.js";
export type WaitForLoadOptions = {
timeout?: number;
+ until?: "load" | "domcontentloaded";
};
export async function waitForDocumentLoad(options: WaitForLoadOptions = {}) {
const timeout = options.timeout ?? 15000;
+ const ready =
+ options.until === "domcontentloaded"
+ ? ["interactive", "complete"]
+ : ["complete"];
const deadline = state.now() + timeout;
while (state.now() < deadline) {
let committed = true;
@@ -17,7 +22,7 @@ export async function waitForDocumentLoad(options: WaitForLoadOptions = {}) {
} catch {
// Page.getFrameTree may not be supported in some sessions; fall back to readyState only.
}
- if (committed && (await evaluate("document.readyState")) === "complete") {
+ if (committed && ready.includes(await evaluate("document.readyState"))) {
return true;
}
await state.sleep(300);
diff --git a/package/ego-browser/src/driver/nav.test.mjs b/package/ego-browser/src/driver/nav.test.mjs
index 7da2ed9..5c68bfd 100644
--- a/package/ego-browser/src/driver/nav.test.mjs
+++ b/package/ego-browser/src/driver/nav.test.mjs
@@ -9,6 +9,7 @@ import {
import {
listTabs,
newTab,
+ openOrReuseTab,
pageInfo,
closeTab,
} from "../../dist/src/driver/nav.js";
@@ -138,6 +139,42 @@ test("newTab throws when the binding returns no targetId", async () => {
);
});
+test("openOrReuseTab settles a newly opened tab in milliseconds, not seconds", async () => {
+ // Regression: the new-tab branch used to sleep(settle * 1000), so settle:500
+ // (documented as 500ms) blocked for 500 seconds while the reuse branch
+ // already treated it as milliseconds.
+ const sleeps = [];
+ await withEgo(
+ {
+ async listTabs() {
+ return { tabs: [] }; // no match → open a new tab
+ },
+ async createTab() {
+ return { targetId: "target-new" };
+ },
+ },
+ async () => {
+ const restore = setOverrides({
+ sleep: async (ms) => {
+ sleeps.push(ms);
+ },
+ });
+ try {
+ const opened = await openOrReuseTab("https://example.com/fresh", {
+ wait: false,
+ settle: 500,
+ });
+ assert.equal(opened.reused, false);
+ assert.equal(opened.targetId, "target-new");
+ } finally {
+ restore();
+ }
+ },
+ );
+
+ assert.deepEqual(sleeps, [500]);
+});
+
test("closeTab closes an explicit target and returns its id", async () => {
const calls = [];
const restore = setOverrides({
diff --git a/package/ego-browser/src/driver/nav.ts b/package/ego-browser/src/driver/nav.ts
index 701b9d1..e7e7c04 100644
--- a/package/ego-browser/src/driver/nav.ts
+++ b/package/ego-browser/src/driver/nav.ts
@@ -62,7 +62,13 @@ export async function goto(url: string, options: GotoOptions = {}) {
const loaded =
options.waitUntil === "commit"
? false
- : await waitForDocumentLoad({ timeout: options.timeout ?? 20000 });
+ : await waitForDocumentLoad({
+ timeout: options.timeout ?? 20000,
+ until:
+ options.waitUntil === "domcontentloaded"
+ ? "domcontentloaded"
+ : "load",
+ });
const settle = Number(options.settle ?? 0);
if (settle > 0) {
await state.sleep(settle);
@@ -184,7 +190,7 @@ export async function openOrReuseTab(
}
const settle = Number(options.settle ?? 0);
if (settle > 0) {
- await state.sleep(settle * 1000);
+ await state.sleep(settle);
}
return { targetId, url, title: "", active: true, reused: false };
}
diff --git a/package/ego-browser/src/driver/waits.ts b/package/ego-browser/src/driver/waits.ts
index 023ac12..0e6bbd7 100644
--- a/package/ego-browser/src/driver/waits.ts
+++ b/package/ego-browser/src/driver/waits.ts
@@ -26,7 +26,8 @@ export async function waitForTimeout(ms = 1000) {
/**
* Wait for a page load state. `"networkidle"` waits until network traffic goes
- * idle; any other state waits until document.readyState is complete.
+ * idle; `"domcontentloaded"` until the DOM is interactive; otherwise until
+ * document.readyState is complete.
* @param {"load"|"domcontentloaded"|"networkidle"} [loadState="load"] Load state to wait for.
* @param {{timeout?: number, idleMs?: number}} [options] timeout in milliseconds; idleMs only applies to "networkidle".
* @returns {Promise<boolean>} True when the state was reached before timeout.
@@ -38,7 +39,10 @@ export async function waitForLoadState(
if (loadState === "networkidle") {
return waitForNetworkIdle(options);
}
- return waitForDocumentLoad({ timeout: options.timeout });
+ return waitForDocumentLoad({
+ timeout: options.timeout,
+ until: loadState === "domcontentloaded" ? "domcontentloaded" : "load",
+ });
}
/**