### Install Released CLI Version Source: https://github.com/vulpineos/mobilebridge/blob/main/RELEASING.md Verify that the released CLI version can be installed using `go install`. ```bash go install github.com/VulpineOS/mobilebridge/cmd/mobilebridge@vX.Y.Z ``` -------------------------------- ### Install mobilebridge using Go Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Install the mobilebridge command-line tool using the Go package manager. Ensure Go 1.22+ is installed and your Go environment is configured. ```bash go install github.com/VulpineOS/mobilebridge/cmd/mobilebridge@latest ``` -------------------------------- ### Start Attached Server and Handle Session Lifecycle Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Starts an attached server and proxies connections to the Android devtools socket. Handles session completion or context cancellation. ```go ctx := context.Background() session, err := mobilebridge.StartAttachedServer(ctx, serial, "127.0.0.1:9222") if err != nil { log.Fatal(err) } defer session.Close() select { case <-ctx.Done(): // shut down case <-session.Done(): // upstream permanently lost (reconnect exhausted backoff) — rebuild } ``` -------------------------------- ### Start Attached Server with Specific ADB Port Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Starts an attached server when the host process already owns ADB port assignment. Allows specifying the ADB port to use. ```go session, err := mobilebridge.StartAttachedServerWithADBPort( ctx, "R58N12ABCDE", 4567, "127.0.0.1:9222", ) if err != nil { log.Fatal(err) } deffer session.Close() ``` -------------------------------- ### Start Attached Server for Embedding in Host Processes Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Starts an attached server for integrating mobilebridge into another Go service. Assumes the host process does not manage ADB port assignment. ```go ctx := context.Background() session, err := mobilebridge.StartAttachedServer(ctx, "R58N12ABCDE", "127.0.0.1:9222") if err != nil { log.Fatal(err) } deffer session.Close() resp, err := http.Get("http://127.0.0.1:9222/json/version") if err != nil { log.Fatal(err) } deffer resp.Body.Close() ``` -------------------------------- ### Host-Process Integration Pattern with Puppeteer Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md Demonstrates the recommended host-process integration pattern. It starts an attached server, connects a CDP client (Puppeteer) using the server's endpoint, and ensures resources are closed. ```go ctx := context.Background() session, err := mobilebridge.StartAttachedServer(ctx, "R58N12ABCDE", "127.0.0.1:9222") if err != nil { log.Fatal(err) } deferr session.Close() browser, err := puppeteer.Connect(puppeteer.ConnectOptions{ BrowserURL: session.Endpoint, }) if err != nil { log.Fatal(err) } deferr browser.Close() ``` -------------------------------- ### Check device/socket readiness Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Verify if the specified Android device and its Chrome DevTools socket are accessible without starting the full bridge service. Requires ADB setup. ```bash mobilebridge --health --device R58N12ABCDE ``` -------------------------------- ### Start Attached Server with mobilebridge Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md Starts an attached server for a given Android device serial and local listen address. Returns an *AttachedServer object containing session details. Ensure to close the session when done. ```go session, err := mobilebridge.StartAttachedServer(ctx, serial, "127.0.0.1:9222") if err != nil { return err } deferr session.Close() ``` -------------------------------- ### Start Attached Server for Mobilebridge Integration Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md Use `StartAttachedServer` for most integrations to manage session endpoints and ensure the session is closed when done. This is the recommended approach over using lower-level primitives. ```go StartAttachedServer session.Endpoint close the session ``` -------------------------------- ### Start Attached Server for MobileBridge Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/device-farm.md This Go code snippet demonstrates the primitive provided by `mobilebridge` to start a local attached session for an Android device. It returns a public `Endpoint`, a `Done()` channel for upstream loss, and a `Close()` path for tearing down the server and ADB forward. ```go session, err := mobilebridge.StartAttachedServer(ctx, serial, "127.0.0.1:9222") ``` -------------------------------- ### Screen Recording (Go) Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Start and stop screen recording using `adb shell screenrecord` programmatically via the `StartScreenRecording` and `StopScreenRecording` methods. The bridge manages the recording process and pulls the MP4 file upon shutdown. ```APIDOC ## Screen Recording The bridge can drive `adb shell screenrecord` in the background while automation runs, then pull the MP4 back to your host on shutdown. It uses a 3-minute cap (Android's own hard limit) and a 4 Mbps bitrate by default. Start it either programmatically: ```go _ = proxy.StartScreenRecording(ctx, "/tmp/run.mp4") // ... automation ... _ = proxy.StopScreenRecording(ctx) ``` or via the CLI: `mobilebridge --port 9222 --screenrecord /tmp/run.mp4`. ``` -------------------------------- ### Start and Stop Screen Recording Programmatically Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Control `adb screenrecord` programmatically using `StartScreenRecording` and `StopScreenRecording`. The bridge manages the recording process, capping it at 3 minutes and using a default 4 Mbps bitrate, and pulls the MP4 to the specified path on shutdown. ```go _ = proxy.StartScreenRecording(ctx, "/tmp/run.mp4") // ... automation ... _ = proxy.StopScreenRecording(ctx) ``` -------------------------------- ### Start Mobilebridge Worker with Control API Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md Use this command to start the Mobilebridge worker with an HTTP control API. This is useful when the worker process is separate from the control plane. ```bash mobilebridge --worker-control 127.0.0.1:7788 ``` -------------------------------- ### Run mobilebridge for a specific device and port Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Start the mobilebridge server, specifying the target Android device serial number and the local port to listen on. This allows a CDP client to connect. ```bash mobilebridge --device R58N12ABCDE --port 9222 ``` -------------------------------- ### Real-Device Smoke Test for Mobilebridge Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Perform an end-to-end smoke test on a real Android device. This involves starting the bridge, listing devices, and verifying the connection with curl. ```bash mobilebridge --list mobilebridge --device --port 9222 & curl http://127.0.0.1:9222/json/version | jq .Browser ``` -------------------------------- ### Run Full Verification Set Source: https://github.com/vulpineos/mobilebridge/blob/main/RELEASING.md Execute build, vet, and test commands to ensure code quality and correctness. ```bash go build ./... go vet ./... go test ./... go test ./... -race ``` -------------------------------- ### Emulate Network Conditions with Go Helper Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Use the `EmulateNetworkConditions` Go helper to simplify network throttling. It handles enabling the Network domain and converts user-friendly kilobits per second to Chrome's required bytes per second. ```go p.EmulateNetworkConditions(false, 200, 1600, 750) // ~3G: 200ms latency, 1.6 Mbps down, 750 kbps up p.EmulateNetworkConditions(true, 0, 0, 0) // offline ``` -------------------------------- ### Network Emulation (Go) Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Programmatically emulate network conditions using the `EmulateNetworkConditions` Go helper, which simplifies enabling the Network domain and converting user-friendly speeds to Chrome's required format. ```APIDOC ## Network Emulation mobilebridge exposes `Network.emulateNetworkConditions` as a Go helper that handles the "enable the Network domain first, then apply the throttle" dance and converts user-friendly kilobits-per-second into Chrome's bytes-per-second format: ```go p.EmulateNetworkConditions(false, 200, 1600, 750) // ~3G: 200ms latency, 1.6 Mbps down, 750 kbps up p.EmulateNetworkConditions(true, 0, 0, 0) // offline ``` ``` -------------------------------- ### Create and Push Release Tag Source: https://github.com/vulpineos/mobilebridge/blob/main/RELEASING.md Tag the current commit on the main branch as a release and push it to the origin. ```bash git tag v0.1.0 git push origin v0.1.0 ``` -------------------------------- ### Build mobilebridge from source Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Clone the mobilebridge repository and build the executable from source. This method requires Git and a Go toolchain (1.22+). ```bash git clone https://github.com/VulpineOS/mobilebridge.git cd mobilebridge go build ./cmd/mobilebridge ``` -------------------------------- ### Perform Touch Gestures with Go Helper Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Utilize the Go helper functions in `pkg/mobilebridge` for simplified touch gesture control. These functions, such as `Tap`, `Swipe`, `Pinch`, and `LongPress`, internally construct and send the necessary `Input.dispatchTouchEvent` payloads. ```go ctx := context.Background() session, _ := mobilebridge.StartAttachedServer(ctx, "R58N12ABCDE", "127.0.0.1:9222") defer session.Close() p := session.Proxy p.Tap(ctx, 200, 400) p.Swipe(ctx, 500, 1200, 500, 300, 300) // scroll up p.Pinch(ctx, 540, 960, 0.5) // pinch out p.LongPress(ctx, 200, 400, 800) ``` -------------------------------- ### Create and Push Patch Release Tag Source: https://github.com/vulpineos/mobilebridge/blob/main/RELEASING.md Tag the current commit on the main branch as a patch release and push it to the origin. ```bash git tag v0.1.1 git push origin v0.1.1 ``` -------------------------------- ### List attached Android devices Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Use the `--list` flag to display all Android devices currently connected and recognized by ADB. ```bash mobilebridge --list ``` -------------------------------- ### Touch Gesture Extensions (Go) Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Utilize higher-level Go functions provided by `pkg/mobilebridge` for driving complex touch gestures, which internally generate sequences of `Input.dispatchTouchEvent` payloads. ```APIDOC ## Touch Gesture Extensions (Go) Standard CDP has `Input.dispatchTouchEvent`, but it's fiddly to drive interactive gestures by hand. mobilebridge exposes higher-level helpers as Go functions in `pkg/mobilebridge`: ```go ctx := context.Background() session, _ := mobilebridge.StartAttachedServer(ctx, "R58N12ABCDE", "127.0.0.1:9222") defer session.Close() p := session.Proxy p.Tap(ctx, 200, 400) p.Swipe(ctx, 500, 1200, 500, 300, 300) // scroll up p.Pinch(ctx, 540, 960, 0.5) // pinch out p.LongPress(ctx, 200, 400, 800) ``` Each helper builds the correct sequence of `Input.dispatchTouchEvent` payloads (`touchStart` -> `touchMove`s -> `touchEnd`) and sends them over the proxied CDP connection. ``` -------------------------------- ### List Visible Android Devices Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md Lists all visible Android devices connected to the host. Iterates through the devices to print their serial, state, and model. ```go devices, err := mobilebridge.ListDevices(ctx) if err != nil { return err } for _, d := range devices { fmt.Printf("%s %s %s\n", d.Serial, d.State, d.Model) } ``` -------------------------------- ### Print enriched device information Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Display detailed information about connected Android devices, including serial numbers, models, and other relevant attributes. ```bash mobilebridge --devices ``` -------------------------------- ### Device Enrichment (Go) Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Enrich a `Device` object with detailed information such as Android version, SDK level, total RAM, and battery percentage using the `Enrich` method. This operation performs several lightweight system reads. ```APIDOC ## Device Enrichment Beyond `adb devices -l`, you can enrich a `Device` with Android version, SDK level, total RAM, and current battery percent. Enrich runs four cheap `getprop`/`dumpsys`/`/proc/meminfo` reads and is best-effort per field: ```go d := devices[0] _ = d.Enrich(ctx) fmt.Printf("android %s sdk %d ram %dMB battery %d%%\n", d.AndroidVersion, d.SDKLevel, d.RAM_MB, d.BatteryPercent) ``` Or from the CLI: `mobilebridge --devices`. ``` -------------------------------- ### Run Go Tests with Race Detector Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Execute unit tests for mobilebridge with the race detector enabled to catch regressions in reconnect goroutines. Ensure you have a phone connected for some tests. ```bash go test ./... -race ``` -------------------------------- ### VulpineOS MobileBridge Integration Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md Illustrates how VulpineOS integrates with mobilebridge using its public interface. It maps mobilebridge devices to a generic shape and manages session lifecycles. ```go devices, _ := extensions.Registry.Mobile().ListDevices(ctx) session, _ := extensions.Registry.Mobile().Connect(ctx, devices[0].UDID) deferr extensions.Registry.Mobile().Disconnect(ctx, session.ID) fmt.Println(session.CDPEndpoint) ``` -------------------------------- ### Enrich Device Information with Go Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Enrich a `Device` object with additional details like Android version, SDK level, RAM, and battery percentage using the `Enrich` method. This method performs several lightweight `adb` and system property reads. ```go d := devices[0] _ = d.Enrich(ctx) fmt.Printf("android %s sdk %d ram %dMB battery %d%%\n", d.AndroidVersion, d.SDKLevel, d.RAM_MB, d.BatteryPercent) ``` -------------------------------- ### Enrich Device Metadata Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md Fetches richer metadata for a given device. This is an optional step after listing devices if more detailed information is required. ```go if len(devices) > 0 { _ = devices[0].Enrich(ctx) } ``` -------------------------------- ### Check Git Status Source: https://github.com/vulpineos/mobilebridge/blob/main/RELEASING.md Verify that the main branch is clean before proceeding with the release. ```bash git status --short --branch ``` -------------------------------- ### Run worker-control server with self-registration Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Configure and run the mobilebridge worker-control server with advanced options for self-registration, including worker ID, authentication tokens, advertised URL, and heartbeat endpoints. ```bash mobilebridge \ --worker-control 127.0.0.1:7788 \ --worker-id worker-auckland-1 \ --worker-control-token $MOBILE_WORKER_CONTROL_TOKEN \ --worker-advertise-url http://10.0.0.10:7788 \ --worker-heartbeat-url https://api.example.com/v1/mobile/workers/heartbeat \ --worker-token $MOBILE_WORKER_TOKEN ``` -------------------------------- ### Connect Puppeteer to mobilebridge Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Connect a Puppeteer instance to the running mobilebridge server. The `browserURL` should point to the local address and port where mobilebridge is serving. ```javascript const browser = await puppeteer.connect({ browserURL: 'http://localhost:9222' }); ``` -------------------------------- ### Run mobilebridge for the only attached device Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md If only one Android device is connected, you can omit the `--device` flag to have mobilebridge automatically target it. ```bash mobilebridge --port 9222 ``` -------------------------------- ### Send Touch Gestures via CDP Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Use the `MobileBridge.tap`, `MobileBridge.swipe`, `MobileBridge.pinch`, and `MobileBridge.longPress` methods over a CDP client to perform touch gestures on the device. These methods abstract the underlying `Input.dispatchTouchEvent` calls. ```javascript const client = await page.target().createCDPSession(); await client.send('MobileBridge.tap', { x: 200, y: 400 }); await client.send('MobileBridge.swipe', { fromX: 500, fromY: 1200, toX: 500, toY: 300, durationMs: 300 }); await client.send('MobileBridge.pinch', { centerX: 540, centerY: 960, scale: 0.5 }); await client.send('MobileBridge.longPress', { x: 200, y: 400, durationMs: 800 }); ``` -------------------------------- ### Handle Mobilebridge Integration Errors Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md When embedding Mobilebridge, explicitly check for these common errors. Ensure proper session management by closing the attached server when done. ```go ErrADBMissing ErrDeviceNotFound ErrNoDevtoolsSocket ErrBusy ``` -------------------------------- ### Configure Mobilebridge Worker for Self-Registration Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md When these flags are provided, the worker can self-register with the control plane. The heartbeat includes device inventory and worker load. ```bash --worker-heartbeat-url --worker-id --worker-token --worker-control-token --worker-advertise-url ``` -------------------------------- ### Touch Gestures (JavaScript) Source: https://github.com/vulpineos/mobilebridge/blob/main/README.md Interact with mobile devices using synthetic touch gestures exposed by the MobileBridge API over WebSocket. These methods can be called directly by any CDP client. ```APIDOC ## Touch Gestures (JavaScript) On top of raw CDP, mobilebridge exposes synthetic `MobileBridge.*` methods over the same WebSocket. Any CDP client can call them directly: ```js // Puppeteer / chrome-remote-interface const client = await page.target().createCDPSession(); await client.send('MobileBridge.tap', { x: 200, y: 400 }); await client.send('MobileBridge.swipe', { fromX: 500, fromY: 1200, toX: 500, toY: 300, durationMs: 300 }); await client.send('MobileBridge.pinch', { centerX: 540, centerY: 960, scale: 0.5 }); await client.send('MobileBridge.longPress', { x: 200, y: 400, durationMs: 800 }); ``` Internally each call expands into a sequence of `Input.dispatchTouchEvent` frames: `touchStart` -> interpolated `touchMove`s -> `touchEnd`. ``` -------------------------------- ### MobileBridge Control API Endpoints Source: https://github.com/vulpineos/mobilebridge/blob/main/docs/integration.md The MobileBridge service can expose a narrow HTTP control API when the worker process is separate from the control plane. This API allows for managing sessions, recordings, and checking the system's health. ```APIDOC ## POST /sessions ### Description Creates a new session. ### Method POST ### Endpoint /sessions ### Parameters #### Request Body - **device_id** (string) - Required - The ID of the device for which to create a session. ### Request Example { "device_id": "..." } ## DELETE /sessions/{id} ### Description Deletes an existing session. ### Method DELETE ### Endpoint /sessions/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the session to delete. ## POST /sessions/{id}/targets ### Description Adds a target to an existing session. ### Method POST ### Endpoint /sessions/{id}/targets ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the session to which the target will be added. ## POST /sessions/{id}/recording/start ### Description Starts recording for a specific session. ### Method POST ### Endpoint /sessions/{id}/recording/start ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the session for which to start recording. ## POST /sessions/{id}/recording/stop ### Description Stops recording for a specific session. ### Method POST ### Endpoint /sessions/{id}/recording/stop ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the session for which to stop recording. ## GET /recordings/{id}/content ### Description Retrieves the content of a specific recording. ### Method GET ### Endpoint /recordings/{id}/content ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the recording whose content to retrieve. ## DELETE /recordings/{id} ### Description Deletes a specific recording. ### Method DELETE ### Endpoint /recordings/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the recording to delete. ## GET /health ### Description Checks the health status of the MobileBridge service. ### Method GET ### Endpoint /health ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.