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
fix(ego-browser): restrict screenshot scale to css
Tachikoma34166b9a6586
diff --git a/package/ego-browser/src/driver/observe.test.mjs b/package/ego-browser/src/driver/observe.test.mjsindex e5fa10c..116da01 100644--- a/package/ego-browser/src/driver/observe.test.mjs+++ b/package/ego-browser/src/driver/observe.test.mjs@@ -171,6 +171,40 @@ test("captureScreenshot clips the currently visible scrolled viewport", async ()}});+test("captureScreenshot keeps CSS-pixel sizing when scale is explicit", async () => {+ const restore = setOverrides({+ async writeFile() {},+ });+ try {+ await withCdpRuntime(async ({ sent }) => {+ await captureScreenshot("/tmp/ego-browser-css-shot.png", {+ scale: "css",+ });++ assert.equal(+ sent.some((request) => request.method === "Runtime.evaluate"),+ true,+ );+ const screenshot = sent.find(+ (request) => request.method === "Page.captureScreenshot",+ );+ assert.equal(screenshot.params.clip.scale, 0.5);+ });+ } finally {+ restore();+ }+});++test("captureScreenshot rejects unsupported device scale", async () => {+ await assert.rejects(+ () =>+ captureScreenshot("/tmp/ego-browser-device-shot.png", {+ scale: "device",+ }),+ /captureScreenshot scale must be css/,+ );+});+test("captureScreenshot creates missing parent directories", async () => {const root = await mkdtemp(join(tmpdir(), "ego-browser-screenshot-test-"));const outputPath = join(root, "nested", "screenshots", "page.png");diff --git a/package/ego-browser/src/driver/observe.ts b/package/ego-browser/src/driver/observe.tsindex 0bb9cee..b2cbf62 100644--- a/package/ego-browser/src/driver/observe.ts+++ b/package/ego-browser/src/driver/observe.ts@@ -35,10 +35,13 @@ type ScreenshotClip = {scale?: number;};+export type ScreenshotScale = "css";+export type CaptureScreenshotOptions = {full?: boolean;raw?: boolean;clip?: ScreenshotClip;+ scale?: ScreenshotScale;};export async function drainEvents() {@@ -92,6 +95,7 @@ export async function captureScreenshot(path?: string,options: CaptureScreenshotOptions = {},) {+ assertScreenshotScale(options.scale);const sessionId = isBrowserRuntime() ? await ensureSession() : undefined;return captureScreenshotForSession(path, options, sessionId);}@@ -105,11 +109,15 @@ export async function captureScreenshotForSession(options: CaptureScreenshotOptions = {},sessionId?: string,) {+ assertScreenshotScale(options.scale);const outputPath =path ??join(tmpdir(), `ego-browser-shot-${process.pid}-${++screenshotSeq}.png`);const full = options.full ?? false;- const raw = options.raw ?? false;+ // CSS-pixel sizing is the default and the only declarative scale mode. Keep+ // the legacy raw flag as an internal compatibility escape hatch.+ const scale = options.scale ?? "css";+ const raw = scale === "css" ? false : (options.raw ?? false);const params: any = {format: "png",captureBeyondViewport: full,@@ -171,3 +179,11 @@ export async function captureScreenshotForSession(await state.writeFile(outputPath, Buffer.from(result.data, "base64"));return outputPath;}++function assertScreenshotScale(+ scale: unknown,+): asserts scale is ScreenshotScale | undefined {+ if (scale !== undefined && scale !== "css") {+ throw new TypeError("captureScreenshot scale must be css");+ }+}diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjsindex fa86b06..4625261 100644--- a/package/ego-browser/src/page-model.test.mjs+++ b/package/ego-browser/src/page-model.test.mjs@@ -2014,6 +2014,24 @@ test("metadata reads stay target-scoped while evaluate and screenshot activate t),"page.screenshot must map Playwright-style options to the v1 capture driver",);+ await assert.rejects(+ () => first.screenshot({ path: "/tmp/device.png", scale: "device" }),+ /scale must be one of css/,+ );+ assert.equal(+ await first.screenshot({ path: "/tmp/css.png", scale: "css" }),+ "/tmp/css.png",+ );+ assert(+ fixture.calls.some(+ ([kind, path, options, sessionId]) =>+ kind === "screenshot" &&+ path === "/tmp/css.png" &&+ options.scale === "css" &&+ sessionId === "session:target-1",+ ),+ "page.screenshot must forward the explicit scale mode",+ );await assert.rejects(() => first.screenshot("/tmp/legacy.png"),/options must be an object/,diff --git a/package/ego-browser/src/public-api-schema.test.mjs b/package/ego-browser/src/public-api-schema.test.mjsindex 9ca3cac..f4e5d06 100644--- a/package/ego-browser/src/public-api-schema.test.mjs+++ b/package/ego-browser/src/public-api-schema.test.mjs@@ -53,6 +53,10 @@ test("schema-driven option validation rejects unknown and invalid fields", () =>timeout: 500,});validatePublicApiOptions("Page.fetch", { saveAs: "/tmp/image.png" });+ validatePublicApiOptions("Page.screenshot", {+ path: "/tmp/image.png",+ scale: "css",+ });validatePublicApiOptions("TaskSpace.finish", { keep: [] });validatePublicApiOptions("TaskSpace.finish", { keep: ["p2"] });validatePublicApiOptions("TaskSpace.finish", { keep: "all" });@@ -76,6 +80,14 @@ test("schema-driven option validation rejects unknown and invalid fields", () =>() => validatePublicApiOptions("Page.click", { trial: true }),/unknown option: trial\. Expected: await page\.click\(selector, \{ button\?, clickCount\?, delay\?, position\?, force\?, timeout\? \}\)/,);+ assert.throws(+ () => validatePublicApiOptions("Page.screenshot", { scale: "invalid" }),+ /scale must be one of css/,+ );+ assert.throws(+ () => validatePublicApiOptions("Page.screenshot", { scale: "device" }),+ /scale must be one of css/,+ );assert.throws(() => validatePublicApiOptions("Page.goto", { timeout: 0 }),/timeout must be a positive number of milliseconds/,diff --git a/package/ego-browser/src/public-api-schema.ts b/package/ego-browser/src/public-api-schema.tsindex 4e0e262..fdb7943 100644--- a/package/ego-browser/src/public-api-schema.ts+++ b/package/ego-browser/src/public-api-schema.ts@@ -244,7 +244,8 @@ export const PUBLIC_API_SCHEMA: readonly PublicApiEntry[] = [},{name: "Page.screenshot",- signature: "await page.screenshot({ path?, fullPage?, clip?, raw? })",+ signature:+ "await page.screenshot({ path?, fullPage?, clip?, scale?, raw? })",summary: "Capture this Page to a PNG file.",options: {path: option(@@ -253,6 +254,11 @@ export const PUBLIC_API_SCHEMA: readonly PublicApiEntry[] = [),fullPage: option("boolean", "Capture the full scrollable page."),clip: option("clip", "CSS-pixel clipping rectangle."),+ scale: option(+ "string",+ "Output scale mode; css uses CSS-pixel sizing and is the default.",+ ["css"],+ ),raw: option("boolean", "Bypass device-pixel-ratio correction."),},},diff --git a/skills/ego-browser/references/api.md b/skills/ego-browser/references/api.mdindex f643c87..7ac5ef3 100644--- a/skills/ego-browser/references/api.md+++ b/skills/ego-browser/references/api.md@@ -50,7 +50,7 @@ Selectors accept refs, Ego locators, XPath, and raw CSS. A small compatibility s| `await page.goto(url, { referer?, timeout?, waitUntil? })` | `referer` — HTTP Referer header for the navigation.<br>`timeout` — Maximum duration in milliseconds.<br>`waitUntil` (commit, domcontentloaded, load, networkidle) — Completion state; defaults to load. networkidle requires 500ms without network activity. | Navigate this Page in place. Timeout errors report whether the new document committed, plus its URL and readyState when available. || `await page.reload({ timeout?, waitUntil? })` | `timeout` — Maximum duration in milliseconds.<br>`waitUntil` (commit, domcontentloaded, load, networkidle) — Completion state; defaults to load. networkidle requires 500ms without network activity. | Reload this Page and wait for the selected navigation state. || `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` — Output path; missing parent directories are created.<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.screenshot({ path?, fullPage?, clip?, scale?, raw? })` | `path` — Output path; missing parent directories are created.<br>`fullPage` — Capture the full scrollable page.<br>`clip` — CSS-pixel clipping rectangle.<br>`scale` (css) — Output scale mode; css uses CSS-pixel sizing and is the default.<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.waitForEvent("popup", { timeout? })` | `timeout` — Maximum duration in milliseconds. | Wait for this Page's next popup; call before the triggering action. |