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.
JavaScript agent-skillsai-agentautomationbrowserbrowser-automationclaude-codecodexhermes-agentskillsskills-sh
feat(ego-browser): default snapshots to viewport
Auted14a5ce700f7
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-labels.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-labels.mjsindex 5b2770b..b43ec88 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/page-labels.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-labels.mjs@@ -234,7 +234,7 @@ export function pageBasicOperationsCase() {marker.textContent = "Snapshot diff marker";document.body.append(marker);});- const changedSnapshot = await first.snapshot();+ const changedSnapshot = await first.snapshot({ scope: "full_page" });assertIncludes(changedSnapshot, "Snapshot diff marker", "snapshot contains new page content");assertEqual(await first.evaluate("document.querySelector('h1').textContent"),diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-oopif.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-oopif.mjsindex 9130fba..0dfe388 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/page-oopif.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-oopif.mjs@@ -4,7 +4,7 @@ export function pageOopifActionCase() {const page = await task.openPage(baseUrl + "/?page-api=oopif", {as: "oopif-page",});- const snapshot = await page.snapshot();+ const snapshot = await page.snapshot({ scope: "full_page" });assertIncludes(snapshot, "Run iframe action", "snapshot includes cross-site iframe content");assertIncludes(snapshot, "Iframe field", "snapshot includes the iframe input");await page.click('loc=role:button[name="Run iframe action"]');@@ -32,7 +32,7 @@ export function pageOopifActionCase() {as: "same-origin-frame",});assertIncludes(- await sameOrigin.snapshot(),+ await sameOrigin.snapshot({ scope: "full_page" }),"Run iframe action","snapshot includes same-process iframe content");@@ -55,7 +55,7 @@ export function pageOopifRestoreCase() {return `const task = await taskSpace(taskName);const page = task.page("oopif-page");- const snapshot = await page.snapshot();+ const snapshot = await page.snapshot({ scope: "full_page" });assertIncludes(snapshot, "Run iframe action", "a later round observes the iframe");await page.click('text="Run iframe action"');diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-shadow-dom.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-shadow-dom.mjsindex 6b9252a..067f290 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/page-shadow-dom.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-shadow-dom.mjs@@ -3,7 +3,7 @@ export function pageShadowDomCase() {const task = await taskSpace(taskName);const page = await task.openPage(baseUrl + "/?page=shadow-dom", { as: "shadow-dom" });try {- const snapshot = await page.snapshot();+ const snapshot = await page.snapshot({ scope: "full_page" });assertIncludes(snapshot, "Shadow field", "snapshot exposes the shadow input");await page.fill('loc=css:input[aria-label="Shadow field"]', "shadow value");diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-snapshot-locators.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-snapshot-locators.mjsindex 48cadb5..32f6e13 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/page-snapshot-locators.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-snapshot-locators.mjs@@ -14,7 +14,7 @@ export function pageSnapshotLocatorCase() {document.body.append(region);});- const snapshot = await page.snapshot();+ const snapshot = await page.snapshot({ scope: "full_page" });const duplicateLines = snapshot.split("\\n").filter((line) => line.includes("locator=duplicate"));diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjsindex 03ca786..3cd64f0 100644--- a/package/ego-browser/src/page-model.test.mjs+++ b/package/ego-browser/src/page-model.test.mjs@@ -51,6 +51,7 @@ function createFixture(rootDir) {const networkSessions = new Set();const sessionOverrides = new Map();const sessionTargets = new Map();+ const snapshotOptions = [];function openPendingPopup() {if (!popupOnNextClick) return;@@ -401,6 +402,7 @@ function createFixture(rootDir) {},async snapshot(options = {}) {const tab = tabs.get(activeTarget);+ snapshotOptions.push({ ...options });calls.push(["snapshot", activeTarget]);return {content: `snapshot:${tab?.url}`,@@ -477,6 +479,7 @@ function createFixture(rootDir) {gate,rootDir,services,+ snapshotOptions,tabs,addExternalTab(targetId, url, { active = false } = {}) {tabs.set(targetId, { targetId, url, title: url, active });@@ -867,7 +870,7 @@ test("snapshot activates the addressed page, not whichever tab was current", asy});});-test("snapshot reports its source and rejects options absent from the schema", async () => {+test("snapshot defaults to the viewport, reports its source, and validates options", async () => {await withFixture(async (fixture) => {const task = taskForRound(fixture, "round-a");const page = await task.openPage("https://example.test/before");@@ -876,6 +879,19 @@ test("snapshot reports its source and rejects options absent from the schema", aawait page.snapshot(),/snapshot:https:\/\/example\.test\/before/,);+ assert.deepEqual(fixture.snapshotOptions.at(-1), {+ scope: "only_within_viewport",+ includeActionMarks: true,+ includeStableLocator: true,+ });++ await page.snapshot({ scope: "full_page" });+ assert.deepEqual(fixture.snapshotOptions.at(-1), {+ scope: "full_page",+ includeActionMarks: true,+ includeStableLocator: true,+ });+await assert.rejects(() => page.snapshot({ diff: true }),/page\.snapshot received unknown option: diff/,diff --git a/package/ego-browser/src/page-model.ts b/package/ego-browser/src/page-model.tsindex 8a9bfb7..0ce9bb8 100644--- a/package/ego-browser/src/page-model.ts+++ b/package/ego-browser/src/page-model.ts@@ -1044,10 +1044,10 @@ class Page {return this.#services.gate.withPage(page, async () => {await this.#activate(page.targetId);const result = await this.#services.snapshot({- scope: "full_page",- includeActionMarks: true,- includeStableLocator: true,...options,+ scope: options.scope ?? "only_within_viewport",+ includeActionMarks: options.includeActionMarks ?? true,+ includeStableLocator: options.includeStableLocator ?? true,});this.#services.pageRefs.replace(page.targetId, result?.refs || []);const content = result?.content || "";diff --git a/package/ego-browser/src/public-api-schema.ts b/package/ego-browser/src/public-api-schema.tsindex 03e6e74..9cc99b2 100644--- a/package/ego-browser/src/public-api-schema.ts+++ b/package/ego-browser/src/public-api-schema.ts@@ -195,12 +195,14 @@ export const PUBLIC_API_SCHEMA: readonly PublicApiEntry[] = [name: "Page.snapshot",signature:"await page.snapshot({ scope?, includeActionMarks?, includeStableLocator? })",- summary: "Return a full semantic snapshot with Page provenance.",+ summary:+ "Return a semantic snapshot of the current viewport with Page provenance.",options: {- scope: option("string", "Snapshot scope.", [- "full_page",- "only_within_viewport",- ]),+ scope: option(+ "string",+ "Snapshot scope; defaults to only_within_viewport.",+ ["full_page", "only_within_viewport"],+ ),includeActionMarks: option("boolean", "Include action marks."),includeStableLocator: option("boolean", "Include stable locators."),},diff --git a/skills/ego-browser/SKILL.md b/skills/ego-browser/SKILL.mdindex 7ffe9a7..903ae5a 100644--- a/skills/ego-browser/SKILL.md+++ b/skills/ego-browser/SKILL.md@@ -153,8 +153,9 @@ await page.keyboard.insertText(text);### Semantic pages: snapshot and selectors-For an ordinary DOM page, start with `page.snapshot()`. It returns semantic-text containing refs and stable locators:+For an ordinary DOM page, work in a short observe → act → observe loop. Start+with `page.snapshot()`, which returns semantic text for the current viewport.+Pass `{ scope: "full_page" }` only when content outside the viewport matters:```jsconst page = task.page("p1");@@ -183,16 +184,19 @@ quote the value for an exact, case-sensitive match, such asmust be unique.Snapshot node names are accessibility roles. Use the current ref for an-immediate action and a generated locator for reuse. CSS searches nested open-shadow roots. If the top-level document has no role match, role locators also-search ordinary iframes and OOPIFs.--Refs are scoped to the Page that produced them. Take another snapshot after-navigation, a substantial DOM change, raw CDP, or before reusing a ref in a-later round.--After opening a menu or dialog that rerenders its contents, take a new snapshot-before selecting an item from it.+immediate action and a generated locator for reuse. A missing ref does not mean+that an element is inert: use its role, text, and surrounding context to judge+whether it is interactive. If it clearly represents the intended control, try+a role locator or an exact text locator such as `text="Save changes"`, then+verify the result with a fresh snapshot. CSS searches nested open shadow roots.+If the top-level document has no role match, role locators also search ordinary+iframes and OOPIFs.++A snapshot is temporary: it describes one Page at one moment, and its refs+belong only to that Page. After any action that may change the page—navigation,+clicking, filling, keyboard input, opening a menu or dialog, page JavaScript, or+raw CDP—take a fresh snapshot before choosing the next target. Also refresh+before using a ref in a later round.### Visual pages: screenshot, mouse, and keyboarddiff --git a/skills/ego-browser/references/api.md b/skills/ego-browser/references/api.mdindex a85197c..7523d62 100644--- a/skills/ego-browser/references/api.md+++ b/skills/ego-browser/references/api.md@@ -37,35 +37,35 @@ High-level Page actions return a receipt that may contain `popups` or a synchron## Page-| API | Options | Purpose |-| --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |-| `page.label` | — | Durable Page label used to restore the tab across rounds. |-| `page.spaceId` | — | Numeric identifier of the Page's task space. |-| `page.openedBy` | — | Conservative origin attribution for this Page. |-| `page.targetId` | — | Internal browser target identifier for advanced Target-domain CDP only. |-| `await page.goto(url, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Navigate this Page in place. |-| `await page.snapshot({ scope?, includeActionMarks?, includeStableLocator? })` | `scope` (full_page, only_within_viewport) — Snapshot scope.<br>`includeActionMarks` — Include action marks.<br>`includeStableLocator` — Include stable locators. | Return a full semantic snapshot with Page provenance. |-| `await page.screenshot({ path?, fullPage?, clip?, raw? })` | `path` — Absolute output path.<br>`fullPage` — Capture the full scrollable page.<br>`clip` — CSS-pixel clipping rectangle.<br>`raw` — Bypass device-pixel-ratio correction. | Capture this Page to a PNG file. |-| `await page.url()` | — | Read this Page's current URL. |-| `await page.waitForURL(urlOrRegExp, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Wait for an exact URL or regular-expression match. |-| `await page.waitForTimeout(timeout)` | — | Wait a fixed number of milliseconds without activating this Page. |-| `await page.title()` | — | Read this Page's current title. |-| `await page.info()` | — | Read URL, title, viewport, scroll, and dialog state. |-| `await page.evaluate(fnOrString, argument?)` | — | Run JavaScript in this Page with JSON-serializable data. |-| `await page.fetch(url, options?)` | `timeout` — Maximum duration in milliseconds.<br>`method` — HTTP method.<br>`headers` — Request headers.<br>`body` — Request body.<br>`cache` (default, no-store, reload, no-cache, force-cache, only-if-cached) — Fetch cache mode.<br>`credentials` (omit, same-origin, include) — Fetch credentials mode.<br>`integrity` — Subresource integrity value.<br>`keepalive` — Allow the request to outlive the page.<br>`mode` (cors, no-cors, same-origin) — Fetch request mode.<br>`redirect` (follow, error, manual) — Redirect handling mode.<br>`referrer` — Request referrer.<br>`referrerPolicy` — Request referrer policy. | Run window.fetch in this Page and return a structured response. |-| `await page.cdp(method, params?, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Send a CDP command through this Page's target session. |-| `await page.waitForSelector(selector, { timeout?, state? })` | `timeout` — Maximum duration in milliseconds.<br>`state` (attached, detached, visible, hidden) — Required element state. | Wait for an element state in this Page. |-| `await page.waitForLoadState(state, { timeout?, idleMs? })` | `timeout` — Maximum duration in milliseconds.<br>`idleMs` — Required network-idle window in milliseconds. | Wait for DOM content, load, or network-idle state. |-| `await page.events()` | — | Read and clear CDP events buffered for this Page. |-| `await page.click(selector, { button?, clickCount?, delay?, position? })` | `button` (left, middle, right) — Mouse button.<br>`clickCount` — Number of clicks.<br>`delay` — Input delay in milliseconds.<br>`position` — CSS-pixel offset from the element's top-left corner. | Click an element with native CDP input. |-| `await page.dblclick(selector, { button?, delay?, position? })` | `button` (left, middle, right) — Mouse button.<br>`delay` — Input delay in milliseconds.<br>`position` — CSS-pixel offset from the element's top-left corner. | Double-click an element with native CDP input. |-| `await page.hover(selector, { position? })` | `position` — CSS-pixel offset from the element's top-left corner. | Move the mouse over an element. |-| `await page.dragAndDrop(source, target, { button?, sourcePosition?, targetPosition? })` | `button` (left, middle, right) — Mouse button.<br>`sourcePosition` — CSS-pixel offset from the element's top-left corner.<br>`targetPosition` — CSS-pixel offset from the element's top-left corner. | Drag from one element to another. |-| `await page.fill(selector, value, { clearFirst? })` | `clearFirst` — Clear the current value before filling. | Focus and fill an input-like element, then verify its value. |-| `await page.setInputFiles(selector, pathOrPaths)` | — | Set files on a file input without opening the system chooser. |-| `page.waitForFileChooser({ timeout? })` | `timeout` — Maximum duration in milliseconds. | Wait for a dynamically created file chooser. |-| `await page.scrollBy(deltaY, { deltaX?, behavior? })` | `deltaX` — Horizontal CSS-pixel delta.<br>`behavior` (auto, instant, smooth) — Scroll behavior. | Scroll this Page by CSS-pixel deltas. |-| `await page.close()` | — | Close this Page after confirming its tab disappeared. |+| API | Options | Purpose |+| --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |+| `page.label` | — | Durable Page label used to restore the tab across rounds. |+| `page.spaceId` | — | Numeric identifier of the Page's task space. |+| `page.openedBy` | — | Conservative origin attribution for this Page. |+| `page.targetId` | — | Internal browser target identifier for advanced Target-domain CDP only. |+| `await page.goto(url, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Navigate this Page in place. |+| `await page.snapshot({ scope?, includeActionMarks?, includeStableLocator? })` | `scope` (full_page, only_within_viewport) — Snapshot scope; defaults to only_within_viewport.<br>`includeActionMarks` — Include action marks.<br>`includeStableLocator` — Include stable locators. | Return a semantic snapshot of the current viewport with Page provenance. |+| `await page.screenshot({ path?, fullPage?, clip?, raw? })` | `path` — Absolute output path.<br>`fullPage` — Capture the full scrollable page.<br>`clip` — CSS-pixel clipping rectangle.<br>`raw` — Bypass device-pixel-ratio correction. | Capture this Page to a PNG file. |+| `await page.url()` | — | Read this Page's current URL. |+| `await page.waitForURL(urlOrRegExp, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Wait for an exact URL or regular-expression match. |+| `await page.waitForTimeout(timeout)` | — | Wait a fixed number of milliseconds without activating this Page. |+| `await page.title()` | — | Read this Page's current title. |+| `await page.info()` | — | Read URL, title, viewport, scroll, and dialog state. |+| `await page.evaluate(fnOrString, argument?)` | — | Run JavaScript in this Page with JSON-serializable data. |+| `await page.fetch(url, options?)` | `timeout` — Maximum duration in milliseconds.<br>`method` — HTTP method.<br>`headers` — Request headers.<br>`body` — Request body.<br>`cache` (default, no-store, reload, no-cache, force-cache, only-if-cached) — Fetch cache mode.<br>`credentials` (omit, same-origin, include) — Fetch credentials mode.<br>`integrity` — Subresource integrity value.<br>`keepalive` — Allow the request to outlive the page.<br>`mode` (cors, no-cors, same-origin) — Fetch request mode.<br>`redirect` (follow, error, manual) — Redirect handling mode.<br>`referrer` — Request referrer.<br>`referrerPolicy` — Request referrer policy. | Run window.fetch in this Page and return a structured response. |+| `await page.cdp(method, params?, { timeout? })` | `timeout` — Maximum duration in milliseconds. | Send a CDP command through this Page's target session. |+| `await page.waitForSelector(selector, { timeout?, state? })` | `timeout` — Maximum duration in milliseconds.<br>`state` (attached, detached, visible, hidden) — Required element state. | Wait for an element state in this Page. |+| `await page.waitForLoadState(state, { timeout?, idleMs? })` | `timeout` — Maximum duration in milliseconds.<br>`idleMs` — Required network-idle window in milliseconds. | Wait for DOM content, load, or network-idle state. |+| `await page.events()` | — | Read and clear CDP events buffered for this Page. |+| `await page.click(selector, { button?, clickCount?, delay?, position? })` | `button` (left, middle, right) — Mouse button.<br>`clickCount` — Number of clicks.<br>`delay` — Input delay in milliseconds.<br>`position` — CSS-pixel offset from the element's top-left corner. | Click an element with native CDP input. |+| `await page.dblclick(selector, { button?, delay?, position? })` | `button` (left, middle, right) — Mouse button.<br>`delay` — Input delay in milliseconds.<br>`position` — CSS-pixel offset from the element's top-left corner. | Double-click an element with native CDP input. |+| `await page.hover(selector, { position? })` | `position` — CSS-pixel offset from the element's top-left corner. | Move the mouse over an element. |+| `await page.dragAndDrop(source, target, { button?, sourcePosition?, targetPosition? })` | `button` (left, middle, right) — Mouse button.<br>`sourcePosition` — CSS-pixel offset from the element's top-left corner.<br>`targetPosition` — CSS-pixel offset from the element's top-left corner. | Drag from one element to another. |+| `await page.fill(selector, value, { clearFirst? })` | `clearFirst` — Clear the current value before filling. | Focus and fill an input-like element, then verify its value. |+| `await page.setInputFiles(selector, pathOrPaths)` | — | Set files on a file input without opening the system chooser. |+| `page.waitForFileChooser({ timeout? })` | `timeout` — Maximum duration in milliseconds. | Wait for a dynamically created file chooser. |+| `await page.scrollBy(deltaY, { deltaX?, behavior? })` | `deltaX` — Horizontal CSS-pixel delta.<br>`behavior` (auto, instant, smooth) — Scroll behavior. | Scroll this Page by CSS-pixel deltas. |+| `await page.close()` | — | Close this Page after confirming its tab disappeared. |## Page.mouse