Loading...
Loading...
Host Apple iOS Simulators in the browser with MJPEG streaming, touch/gesture control, and AI agent integration via npx serve-sim.
npx skill4agent add aradotso/trending-skills serve-sim-apple-simulatorSkill by ara.so — Daily 2026 Skills collection.
serve-simnpx servesimctl ioxcrun simctlnpx# Start preview server (auto-detects booted simulator)
npx serve-sim
# → Preview at http://localhost:3200serve-sim [device...] # Start preview server (default: localhost:3200)
serve-sim --no-preview [device...] # Stream only, no web UI
serve-sim gesture '<json>' [-d udid] # Send a touch gesture
serve-sim button [name] [-d udid] # Send a button press (default: home)
serve-sim rotate <orientation> [-d udid]
serve-sim ca-debug <option> <on|off> [-d udid]
serve-sim memory-warning [-d udid] # Simulate a memory warning
# Options
-p, --port <port> Starting port (preview default: 3200, stream default: 3100)
-d, --detach Spawn helper and exit (daemon mode)
-q, --quiet JSON-only output
--no-preview Skip the web UI; stream in foreground only
--list [device] List running streams
--kill [device] Kill running stream(s)# Target a specific device by name
serve-sim "iPhone 16 Pro"
# Start on a custom port
serve-sim -p 4000
# Start as background daemon, returns JSON with stream info
serve-sim --detach
# List all running streams
serve-sim --list
# Kill all running helpers
serve-sim --kill
# Send home button press
serve-sim button home -d <udid>
# Rotate simulator
serve-sim rotate landscape_left -d <udid>
# orientations: portrait | portrait_upside_down | landscape_left | landscape_right
# Toggle CoreAnimation debug flags
serve-sim ca-debug slow-animations on -d <udid>
# options: blended | copies | misaligned | offscreen | slow-animations
# Simulate memory warning
serve-sim memory-warning -d <udid>
# Multiple simulators at once
serve-sim "iPhone 16 Pro" "iPad Pro"
# Send a touch gesture (JSON format)
serve-sim gesture '{"type":"tap","x":200,"y":400}' -d <udid>┌──────────────┐ simctl io ┌─────────────────┐ MJPEG / WS ┌─────────┐
│ iOS Simulator│ ────────────► │ serve-sim-bin │ ───────────► │ Browser │
└──────────────┘ (Swift) │ (per-device) │ └─────────┘
└─────────────────┘
▲
state file in
$TMPDIR/serve-sim/
▲
┌──────────────────┐
│ serve-sim CLI / │
│ middleware │
└──────────────────┘$TMPDIR/serve-sim/.claude/launch.json{
"version": "0.0.1",
"configurations": [
{
"name": "ios",
"runtimeExecutable": "npx",
"runtimeArgs": ["serve-sim"],
"port": 3200
}
]
}metro.config.jshttp://localhost:8081/.sim// metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const connect = require("connect");
const { simMiddleware } = require("serve-sim/middleware");
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
config.server = config.server || {};
const originalEnhanceMiddleware = config.server.enhanceMiddleware;
config.server.enhanceMiddleware = (metroMiddleware, server) => {
const middleware = originalEnhanceMiddleware
? originalEnhanceMiddleware(metroMiddleware, server)
: metroMiddleware;
const app = connect();
app.use(simMiddleware({ basePath: "/.sim" }));
app.use(middleware);
return app;
};
module.exports = config;npx expo starthttp://localhost:8081/.simimport express from "express";
import { simMiddleware } from "serve-sim/middleware";
const app = express();
// First start the helper in daemon mode
// $ npx serve-sim --detach
app.use(simMiddleware({ basePath: "/.sim" }));
app.listen(3000, () => {
console.log("Dev server at http://localhost:3000");
console.log("Simulator preview at http://localhost:3000/.sim");
});// vite.config.ts
import { defineConfig } from "vite";
import { simMiddleware } from "serve-sim/middleware";
export default defineConfig({
server: {
middlewareMode: false,
},
plugins: [
{
name: "serve-sim",
configureServer(server) {
// Start helper first: npx serve-sim --detach
server.middlewares.use("/.sim", simMiddleware({ basePath: "/.sim" }));
},
},
],
});// server.ts
import { createServer } from "http";
import { parse } from "url";
import next from "next";
import { simMiddleware } from "serve-sim/middleware";
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const simHandler = simMiddleware({ basePath: "/.sim" });
app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url!, true);
if (parsedUrl.pathname?.startsWith("/.sim")) {
return simHandler(req, res, () => handle(req, res, parsedUrl));
}
handle(req, res, parsedUrl);
}).listen(3000);
});import { simMiddleware } from "serve-sim/middleware";
// Mount options
simMiddleware({
basePath: "/.sim", // URL prefix for all serve-sim routes
});
// Middleware exposes:
// GET /.sim → Preview HTML UI
// GET /.sim/api → State JSON (connected devices, stream URLs)
// GET /.sim/logs → SSE log stream from simulator$TMPDIR/serve-sim/--detach# Start daemon and capture JSON output
STREAM_INFO=$(npx serve-sim --detach --quiet)
echo $STREAM_INFO
# {"udid":"...","mjpeg":"http://localhost:3100/stream","ws":"ws://localhost:3100/control"}
# List running streams as JSON
npx serve-sim --list --quiet
# Kill specific device stream
npx serve-sim --kill "iPhone 16 Pro"
# Kill all streams
npx serve-sim --killimport { simMiddleware } from "serve-sim/middleware";
import connect from "connect";
const app = connect();
// Attach middleware — requires serve-sim helper already running (--detach)
app.use(
simMiddleware({
basePath: "/.sim",
})
);
export default app;serve-sim gesture '<json>'# Tap at coordinates
serve-sim gesture '{"type":"tap","x":200,"y":400}' -d <udid>
# Swipe gesture
serve-sim gesture '{"type":"swipe","startX":200,"startY":800,"endX":200,"endY":200,"duration":0.3}' -d <udid>git clone https://github.com/EvanBacon/serve-sim
cd serve-sim
bun install
# Build JS bundles
bun run --filter serve-sim build
# Rebuild Swift helper binary
bun run --filter serve-sim build:swift
# Watch mode for development
bun run --filter serve-sim dev# Check booted simulators
xcrun simctl list devices booted
# Boot a simulator if none running
xcrun simctl boot "iPhone 16 Pro"# Use a different port
serve-sim -p 4200
# Kill existing helpers first
serve-sim --kill# Ensure helper is running first
serve-sim --detach
# Verify state files exist
ls $TMPDIR/serve-sim/
# Check running streams
serve-sim --list# Ensure Xcode CLT are installed
xcode-select --install
# Verify simctl works
xcrun simctl list# List all booted simulators with UDIDs
xcrun simctl list devices booted
# Target by UDID explicitly
serve-sim -d <udid>bun run --filter serve-sim build:swift