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): refine URL wait and locator semantics

0x0bd7f3e578113
diff --git a/package/ego-browser/src/driver/waits.test.mjs b/package/ego-browser/src/driver/waits.test.mjs
index 6e779b4..fafe243 100644
--- a/package/ego-browser/src/driver/waits.test.mjs
+++ b/package/ego-browser/src/driver/waits.test.mjs
@@ -211,6 +211,42 @@ test("waitForURL resolves a matched about:blank without waiting for load", async
);
});
+test("waitForURL preserves networkidle for a matched about:blank", async () => {
+ const methods = [];
+ let t = 0;
+ const restore = setOverrides({
+ cdpOverride: async (method, params) => {
+ methods.push(method);
+ if (
+ method === "Runtime.evaluate" &&
+ params.expression === "location.href"
+ ) {
+ return { result: { value: "about:blank" } };
+ }
+ return {};
+ },
+ now: () => t,
+ sleep: async (ms) => {
+ t += ms;
+ },
+ });
+ try {
+ assert.equal(
+ await waitForURL("about:blank", {
+ timeout: 5000,
+ waitUntil: "networkidle",
+ }),
+ true,
+ );
+ } finally {
+ restore();
+ }
+
+ assert.ok(methods.includes("Network.enable"));
+ assert.ok(methods.includes("Network.disable"));
+ assert.ok(t >= 500, "networkidle observes its default idle window");
+});
+
test("waitForRequest matches exact URL and returns a request facade", async () => {
const calls = installAutoEgo();
try {
diff --git a/package/ego-browser/src/driver/waits.ts b/package/ego-browser/src/driver/waits.ts
index 97a2e06..05f0704 100644
--- a/package/ego-browser/src/driver/waits.ts
+++ b/package/ego-browser/src/driver/waits.ts
@@ -102,10 +102,11 @@ export async function waitForURL(url, options: WaitForURLOptions = {}) {
);
if (urlMatches(current, url)) {
const waitUntil = options.waitUntil ?? "load";
- // waitForDocumentLoad treats about:blank as an uncommitted transient
- // document, so a load wait on a matched blank page can never succeed;
- // its empty document is already loaded and has no network traffic.
- return waitUntil === "commit" || current === "about:blank"
+ // waitForDocumentLoad treats about:blank as an uncommitted transient,
+ // so skip document-load states for a matched blank page. Explicit
+ // networkidle still needs to observe its idle window.
+ return waitUntil === "commit" ||
+ (current === "about:blank" && waitUntil !== "networkidle")
? true
: waitForLoadState(waitUntil, {
timeout: Math.max(0, deadline - state.now()),
diff --git a/package/ego-browser/src/helpers.ts b/package/ego-browser/src/helpers.ts
index a5a1087..e9a8b9a 100644
--- a/package/ego-browser/src/helpers.ts
+++ b/package/ego-browser/src/helpers.ts
@@ -803,7 +803,7 @@ function createSiteFacade() {
const FACADE_HELP: Record<string, string> = {
page: 'page: Playwright-style page facade. page.url() asynchronously returns the current URL; always call await page.url() before using the string. Use page.goto(url), page.locator(selector), page.getByText(text), page.getByLabel(text), page.getByPlaceholder(text), page.getByTestId(testId), page.setDefaultTimeout(ms), page.waitForEvent("download"), page.waitForLoadState(state, options), page.waitForURL(url, options), page.waitForRequest(urlOrPredicate, options), page.waitForResponse(urlOrPredicate, options), page.evaluate(expression), page.screenshot(options), page.keyboard.press(key), page.keyboard.type(text), and page.mouse.click(x, y). waitForURL predicates receive URL objects and waitUntil defaults to load.',
locator:
- "page.locator(selector): returns an auto-waiting locator facade with locator(), getByRole(), getByText(), filter(), first(), nth(index), last(), click(), fill(value), clear(), press(key), check(), selectOption(value), textContent(), innerText(), innerHTML(), isVisible(), isEnabled(), getAttribute(name), screenshot(), count(), evaluate(fn, arg), evaluateAll(fn, arg), and waitFor(options). getBy*, loc=..., and chained/filtered locators are strict and fail on multiple matches; raw CSS and xpath= selectors act on the first match. Narrow multiple matches; use first()/nth() only for confirmed legitimate duplicates.",
+ "page.locator(selector): returns an auto-waiting locator facade with locator(), getByRole(), getByText(), filter(), first(), nth(index), last(), click(), fill(value), clear(), press(key), check(), selectOption(value), textContent(), innerText(), innerHTML(), isVisible(), isEnabled(), getAttribute(name), screenshot(), count(), evaluate(fn, arg), evaluateAll(fn, arg), and waitFor(options). Unqualified raw CSS and raw xpath= selectors are not strict and act on the first match by default; prefer getBy*, loc=..., or chained/filtered locators when ambiguity must fail loudly. Narrow multiple matches; use first()/nth() only for confirmed legitimate duplicates.",
browser:
"browser: tab facade. Use browser.listTabs(), browser.currentTab(), browser.switchTab(target), browser.openOrReuseTab(url, options), and browser.closeTab(target). Treat targetId as short-lived: obtain and validate it in the current script; switchTab/closeTab refresh the tab list before acting.",
taskSpaces:
diff --git a/skills/ego-browser/SKILL.md b/skills/ego-browser/SKILL.md
index d5e64db..00e5a2d 100644
--- a/skills/ego-browser/SKILL.md
+++ b/skills/ego-browser/SKILL.md
@@ -139,7 +139,7 @@ EOF
- A `page.waitForURL(...)` predicate receives a `URL` object. Use `url.href`, `url.pathname`, or `url.searchParams`, never `url.includes(...)`. It waits for `load` by default; use `waitUntil: 'commit'` only when intentionally proceeding before load.
- `page.waitForURL`, `page.waitForLoadState`, `page.waitForSelector`, locator `waitFor`, and `page.waitForFunction` return a falsy value on timeout. Check the result or immediately verify the required state; do not continue on an unverified assumption.
- Start `page.waitForRequest(...)`, `page.waitForResponse(...)`, or another event wait before the triggering action. Network predicates are synchronous and receive Playwright-style request/response facades.
-- Single-element actions and required reads auto-wait. Only `getBy*`, `loc=...`, and chained or filtered locators are strict and fail on multiple matches; raw CSS and `xpath=` selectors silently act on the first match, so use a strict form for anything destructive. For zero matches, confirm load, active tab, and modal/overlay state before correcting the locator. For multiple matches, inspect `count()` / `allInnerTexts()`, narrow semantically or with `filter(...)`, and use `first()` / `nth()` only after confirming duplicates are legitimate.
+- Single-element actions and required reads auto-wait. Unqualified raw CSS and raw `xpath=` locators are not strict and act on the first match by default; prefer `getBy*`, `loc=...`, or chained/filtered locators when ambiguity must fail loudly, especially for destructive actions. For zero matches, confirm load, active tab, and modal/overlay state before correcting the locator. For multiple matches, inspect `count()` / `allInnerTexts()`, narrow semantically or with `filter(...)`, and use `first()` / `nth()` only after confirming duplicates are legitimate.
- Prefer `getByRole`, `getByLabel`, `getByText`, `getByPlaceholder`, `getByTestId`, chained locators, and stable `loc=...` values. Use coordinates only for genuinely visual or canvas-like surfaces.
- For lists, extract item objects with `evaluateAll`, `allInnerTexts`, or semantic locators before choosing. Do not choose primarily from a sliced snapshot, a broad free-text regex, or coordinates.
- Verify every state-changing action before the Bash command exits. Throw when the required URL, dialog, selected value, item, or data is absent. Do not swallow errors from required actions; reserve `.catch(() => {})` for optional cleanup or non-blocking probes.