Skip to content

Commit 6e5a006

Browse files
committed
fix(browser): align coordinate guidance with screenshot mapping
1 parent 7e199fb commit 6e5a006

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎apps/desktop/src/main/browser-agent/driver.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3507,7 +3507,7 @@ describe('credential protection', () => {
35073507
const result = await driver.executeTool('chat-test', 'browser_click_at', { x: 9999, y: 5 })
35083508

35093509
expect(result.ok).toBe(false)
3510-
expect(result.error).toMatch(/divide image pixels by its scale/)
3510+
expect(result.error).toMatch(/X\/Y coordinate mapping and crop origin/)
35113511
})
35123512

35133513
it('inserts text into the focused editable at the caret', async () => {

‎apps/desktop/src/main/browser-agent/driver.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ function unwrapPageResult(result: unknown): unknown {
12371237
}
12381238
if (code === 'outside-viewport') {
12391239
throw new ToolError(
1240-
'That point is outside the visible viewport. Coordinates are CSS pixels within the current viewport — when reading them off a browser_screenshot, divide image pixels by its scale, and scroll the target into view first.'
1240+
"That point is outside the visible viewport. Coordinates are CSS pixels within the current viewport — when reading them off a browser_screenshot, follow its caption's X/Y coordinate mapping and crop origin, and scroll the target into view first."
12411241
)
12421242
}
12431243
if (code === 'ambiguous-editable') {
@@ -4219,7 +4219,7 @@ async function executeToolInner(
42194219
)
42204220
if (!isRecordLike(pointTarget) || pointTarget.found !== true) {
42214221
throw new ToolError(
4222-
'Nothing is rendered at that point. Coordinates are CSS pixels in the current viewport — when reading them off a browser_screenshot, divide image pixels by its scale.'
4222+
"Nothing is rendered at that point. Coordinates are CSS pixels in the current viewport — when reading them off a browser_screenshot, follow its caption's X/Y coordinate mapping and crop origin."
42234223
)
42244224
}
42254225
if (pointTarget.fileInput === true) {
@@ -4463,7 +4463,7 @@ async function executeToolInner(
44634463
)
44644464
if (!isRecordLike(probe) || probe.found !== true) {
44654465
throw new ToolError(
4466-
`Nothing is rendered at the ${which} point. Coordinates are CSS pixels in the current viewport — when reading them off a browser_screenshot, divide image pixels by its scale.`
4466+
`Nothing is rendered at the ${which} point. Coordinates are CSS pixels in the current viewport — when reading them off a browser_screenshot, follow its caption's X/Y coordinate mapping and crop origin.`
44674467
)
44684468
}
44694469
return {

‎apps/sim/lib/copilot/generated/tool-catalog-v1.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,12 @@ export const BrowserClickAt: ToolCatalogEntry = {
500500
x: {
501501
type: 'number',
502502
description:
503-
'X in CSS pixels within the current viewport. When read off a browser_screenshot, divide the image pixel value by scale and add clip.x when present.',
503+
"X in CSS pixels within the current viewport. When read off a browser_screenshot, follow its caption's X mapping and crop origin.",
504504
},
505505
y: {
506506
type: 'number',
507507
description:
508-
'Y in CSS pixels within the current viewport, converted from screenshot pixels the same way as x.',
508+
"Y in CSS pixels within the current viewport. When read off a browser_screenshot, follow its caption's Y mapping and crop origin.",
509509
},
510510
},
511511
required: ['x', 'y'],
@@ -1519,7 +1519,7 @@ export const BrowserScreenshot: ToolCatalogEntry = {
15191519
elementId: {
15201520
type: 'number',
15211521
description:
1522-
"Optional element id from the current tab's latest browser_snapshot. When present, capture only the visible portion of that top-page element without scrolling or changing layout. Scroll explicitly first if needed. Framed elements are rejected; use a viewport screenshot for them. Use the returned clip offset when converting image coordinates.",
1522+
"Optional element id from the current tab's latest browser_snapshot. When present, capture only the visible portion of that top-page element without scrolling or changing layout. Scroll explicitly first if needed. Framed elements are rejected; use a viewport screenshot for them. Follow the image caption's coordinate mapping, including its crop origin.",
15231523
},
15241524
},
15251525
},

‎apps/sim/lib/copilot/generated/tool-schemas-v1.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ export const TOOL_RUNTIME_SCHEMAS: Record<string, ToolRuntimeSchemaEntry> = {
225225
x: {
226226
type: 'number',
227227
description:
228-
'X in CSS pixels within the current viewport. When read off a browser_screenshot, divide the image pixel value by scale and add clip.x when present.',
228+
"X in CSS pixels within the current viewport. When read off a browser_screenshot, follow its caption's X mapping and crop origin.",
229229
},
230230
y: {
231231
type: 'number',
232232
description:
233-
'Y in CSS pixels within the current viewport, converted from screenshot pixels the same way as x.',
233+
"Y in CSS pixels within the current viewport. When read off a browser_screenshot, follow its caption's Y mapping and crop origin.",
234234
},
235235
},
236236
required: ['x', 'y'],
@@ -1430,7 +1430,7 @@ export const TOOL_RUNTIME_SCHEMAS: Record<string, ToolRuntimeSchemaEntry> = {
14301430
elementId: {
14311431
type: 'number',
14321432
description:
1433-
"Optional element id from the current tab's latest browser_snapshot. When present, capture only the visible portion of that top-page element without scrolling or changing layout. Scroll explicitly first if needed. Framed elements are rejected; use a viewport screenshot for them. Use the returned clip offset when converting image coordinates.",
1433+
"Optional element id from the current tab's latest browser_snapshot. When present, capture only the visible portion of that top-page element without scrolling or changing layout. Scroll explicitly first if needed. Framed elements are rejected; use a viewport screenshot for them. Follow the image caption's coordinate mapping, including its crop origin.",
14341434
},
14351435
},
14361436
},

‎apps/sim/lib/copilot/tools/client/browser-tool-result.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function sanitizeBrowserToolResultForModel(
5858
: null
5959
: { x: 0, y: 0 }
6060
const content = [
61-
`Screenshot${location}. This is the rendered ${clip ? 'element' : 'viewport'} only — it carries no element ids, so use browser_snapshot before interacting.`,
61+
`Screenshot${location}. This is the rendered ${clip ? 'element' : 'viewport'} only — it carries no element ids. Use browser_snapshot for element-ref actions and the mapping below for coordinate actions.`,
6262
viewportSize && `Viewport: ${viewportSize.width} × ${viewportSize.height} CSS pixels.`,
6363
imageSize && `Encoded image: ${imageSize.width} × ${imageSize.height} pixels.`,
6464
hasScale && `Image scale: X=${scaleX}, Y=${scaleY} encoded image pixels per CSS pixel.`,

0 commit comments

Comments
 (0)