{"record":{"id":"7873fd69d0e72400","repo":"Hmbown/CodeWhale","slug":"cursor-position-does-not-exist-on-touch-devices","errorCode":null,"errorMessage":"cursor position does not exist on touch devices","messagePattern":"cursor position does not exist on touch devices","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/harmonyos.mjs","lineNumber":271,"sourceCode":"      const d = Math.max(1, Math.min(5, Number(duration) || 1));\n      return uiInput([\"longClick\", \"300\", \"300\"]);\n    },\n    set_value: async ({ target, value }) => {\n      const b = await centerOf(target);\n      await uiInput([\"click\", String(b.cx), String(b.cy)]);\n      await new Promise((r) => setTimeout(r, 300));\n      await uiInput([\"inputText\", String(b.cx), String(b.cy), escDeviceText(String(value))]);\n      return { action_sent: true, strategy: \"uitest-element\" };\n    },\n    select_text: async () => { throw new ExecError(\"select_text is not exposed by uitest dumpLayout/uiInput on the harmony backend\"); },\n    perform_action: async ({ target, action }) => {\n      const b = await centerOf(target);\n      if (action === \"longClick\") return uiInput([\"longClick\", String(b.cx), String(b.cy)]);\n      return uiInput([\"click\", String(b.cx), String(b.cy)]);\n    },\n    read_clipboard: async () => { throw new ExecError(\"clipboard read is not exposed by hdc on current HarmonyOS builds\"); },\n    write_clipboard: async () => { throw new ExecError(\"clipboard write is not exposed by hdc on current HarmonyOS builds\"); },\n    cursor_position: async () => { throw new ExecError(\"cursor position does not exist on touch devices\"); },\n    recordingStart: async ({ intervalMs = 400 } = {}) => {\n      if (recording) throw new ExecError(`recording ${recording.id} already running`);\n      if (!(await have(\"ffmpeg\"))) throw new ExecError(\"ffmpeg is required on the host to mux harmony snapshot-series recordings\");\n      const id = crypto.randomBytes(4).toString(\"hex\");\n      const dir = fs.mkdtempSync(path.join(os.tmpdir(), `cu-rec-${id}-`));\n      const startedAt = new Date().toISOString();\n      const rec = recording = { id, dir, startedAt, intervalMs, seq: 0, controller: new AbortController() };\n      const tick = () => {\n        if (rec.stopped || rec.pending) return rec.pending;\n        rec.pending = (async () => {\n          const opts = { timeoutMs: 15_000, signal: rec.controller.signal };\n          const remote = `${DEVICE_TMP}-rec-${id}-${String(rec.seq).padStart(5, \"0\")}.jpeg`;\n          try {\n            await deviceOut([\"snapshot_display\", \"-f\", remote], opts);\n            await exec.pullFile(remote, path.join(dir, `f${String(rec.seq).padStart(5, \"0\")}.jpeg`), opts);\n            rec.seq++;\n          } finally { await shell([\"rm\", \"-f\", remote], opts).catch(() => {}); }\n        })().catch(() => {}).finally(() => { rec.pending = null; });","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/backends/harmonyos.mjs#L253-L289","documentation":"The HarmonyOS computer-use backend throws this from `cursor_position` because hdc-controlled HarmonyOS devices are touch devices with no mouse cursor; the backend fails closed instead of returning a fake coordinate. There is no way to query a pointer position on this platform, so the operation is intentionally unsupported.","triggerScenarios":"Calling `backend.cursor_position()` on a backend created via `create()` in harmonyos.mjs (backends/harmonyos.mjs:271).","commonSituations":"Generic computer-use automation code that queries cursor position across platforms; porting macOS/Windows-style mouse-based workflows to a HarmonyOS phone/tablet; implementing a UI status bar that shows cursor coordinates.","solutions":["Wrap cursor_position in a try/catch and treat 'not supported on touch devices' as 'no cursor' in your UI.","Skip cursor-position logic entirely when the selected backend is HarmonyOS (touch-only).","Use an element target with click/longClick instead of cursor-relative positioning for HarmonyOS automation."],"exampleFix":"// before\nconst pos = await backend.cursor_position();\n// after\nlet pos = null;\ntry { pos = await backend.cursor_position(); }\ncatch (e) { /* touch device: no cursor concept */ }","handlingStrategy":"try-catch","validationCode":"const isTouchBackend = backendName === \"harmonyos\";","typeGuard":"const cursorSupported = typeof backend?.cursor_position === \"function\" && backendName !== \"harmonyos\";","tryCatchPattern":"let pos;\ntry { pos = await backend.cursor_position(); }\ncatch (e) { if (String(e.message).includes(\"touch devices\")) pos = null; else throw e; }","preventionTips":["Gate cursor-position UI on the backend's platform capabilities","Never assume mouse semantics for touch-only backends"],"tags":["touch-device","unsupported-operation","harmonyos"],"backgroundTag":"unsupported-operation","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T21:17:16.096Z"}