$ cat tips/chrome-android-remote-debugging-wifi.md

Give an AI agent a real phone: Chrome DevTools over Wi-Fi adb

Turn on wireless debugging on the phone, pair it with your computer and forward Chrome's DevTools port. The agent gets localhost:9222 and, through the Chrome DevTools Protocol, runs JavaScript on the page, taps the screen and scrolls.

The phone and the computer have to be on the same Wi-Fi network. In developer options turn on wireless debugging and choose pairing with a code: the phone shows an address, a port and a code.

adb pair <ip>:<pairing-port>
adb connect <ip>:<port>
adb forward tcp:9222 localabstract:chrome_devtools_remote
curl localhost:9222/json

You pair once. The port for adb connect is not the pairing port and it changes between sessions; adb mdns services shows the current one in the _adb-tls-connect._tcp row.

curl returns the list of tabs open in Chrome on the phone. Each has its own webSocketDebuggerUrl, and DevTools commands go over that websocket: Runtime.evaluate runs JavaScript on the page, Input.dispatchTouchEvent taps, Input.synthesizeScrollGesture scrolls. For me a 40-line Python client was enough.

The agent sees every open tab, not only your page. Close the rest or tell it plainly which tab it may touch.

I got here through a bug that showed only under the on-screen keyboard. Desktop Chrome does not emulate it, I had no emulator, and every USB cable at hand was charge-only.

If adb pair answers “unknown command”, the apt adb is too old. When the agent has to see the screen with the keyboard on it, it needs a screenshot from adb, not from DevTools.

checked: Pixel 9 Pro, Chrome on Android, Ubuntu 22.04, platform-tools 37.0.1

$ ls ./blog/tips
all tips →
↑