The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scale drive_preview input by the guest zoom factor
teknium159496ffc6d7e
diff --git a/apps/desktop/src/app/chat/right-rail/preview-input.test.ts b/apps/desktop/src/app/chat/right-rail/preview-input.test.tsnew file mode 100644index 00000000000..b00e9e8c076--- /dev/null+++ b/apps/desktop/src/app/chat/right-rail/preview-input.test.ts@@ -0,0 +1,31 @@+import { describe, expect, it } from 'vitest'++import { toWebviewInputSpace } from './preview-input'++// #116281: the act engine measures targets in guest CSS pixels, but the+// webview's input space is css × zoom. At the shipped 90 % default an+// unscaled click landed 1/0.9 too far from the origin and missed silently.+describe('toWebviewInputSpace', () => {+ it('scales pointer events by the guest zoom so the reporter\'s 500,310 target is hit at 90 %', () => {+ const down = toWebviewInputSpace({ button: 'left', clickCount: 1, type: 'mouseDown', x: 500, y: 310 }, 0.9)++ expect(down).toEqual({ button: 'left', clickCount: 1, type: 'mouseDown', x: 450, y: 279 })+ expect(toWebviewInputSpace({ deltaX: 0, deltaY: 600, type: 'mouseWheel', x: 380, y: 467 }, 1.25)).toEqual({+ deltaX: 0,+ deltaY: 600,+ type: 'mouseWheel',+ x: 475,+ y: 584+ })+ })++ it('leaves events untouched at 100 %, with an unknown zoom, and for keys', () => {+ const move = { type: 'mouseMove', x: 500, y: 382 } as const+ const key = { keyCode: 'Enter', type: 'keyDown' } as const++ expect(toWebviewInputSpace(move, 1)).toBe(move)+ expect(toWebviewInputSpace(move, undefined)).toBe(move)+ expect(toWebviewInputSpace(move, Number.NaN)).toBe(move)+ expect(toWebviewInputSpace(key, 0.9)).toBe(key)+ })+})diff --git a/apps/desktop/src/app/chat/right-rail/preview-input.ts b/apps/desktop/src/app/chat/right-rail/preview-input.tsindex c0f1dbb5a0d..ad6ff57911f 100644--- a/apps/desktop/src/app/chat/right-rail/preview-input.ts+++ b/apps/desktop/src/app/chat/right-rail/preview-input.ts@@ -12,9 +12,13 @@* webContents does not reach a guest (electron/electron#20333), which is why* this is a per-pane registry rather than something main could do.*- * Coordinates are relative to the webview, and the webview IS the guest- * viewport — so a rect the act engine measured inside the page needs no- * conversion on the way back out.+ * Coordinates are relative to the webview element, in the host's+ * device-independent pixels. The act engine measures inside the guest in CSS+ * pixels, and Chromium places guest positions at css × zoom (the context-menu+ * handler in preview-pane.tsx measured it live), so a rect measured in the page+ * must be scaled by the guest's zoom factor on the way back out — the shipped+ * default zoom is 90 %, and at that zoom an unscaled click lands 11 % too far+ * from the origin and silently misses its target (#116281).*/import { $rightRailActiveTabId } from '@/store/layout'@@ -33,6 +37,16 @@ export interface PreviewInputHandle {send: (event: PreviewInputEvent) => void}+/** Convert a point the act engine measured in guest CSS pixels into the+ * webview's input space. Key events carry no point and pass through. */+export function toWebviewInputSpace(event: PreviewInputEvent, zoomFactor: number | undefined): PreviewInputEvent {+ if (!('x' in event) || !zoomFactor || !Number.isFinite(zoomFactor) || zoomFactor <= 0 || zoomFactor === 1) {+ return event+ }++ return { ...event, x: Math.round(event.x * zoomFactor), y: Math.round(event.y * zoomFactor) }+}+const handles = new Map<string, PreviewInputHandle>()/** Register a live pane's input channel; returns an idempotent unregister. */diff --git a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx b/apps/desktop/src/app/chat/right-rail/preview-pane.tsxindex 1604d5b3435..7354901994d 100644--- a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx+++ b/apps/desktop/src/app/chat/right-rail/preview-pane.tsx@@ -67,7 +67,7 @@ import {import { type ConsoleEntry } from './preview-console-state'import { previewConsoleState } from './preview-console-store'import { LocalFilePreview, PreviewEmptyState } from './preview-file'-import { type PreviewInputEvent, registerPreviewInput } from './preview-input'+import { type PreviewInputEvent, registerPreviewInput, toWebviewInputSpace } from './preview-input'import { PREVIEW_BROWSER_ATTR, registerPreviewNav } from './preview-nav'import { registerPreviewPageReader } from './preview-reader'import { registerPreviewScriptRunner } from './preview-script-runner'@@ -95,6 +95,7 @@ type PreviewWebview = HTMLElement & {replaceMisspelling?: (word: string) => voidselectAll?: () => voidsendInputEvent?: (event: PreviewInputEvent) => void+ getZoomFactor?: () => number}/** Electron throws if getURL/getTitle run before attach + dom-ready, or after@@ -820,7 +821,9 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =throw new Error('preview webview cannot take input events')}- webview.sendInputEvent(event)+ // The guest keeps its own (per-host) zoom, which the act engine's CSS+ // measurements do not include — ask the webview, not the window.+ webview.sendInputEvent(toWebviewInputSpace(event, webview.getZoomFactor?.()))}})}, [isRemoteHtml, isWebPreview, tabId])