Skip to content
karagöz docs
Star4npm0.5.1

Read an Android screen as JSON and tap by text

Read an Android screen's accessibility tree as JSON, find a node by its text or id and tap it, or tap a point from its bounds.

On Android, karagoz ui-tree reads the focused window’s accessibility tree with uiautomator dump and prints it as JSON. Each node carries its bounds, and its text when it has any. karagoz tap --text uses them to find a node in the tree and tap its center.

When stdout is not a terminal, as in a pipe or Claude Code’s shell, every command prints one line of JSON, shown below. At a terminal, devices and doctor print a summary and the other commands indent their JSON.

  • adb from Android platform-tools, and a running emulator or a phone with USB debugging on.
  • Karagöz: Install.
  • The screen on, and no other UiAutomation client connected.
~/app
karagoz ui-tree
{"device":"emulator-5554","rotation":0,"root":{"class":"FrameLayout","package":"com.google.android.apps.nexuslauncher","bounds":[0,0,1080,2400],"children":[…]}}

By default the tree is compact. It leaves out a node with no text, label or action and puts its children in its place. It also leaves out nodes off screen, shortens class and resourceId, and drops a contentDesc equal to text.

ui-tree --detail full returns every node uiautomator reports, unchanged. bounds are the same pixels in both, so tap takes either tree’s centers.

The tree covers what uiautomator covers: the focused window, and nodes visible to the user.

For more information, see ui-tree.

On the launcher, the Chrome icon is this node:

{
"class": "TextView",
"text": "Chrome",
"clickable": true,
"longClickable": true,
"focusable": true,
"bounds": [581, 1905, 754, 2100]
}

In the full tree its class is android.widget.TextView. The fields to find a node by:

  • text: the node’s text. Jetpack Compose puts text here.
  • contentDesc: the node’s content description, uiautomator’s content-desc. Flutter puts text here.
  • resourceId: the node’s resource id, com.example:id/save in the full tree, save in the compact tree.
  • bounds: [left, top, right, bottom] in screen pixels.
~/app
karagoz tap --text Chrome
{"device":"emulator-5554","x":667.5,"y":2002.5,"element":{"class":"android.widget.TextView","text":"Chrome","contentDesc":"Chrome","clickable":true,"longClickable":true,"focusable":true,"bounds":[581,1905,754,2100]}}exit 0
  • --text matches a node whose text or contentDesc equals the label. The match is case-sensitive, covers the whole string and does not trim whitespace.
  • --id matches a node whose resourceId equals the value, or ends with :id/<value>. --id save matches com.example:id/save.
  • The tap goes to the center of the node that matched, not to a clickable parent. element is that node as ui-tree --detail full returns it, without children.
  • --timeout <ms> keeps reading the tree until a node matches or that much time has passed. The tap itself is never repeated.

Exit 0 means Android accepted the event, not that the app reacted to it. Read the tree again to check.

For more information, see tap.

screenshot pixels, ui-tree bounds and the tap coordinates share one space: physical pixels of the current screen orientation, origin top left. A node with bounds [581,1905,754,2100] has its center at (667.5, 2002.5). tap takes decimals too.

~/app
karagoz tap 540 1200
{"device":"emulator-5554","x":540,"y":1200}exit 0

A point tap does not read the tree, so it works while another UiAutomation client is connected.

For more information, see Coordinates.

~/app
karagoz screenshot --out home.png
{"path":"/Users/me/home.png","device":"emulator-5554","pixels":{"width":1080,"height":2400},"logical":{"width":411.42857142857144,"height":914.2857142857143},"scale":2.625,"safeArea":{"top":63,"right":0,"bottom":63,"left":0},"rotation":0}exit 0

screenshot saves the screen as a PNG at full device resolution, without scaling it, and prints where it went. A node’s center from the tree is the same pixel in that PNG.

Over MCP, screenshot with inline: true also returns the image, and the client scales it before the model sees it. An agent takes coordinates from the tree’s bounds, or from pixels and scale, never from the image.

For more information, see screenshot.

  • ELEMENT_NOT_FOUND: no node matches, no node with text or contentDesc 'Save' in com.example (1 read in 2.6 s). With --timeout, a “no match” triggers another read.
  • ELEMENT_AMBIGUOUS: more than one node matches, and the message lists up to five with class and bounds. A parent and a child that both match are two matches: pick one and tap its coordinates.
  • ELEMENT_COVERED: the node’s center is under the on-screen keyboard. Close the keyboard with karagoz key BACK.
  • CAPTURE_FAILED: the screen could not be read, with the reason in the message:
    • the screen kept changing for uiautomator’s 10 s idle wait (an animation or live content);
    • no focused window: the screen is off, an app is still starting, or the app is in a work profile or Secure Folder, which adb cannot read;
    • uiautomator was killed (the message names adb -s <id> logcat -b crash);
    • the output could not be parsed.
  • AUTOMATION_BUSY: another UiAutomation client is connected, and only one can be at a time. A point tap still works.
  • ui-tree: every node field, and the iOS trees.
  • tap: how a node is found, and the waits.
  • screenshot: the PNG and its scale metadata.
  • Output: the one JSON line, and the coordinate space.
  • MCP server: the same commands as tools for an AI agent.