Run JavaScript on iPhone: Scriptable Plus a 3-Line Live-Reload Script
JavaScript developers get a free execution target on iOS without touching Xcode. The three-line loader removes the copy-and-paste loop that kills phone scripting, and the timestamped-URL plus async-eval pattern transfers to any device that can fetch and run a string from a local server.
Scriptable is an iOS app that runs JavaScript on the phone, and scripts can be added to the home screen as widgets. A minimal Alert script with title, message, and an OK button shows how little setup a first script needs; the result behaves like a PWA, web-built but installed from the home screen. Long-press the desktop, add the widget, then long-press it to pick which script runs.
The edit loop is the pain point: code written in VS Code gets pasted through a chat app to reach the phone, and editing on the device is unfriendly. LAN hot reload is the fix. A Python one-liner, `python -m http.server 8080`, serves the code folder from the computer, and a permanent three-line loader on the phone builds a Request to `http://{LAN-IP}:8080/my-script.js?t=${Date.now()}`, loads it as a string, and evaluates it.
The timestamped URL makes each request unique, defeating the iOS HTTP cache so the phone always gets the newest file. Fetched code is then wrapped in an immediately-invoked async arrow function inside eval(), because native eval runs synchronously and can't hold top-level await, while Scriptable expects an async context. A verification ladder runs from terminal output to a desktop browser to a phone-browser fetch of `http://{computer-ip}:8080`, with a `GET / HTTP/1.1 200` in the server log as final proof.
The opening premise is the notable part: handing tasks to AI felt like "making wishes" rather than programming, so the response was to build something by hand. Technical content here is deliberately basic; the act of building is the point.
Worth stealing from the loader: timestamped URLs plus an async IIFE inside eval() solve both iOS caching and the top-level-await limitation in four lines.
Proving the network path matters more than starting the server: terminal output and a desktop check only confirm Python is running, while the phone-browser test with a server-log 200 actually proves the device can reach the machine.
This trick is really handy; the hot-reload part is the key. Change on the computer, and the phone runs it right away — this is what learning iOS should look like.
Yes, and another trick: while the phone is running, when printing logs for debugging, transmit the logs over the LAN to a file on the computer, so the phone runs while the computer shows the logs — even smoother for development. I'll add this content later.
Updated the way to view phone runtime logs on the computer: https://juejin.cn/spost/7712284408648695843