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
test page drag and canvas drawing
Aute4eed403af8b1
diff --git a/docs/runtime-v2-architecture.md b/docs/runtime-v2-architecture.mdindex e558e31..ee5b885 100644--- a/docs/runtime-v2-architecture.md+++ b/docs/runtime-v2-architecture.md@@ -480,6 +480,8 @@ surface,不属于本阶段。- screenshot、evaluate、fetch、键盘和鼠标都操作并激活指定 Page。- 页面动作不安装观察探针;高层动作仍能返回 popup 回执。- `keyboard.press()` 产生 native/trusted 输入;新版不暴露 synthetic dispatch。+- `dragAndDrop()` 不只发出起止事件,还能把简单的 pointer-driven 元素实际拖到目标+ 区域;`mouse.down/move/up` 能在 Canvas 上保持按键状态并连续绘制曲线和折线。- snapshot 始终返回全量并标明来源,不接受 `diff`。- 旧格式账本能读取,并在下一次写入时删掉过期字段。- 1.2.3 代表性脚本原样通过。diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/index.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/index.mjsindex 5ab5d07..7f5804b 100644--- a/package/ego-browser/scripts/real-browser-e2e/cases/index.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/cases/index.mjs@@ -8,6 +8,7 @@ import { keyboardCase } from "./keyboard.mjs";import { keyboardRegressionCase } from "./keyboard-regression.mjs";import { pageKeyboardInterfaceCase } from "./page-keyboard.mjs";import { pageClickHitTargetCase } from "./page-click-hit-target.mjs";+import { pageDragAndDrawCase } from "./page-drag-and-draw.mjs";import { pageScrolledScreenshotCase } from "./page-screenshot.mjs";import { pageSnapshotLocatorCase } from "./page-snapshot-locators.mjs";import { pageLoadStatesCase } from "./page-load-states.mjs";@@ -68,6 +69,7 @@ export const e2eCases = [{ name: "page fetch", body: pageFetchCase },{ name: "page actions and popup adoption", body: pageActionsAndPopupCase },{ name: "Page click hit target", body: pageClickHitTargetCase },+ { name: "Page drag and canvas drawing", body: pageDragAndDrawCase },{ name: "Page scrolled screenshot", body: pageScrolledScreenshotCase },{ name: "Page snapshot locator quality", body: pageSnapshotLocatorCase },{ name: "Page load states", body: pageLoadStatesCase },diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-drag-and-draw.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-drag-and-draw.mjsnew file mode 100644index 0000000..4a8e10a--- /dev/null+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-drag-and-draw.mjs@@ -0,0 +1,82 @@+export function pageDragAndDrawCase() {+ return `+ const task = await taskSpace(taskName);+ const page = await task.openPage(baseUrl + "/pointer-workbench", {+ as: "pointer-workbench",+ });+ const beforePath = join(artifactDir, "pointer-workbench-before.png");+ const afterPath = join(artifactDir, "pointer-workbench-after.png");+ await page.screenshot({ path: beforePath });++ await page.dragAndDrop("#drag-source", "#drop-target");+ const dragged = await page.evaluate(() => window.__pointerWorkbench.read().drag);+ assertEqual(dragged.landed, true, "dragAndDrop moves the element into the target");+ assert(dragged.moveCount >= 1, "dragAndDrop delivers movement while the button is held");+ assertEqual(dragged.downTrusted, true, "dragAndDrop starts with trusted input");+ assertEqual(dragged.movesTrusted, true, "dragAndDrop movement stays trusted");+ assertEqual(dragged.upTrusted, true, "dragAndDrop ends with trusted input");++ const canvas = await page.evaluate(() => {+ const rect = document.querySelector("#drawing-canvas").getBoundingClientRect();+ return { left: rect.left, top: rect.top };+ });+ const curve = [+ [70, 85],+ [135, 35],+ [215, 45],+ [285, 105],+ [360, 125],+ ];+ await page.mouse.move(canvas.left + curve[0][0], canvas.top + curve[0][1]);+ await page.mouse.down();+ for (const [x, y] of curve.slice(1)) {+ await page.mouse.move(canvas.left + x, canvas.top + y, { steps: 4 });+ }+ await page.mouse.up();++ const polyline = [+ [90, 230],+ [230, 165],+ [390, 245],+ [570, 175],+ ];+ await page.mouse.move(canvas.left + polyline[0][0], canvas.top + polyline[0][1]);+ await page.mouse.down();+ for (const [x, y] of polyline.slice(1)) {+ await page.mouse.move(canvas.left + x, canvas.top + y);+ }+ await page.mouse.up();++ const drawing = await page.evaluate(() => window.__pointerWorkbench.read().drawing);+ assertEqual(drawing.strokes.length, 2, "canvas records one curved stroke and one polyline");+ assert(+ drawing.strokes[0].points.length >= 17,+ "the curved stroke receives intermediate mousemove steps"+ );+ assertEqual(+ drawing.strokes[1].points.length,+ polyline.length,+ "the polyline receives its explicit vertices"+ );+ assertEqual(drawing.allButtonsHeld, true, "canvas moves retain the pressed left button");+ assertEqual(drawing.allTrusted, true, "canvas drawing uses trusted mouse input throughout");+ assert(+ drawing.strokes.every((stroke) => stroke.downTrusted && stroke.upTrusted),+ "both canvas strokes have trusted down and up boundaries"+ );+ assert(drawing.inkPixels > 1000, "canvas contains a substantial amount of drawn ink");+ assert(+ drawing.inkBounds.minX < 80 && drawing.inkBounds.maxX > 560 &&+ drawing.inkBounds.minY < 50 && drawing.inkBounds.maxY > 235,+ "drawn pixels span the expected curve and polyline regions"+ );++ await page.screenshot({ path: afterPath });+ const before = await readFile(beforePath);+ const after = await readFile(afterPath);+ assert(before.length > 100 && after.length > 100, "visual artifacts contain PNG data");+ assert(!before.equals(after), "dragging and drawing visibly change the rendered page");++ await page.close();+ `;+}diff --git a/package/ego-browser/scripts/real-browser-e2e/fixture.mjs b/package/ego-browser/scripts/real-browser-e2e/fixture.mjsindex c6931d8..8fd71be 100644--- a/package/ego-browser/scripts/real-browser-e2e/fixture.mjs+++ b/package/ego-browser/scripts/real-browser-e2e/fixture.mjs@@ -168,6 +168,11 @@ export async function startFixtureServer(taskName) {res.end(visualPageHtml());return;}+ if (url.pathname === "/pointer-workbench") {+ res.writeHead(200, { "content-type": "text/html" });+ res.end(pointerWorkbenchHtml());+ return;+ }if (url.pathname === "/slow-page") {const delayMs = Number(url.searchParams.get("ms") || 250);setTimeout(() => {@@ -562,3 +567,204 @@ function visualPageHtml() {</body></html>`;}++function pointerWorkbenchHtml() {+ return `<!doctype html>+<html>+ <head>+ <meta charset="utf-8">+ <title>ego-lite pointer workbench</title>+ <style>+ * { box-sizing: border-box; }+ body { background: #f6f7fb; font-family: system-ui, sans-serif; margin: 0; }+ h1 { font-size: 20px; margin: 12px 24px; }+ #drag-area {+ background: #fff;+ border: 2px solid #cbd5e1;+ height: 170px;+ margin: 0 24px 16px;+ position: relative;+ width: 720px;+ }+ #drag-source, #drop-target {+ align-items: center;+ display: flex;+ justify-content: center;+ position: absolute;+ user-select: none;+ }+ #drag-source {+ background: #ef4444;+ color: #fff;+ height: 56px;+ left: 32px;+ top: 54px;+ width: 72px;+ z-index: 2;+ }+ #drag-source.dropped { background: #16a34a; }+ #drop-target {+ background: #dcfce7;+ border: 3px dashed #16a34a;+ height: 110px;+ left: 540px;+ top: 28px;+ width: 140px;+ }+ #drawing-canvas {+ background: #fff;+ border: 2px solid #334155;+ display: block;+ height: 300px;+ margin: 0 24px;+ width: 720px;+ }+ </style>+ </head>+ <body>+ <h1>Pointer workbench</h1>+ <div id="drag-area">+ <div id="drag-source">A</div>+ <div id="drop-target">B</div>+ </div>+ <canvas id="drawing-canvas" width="720" height="300"></canvas>+ <script>+ const dragArea = document.querySelector("#drag-area");+ const dragSource = document.querySelector("#drag-source");+ const dropTarget = document.querySelector("#drop-target");+ const canvas = document.querySelector("#drawing-canvas");+ const context = canvas.getContext("2d");+ context.fillStyle = "#ffffff";+ context.fillRect(0, 0, canvas.width, canvas.height);+ context.strokeStyle = "#172033";+ context.lineCap = "round";+ context.lineJoin = "round";+ context.lineWidth = 6;++ const state = {+ drag: {+ downTrusted: false,+ landed: false,+ moveCount: 0,+ movesTrusted: true,+ upTrusted: false,+ },+ drawing: {+ allButtonsHeld: true,+ allTrusted: true,+ strokes: [],+ },+ };+ window.__pointerWorkbench = state;++ let drag;+ dragSource.addEventListener("mousedown", (event) => {+ if (event.button !== 0) return;+ const rect = dragSource.getBoundingClientRect();+ drag = {+ offsetX: event.clientX - rect.left,+ offsetY: event.clientY - rect.top,+ };+ state.drag.downTrusted = event.isTrusted;+ event.preventDefault();+ });+ window.addEventListener("mousemove", (event) => {+ if (!drag) return;+ const areaRect = dragArea.getBoundingClientRect();+ dragSource.style.left =+ event.clientX - areaRect.left - drag.offsetX + "px";+ dragSource.style.top =+ event.clientY - areaRect.top - drag.offsetY + "px";+ state.drag.moveCount += 1;+ state.drag.movesTrusted &&= event.isTrusted;+ });+ window.addEventListener("mouseup", (event) => {+ if (!drag) return;+ const sourceRect = dragSource.getBoundingClientRect();+ const targetRect = dropTarget.getBoundingClientRect();+ const centerX = sourceRect.left + sourceRect.width / 2;+ const centerY = sourceRect.top + sourceRect.height / 2;+ state.drag.landed =+ centerX >= targetRect.left &&+ centerX <= targetRect.right &&+ centerY >= targetRect.top &&+ centerY <= targetRect.bottom;+ state.drag.upTrusted = event.isTrusted;+ if (state.drag.landed) dragSource.classList.add("dropped");+ drag = null;+ });++ let activeStroke;+ const canvasPoint = (event) => {+ const rect = canvas.getBoundingClientRect();+ return { x: event.clientX - rect.left, y: event.clientY - rect.top };+ };+ canvas.addEventListener("mousedown", (event) => {+ if (event.button !== 0) return;+ const point = canvasPoint(event);+ activeStroke = {+ points: [point],+ downTrusted: event.isTrusted,+ upTrusted: false,+ };+ state.drawing.strokes.push(activeStroke);+ state.drawing.allTrusted &&= event.isTrusted;+ context.beginPath();+ context.moveTo(point.x, point.y);+ event.preventDefault();+ });+ canvas.addEventListener("mousemove", (event) => {+ if (!activeStroke) return;+ const point = canvasPoint(event);+ activeStroke.points.push(point);+ state.drawing.allButtonsHeld &&= (event.buttons & 1) === 1;+ state.drawing.allTrusted &&= event.isTrusted;+ context.lineTo(point.x, point.y);+ context.stroke();+ });+ window.addEventListener("mouseup", (event) => {+ if (!activeStroke) return;+ activeStroke.upTrusted = event.isTrusted;+ state.drawing.allTrusted &&= event.isTrusted;+ activeStroke = null;+ });++ state.read = () => {+ const pixels = context.getImageData(0, 0, canvas.width, canvas.height).data;+ let inkPixels = 0;+ let minX = canvas.width;+ let minY = canvas.height;+ let maxX = -1;+ let maxY = -1;+ for (let y = 0; y < canvas.height; y += 1) {+ for (let x = 0; x < canvas.width; x += 1) {+ const offset = (y * canvas.width + x) * 4;+ if (pixels[offset] > 80 || pixels[offset + 1] > 80 || pixels[offset + 2] > 80) {+ continue;+ }+ inkPixels += 1;+ minX = Math.min(minX, x);+ minY = Math.min(minY, y);+ maxX = Math.max(maxX, x);+ maxY = Math.max(maxY, y);+ }+ }+ return {+ drag: { ...state.drag },+ drawing: {+ allButtonsHeld: state.drawing.allButtonsHeld,+ allTrusted: state.drawing.allTrusted,+ inkBounds: inkPixels > 0 ? { minX, minY, maxX, maxY } : null,+ inkPixels,+ strokes: state.drawing.strokes.map((stroke) => ({+ downTrusted: stroke.downTrusted,+ points: stroke.points,+ upTrusted: stroke.upTrusted,+ })),+ },+ };+ };+ </script>+ </body>+</html>`;+}