diff options
| -rw-r--r-- | src/domains/box.ts | 5 | ||||
| -rw-r--r-- | src/domains/keyboard.ts | 8 | ||||
| -rw-r--r-- | test/domains/box-test.ts | 2 |
3 files changed, 8 insertions, 7 deletions
diff --git a/src/domains/box.ts b/src/domains/box.ts index 7b12e82..e013f70 100644 --- a/src/domains/box.ts +++ b/src/domains/box.ts @@ -41,7 +41,10 @@ export const boxOf = async ( return err({ kind: "invalid_state", message: "DOM.getBoxModel returned an incomplete content quad" }); } if (model.width <= 0 || model.height <= 0) { - return err({ kind: "invalid_state", message: "element has a zero-size box and cannot be clicked" }); + return err({ + kind: "invalid_state", + message: "element has a zero-size box and cannot be clicked", + }); } return ok(centreOf(model)); }; diff --git a/src/domains/keyboard.ts b/src/domains/keyboard.ts index 21681c5..6722ffb 100644 --- a/src/domains/keyboard.ts +++ b/src/domains/keyboard.ts @@ -27,10 +27,6 @@ export const typeTool = defineBrowserTool({ ], parameters: TypeArgs, async handler(args, { client }): Promise<Result<ToolOk, ToolErr>> { - // Guard against silent text loss: Input.insertText succeeds regardless of - // whether an editable element is focused, so without this check typed text - // can vanish into the void with no error. Fail loudly with an actionable - // message instead. IIFE starts with "(" so evaluateJs returns it directly. const focused = await client.evaluateJs(safeJs` (() => { const el = document.activeElement; @@ -39,8 +35,8 @@ export const typeTool = defineBrowserTool({ return { ok, tag: el ? el.tagName : null }; })() `); - if (focused.success && isFocusProbe(focused.data)) { - const f = focused.data; + if (focused.success) { + const f: FocusProbe = isFocusProbe(focused.data) ? focused.data : { ok: false, tag: null }; if (!f.ok) { return err({ kind: "invalid_state", diff --git a/test/domains/box-test.ts b/test/domains/box-test.ts index cb930a0..248ae38 100644 --- a/test/domains/box-test.ts +++ b/test/domains/box-test.ts @@ -5,6 +5,8 @@ import { centreOf } from "../../src/domains/box"; describe("box centre", () => { test("computes the centre from a content quad", () => { const b = centreOf({ content: [10, 20, 110, 20, 110, 70, 10, 70], width: 100, height: 50 }); + assert.equal(b.x, 10); + assert.equal(b.y, 20); assert.equal(b.cx, 60); assert.equal(b.cy, 45); assert.equal(b.width, 100); |
