portholejs 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +186 -0
  2. package/README.md +285 -0
  3. package/client-dist/assets/index-DluwPdUK.js +49 -0
  4. package/client-dist/index.html +1 -1
  5. package/dist/cli.js +351 -83
  6. package/dist/cli.js.map +1 -1
  7. package/dist/control-client.d.ts +1 -0
  8. package/dist/control-client.d.ts.map +1 -1
  9. package/dist/control-client.js +10 -2
  10. package/dist/control-client.js.map +1 -1
  11. package/dist/engine/scrcpy-engine.d.ts +2 -2
  12. package/dist/engine/scrcpy-engine.d.ts.map +1 -1
  13. package/dist/engine/scrcpy-engine.js.map +1 -1
  14. package/dist/engine/types.d.ts +3 -8
  15. package/dist/engine/types.d.ts.map +1 -1
  16. package/dist/focus-navigation.d.ts +27 -0
  17. package/dist/focus-navigation.d.ts.map +1 -0
  18. package/dist/focus-navigation.js +118 -0
  19. package/dist/focus-navigation.js.map +1 -0
  20. package/dist/gesture.d.ts +14 -0
  21. package/dist/gesture.d.ts.map +1 -0
  22. package/dist/gesture.js +110 -0
  23. package/dist/gesture.js.map +1 -0
  24. package/dist/index.d.ts +3 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/input-validation.d.ts.map +1 -1
  29. package/dist/input-validation.js +4 -56
  30. package/dist/input-validation.js.map +1 -1
  31. package/dist/input.d.ts +1 -21
  32. package/dist/input.d.ts.map +1 -1
  33. package/dist/keycodes.d.ts +2 -1
  34. package/dist/keycodes.d.ts.map +1 -1
  35. package/dist/keycodes.js.map +1 -1
  36. package/dist/mcp/server.d.ts.map +1 -1
  37. package/dist/mcp/server.js +183 -1
  38. package/dist/mcp/server.js.map +1 -1
  39. package/dist/mp4-writer.d.ts +18 -0
  40. package/dist/mp4-writer.d.ts.map +1 -0
  41. package/dist/mp4-writer.js +195 -0
  42. package/dist/mp4-writer.js.map +1 -0
  43. package/dist/protocol.d.ts +74 -2
  44. package/dist/protocol.d.ts.map +1 -1
  45. package/dist/protocol.js +154 -7
  46. package/dist/protocol.js.map +1 -1
  47. package/dist/recording.d.ts +22 -0
  48. package/dist/recording.d.ts.map +1 -0
  49. package/dist/recording.js +132 -0
  50. package/dist/recording.js.map +1 -0
  51. package/dist/screen-diff.d.ts +21 -0
  52. package/dist/screen-diff.d.ts.map +1 -0
  53. package/dist/screen-diff.js +70 -0
  54. package/dist/screen-diff.js.map +1 -0
  55. package/dist/server/http.d.ts +5 -4
  56. package/dist/server/http.d.ts.map +1 -1
  57. package/dist/server/http.js +69 -31
  58. package/dist/server/http.js.map +1 -1
  59. package/dist/server/ws.d.ts +4 -3
  60. package/dist/server/ws.d.ts.map +1 -1
  61. package/dist/server/ws.js +32 -18
  62. package/dist/server/ws.js.map +1 -1
  63. package/dist/session.d.ts +25 -10
  64. package/dist/session.d.ts.map +1 -1
  65. package/dist/session.js +117 -67
  66. package/dist/session.js.map +1 -1
  67. package/dist/state.d.ts.map +1 -1
  68. package/dist/state.js +1 -3
  69. package/dist/state.js.map +1 -1
  70. package/package.json +18 -3
  71. package/skills/porthole/SKILL.md +130 -0
  72. package/client-dist/assets/index-C_qSS_Gy.js +0 -49
package/LICENSE ADDED
@@ -0,0 +1,186 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation or
31
+ translation of a Source form, including but not limited to compiled object
32
+ code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work (an example is provided in the Appendix
37
+ below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as a
42
+ whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
52
+ of this definition, "submitted" means any form of electronic, verbal, or
53
+ written communication sent to the Licensor or its representatives, including
54
+ but not limited to communication on electronic mailing lists, source code
55
+ control systems, and issue tracking systems that are managed by, or on behalf
56
+ of, the Licensor for the purpose of discussing and improving the Work, but
57
+ excluding communication that is conspicuously marked or otherwise designated
58
+ in writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
61
+ behalf of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
65
+ License, each Contributor hereby grants to You a perpetual, worldwide,
66
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
67
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
68
+ sublicense, and distribute the Work and such Derivative Works in Source or
69
+ Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of this
72
+ License, each Contributor hereby grants to You a perpetual, worldwide,
73
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
74
+ section) patent license to make, have made, use, offer to sell, sell, import,
75
+ and otherwise transfer the Work, where such license applies only to those
76
+ patent claims licensable by such Contributor that are necessarily infringed
77
+ by their Contribution(s) alone or by combination of their Contribution(s) with
78
+ the Work to which such Contribution(s) was submitted. If You institute patent
79
+ litigation against any entity (including a cross-claim or counterclaim in a
80
+ lawsuit) alleging that the Work or a Contribution incorporated within the Work
81
+ constitutes direct or contributory patent infringement, then any patent
82
+ licenses granted to You under this License for that Work shall terminate as of
83
+ the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
86
+ Derivative Works thereof in any medium, with or without modifications, and in
87
+ Source or Object form, provided that You meet the following conditions:
88
+
89
+ (a) You must give any other recipients of the Work or Derivative Works a copy
90
+ of this License; and
91
+
92
+ (b) You must cause any modified files to carry prominent notices stating that
93
+ You changed the files; and
94
+
95
+ (c) You must retain, in the Source form of any Derivative Works that You
96
+ distribute, all copyright, patent, trademark, and attribution notices from the
97
+ Source form of the Work, excluding those notices that do not pertain to any
98
+ part of the Derivative Works; and
99
+
100
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
101
+ then any Derivative Works that You distribute must include a readable copy of
102
+ the attribution notices contained within such NOTICE file, excluding those
103
+ notices that do not pertain to any part of the Derivative Works, in at least
104
+ one of the following places: within a NOTICE text file distributed as part of
105
+ the Derivative Works; within the Source form or documentation, if provided
106
+ along with the Derivative Works; or, within a display generated by the
107
+ Derivative Works, if and wherever such third-party notices normally appear.
108
+ The contents of the NOTICE file are for informational purposes only and do not
109
+ modify the License. You may add Your own attribution notices within
110
+ Derivative Works that You distribute, alongside or as an addendum to the
111
+ NOTICE text from the Work, provided that such additional attribution notices
112
+ cannot be construed as modifying the License.
113
+
114
+ You may add Your own copyright statement to Your modifications and may
115
+ provide additional or different license terms and conditions for use,
116
+ reproduction, or distribution of Your modifications, or for any such
117
+ Derivative Works as a whole, provided Your use, reproduction, and distribution
118
+ of the Work otherwise complies with the conditions stated in this License.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
121
+ Contribution intentionally submitted for inclusion in the Work by You to the
122
+ Licensor shall be under the terms and conditions of this License, without any
123
+ additional terms or conditions. Notwithstanding the above, nothing herein
124
+ shall supersede or modify the terms of any separate license agreement you may
125
+ have executed with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade names,
128
+ trademarks, service marks, or product names of the Licensor, except as
129
+ required for reasonable and customary use in describing the origin of the Work
130
+ and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
133
+ writing, Licensor provides the Work (and each Contributor provides its
134
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
135
+ KIND, either express or implied, including, without limitation, any warranties
136
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
137
+ PARTICULAR PURPOSE. You are solely responsible for determining the
138
+ appropriateness of using or redistributing the Work and assume any risks
139
+ associated with Your exercise of permissions under this License.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
142
+ tort (including negligence), contract, or otherwise, unless required by
143
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
144
+ writing, shall any Contributor be liable to You for damages, including any
145
+ direct, indirect, special, incidental, or consequential damages of any
146
+ character arising as a result of this License or out of the use or inability
147
+ to use the Work (including but not limited to damages for loss of goodwill,
148
+ work stoppage, computer failure or malfunction, or any and all other
149
+ commercial damages or losses), even if such Contributor has been advised of
150
+ the possibility of such damages.
151
+
152
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
153
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
154
+ acceptance of support, warranty, indemnity, or other liability obligations
155
+ and/or rights consistent with this License. However, in accepting such
156
+ obligations, You may act only on Your own behalf and on Your sole
157
+ responsibility, not on behalf of any other Contributor, and only if You agree
158
+ to indemnify, defend, and hold each Contributor harmless for any liability
159
+ incurred by, or claims asserted against, such Contributor by reason of your
160
+ accepting any such warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ APPENDIX: How to apply the Apache License to your work.
165
+
166
+ To apply the Apache License to your work, attach the following boilerplate
167
+ notice, with the fields enclosed by brackets "[]" replaced with your own
168
+ identifying information. (Don't include the brackets!) The text should be
169
+ enclosed in the appropriate comment syntax for the file format. We also
170
+ recommend that a file or class name and description of purpose be included on
171
+ the same "printed page" as the copyright notice for easier identification
172
+ within third-party archives.
173
+
174
+ Copyright [yyyy] [name of copyright owner]
175
+
176
+ Licensed under the Apache License, Version 2.0 (the "License");
177
+ you may not use this file except in compliance with the License.
178
+ You may obtain a copy of the License at
179
+
180
+ http://www.apache.org/licenses/LICENSE-2.0
181
+
182
+ Unless required by applicable law or agreed to in writing, software
183
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
184
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185
+ See the License for the specific language governing permissions and
186
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,285 @@
1
+ # Porthole
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/giolaq/porthole/main/assets/porthole-logo.png" alt="Porthole logo" width="220">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/portholejs"><img src="https://img.shields.io/npm/v/portholejs" alt="npm version"></a>
9
+ <a href="https://github.com/giolaq/porthole/actions/workflows/ci.yml"><img src="https://github.com/giolaq/porthole/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
10
+ <a href="https://github.com/giolaq/porthole/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/portholejs" alt="license"></a>
11
+ <a href="https://www.npmjs.com/package/portholejs"><img src="https://img.shields.io/node/v/portholejs" alt="node"></a>
12
+ </p>
13
+
14
+ A window into your Android emulator — `npx portholejs`.
15
+
16
+ Porthole boots or attaches to Android phone and TV AVDs, streams them to a browser,
17
+ and forwards touch, keyboard, D-pad remote, screenshots, logcat, and file drops
18
+ through one local tool. It is the Android sibling of
19
+ [serve-sim](https://github.com/EvanBacon/serve-sim).
20
+
21
+ ## Quick Start
22
+
23
+ Prerequisites:
24
+
25
+ - Node.js 20 or newer
26
+ - Android Studio or Android SDK command line tools
27
+ - `emulator` and `adb` installed under the SDK
28
+ - Chrome, Edge, or another browser with WebCodecs for H.264 playback
29
+
30
+ Porthole finds the SDK from `ANDROID_HOME`, then `ANDROID_SDK_ROOT`, then the
31
+ platform defaults:
32
+
33
+ - macOS: `~/Library/Android/sdk`
34
+ - Linux: `~/Android/Sdk`
35
+ - Windows: `%LOCALAPPDATA%\Android\Sdk`
36
+
37
+ ```sh
38
+ npx portholejs
39
+ ```
40
+
41
+ With no running emulator, Porthole prompts for an AVD. To boot a specific AVD:
42
+
43
+ ### The scrcpy-server component
44
+
45
+ Porthole mirrors and controls the emulator by speaking the
46
+ [scrcpy](https://github.com/Genymobile/scrcpy) protocol. At runtime it pushes a
47
+ small server jar (`scrcpy-server`, Apache-2.0, by Genymobile) to the emulator
48
+ over adb and connects to its video and control sockets — no scrcpy CLI or
49
+ native binary is involved.
50
+
51
+ The jar is **not** bundled in this repository or in the npm package. It is
52
+ downloaded automatically during `npm install` (a `postinstall` step) from the
53
+ official Genymobile/scrcpy GitHub release, pinned to **v3.1** and verified
54
+ against a SHA-256 checksum. If the download was skipped (for example, an
55
+ offline install), fetch it later with:
56
+
57
+ ```sh
58
+ node node_modules/portholejs/scripts/download-scrcpy-server.mjs
59
+ ```
60
+
61
+ `porthole doctor` reports whether the jar is present. To bump the pinned
62
+ version, update `SCRCPY_VERSION` and `SCRCPY_SHA256` in
63
+ `scripts/download-scrcpy-server.mjs` and keep the engine's scrcpy options class
64
+ in sync (see `src/engine/scrcpy-engine.ts`).
65
+
66
+ ```sh
67
+ npx portholejs start Pixel_8_Pro_API_34
68
+ npx portholejs start Pixel_8_Pro_API_34 Television_1080p_API_34
69
+ ```
70
+
71
+ For a headless agent workflow:
72
+
73
+ ```sh
74
+ npx portholejs start Android_TV_1080p --detach -q
75
+ npx portholejs remote dpad_down
76
+ npx portholejs screenshot -q
77
+ npx portholejs kill -q
78
+ ```
79
+
80
+ ## Things to try
81
+
82
+ Test a TV app **without touching a remote**: `porthole focus-on "Library"
83
+ --select` walks the D-pad focus to any element by its text and presses OK —
84
+ then `porthole focused -q` tells you exactly where leanback focus landed, as
85
+ JSON. Record a bug repro as a real video with
86
+ `porthole record repro.mp4 --duration 30s` while you swipe, scroll, and
87
+ long-press the phone from the CLI (`porthole scroll down`,
88
+ `porthole swipe 0.5 0.05 0.5 0.7` opens the notification shade). Catch visual
89
+ regressions in one line: save a baseline with `porthole screenshot -o good.png`,
90
+ then `porthole assert-screen good.png --threshold 0.02` exits non-zero and
91
+ writes a diff image the moment the screen drifts. Stream a **phone and a TV
92
+ side by side** from one command — `porthole start Pixel_8 Tv_1080p` puts both
93
+ in the same browser tab with a device picker. And the whole loop works with no
94
+ human at all: add the MCP server to Claude Code (below) and ask it to _"open
95
+ my app on the TV emulator, navigate to Settings, and check nothing crashed"_ —
96
+ it will drive the D-pad, read the UI as JSON (`dump_ui`), and pull
97
+ `get_crashes` on its own. If anything misbehaves, `porthole doctor` diagnoses
98
+ your setup in seconds.
99
+
100
+ ## CLI Reference
101
+
102
+ | Command | Purpose |
103
+ | ------------------------------------ | --------------------------------------------------- |
104
+ | `porthole start [avd...]` | Boot or attach one or more emulators and serve them |
105
+ | `porthole list` | List AVDs, running emulators, and known sessions |
106
+ | `porthole kill [avd]` | Stop emulators Porthole booted and detached servers |
107
+ | `porthole tap <x> <y>` | Touch normalized phone coordinates from `0..1` |
108
+ | `porthole swipe <x1> <y1> <x2> <y2>` | Swipe between normalized phone coordinates |
109
+ | `porthole longpress <x> <y>` | Long-press normalized phone coordinates |
110
+ | `porthole scroll <direction>` | Scroll phone content up, down, left, or right |
111
+ | `porthole key <keycode>` | Send an Android keycode down/up pair |
112
+ | `porthole remote <button>` | Press a TV D-pad/media button |
113
+ | `porthole text "<string>"` | Type text into the active session |
114
+ | `porthole screenshot [-o file.png]` | Save a PNG screenshot |
115
+ | `porthole assert-screen <png>` | Compare the current screen with a PNG baseline |
116
+ | `porthole record <out.mp4>` | Record the current H.264 stream to MP4 |
117
+ | `porthole focused` | Print the currently focused UI node |
118
+ | `porthole focus-on <text>` | Move TV D-pad focus to matching text |
119
+ | `porthole dump-ui [--filter text]` | Dump the Android UI hierarchy |
120
+ | `porthole wait-for <text>` | Wait until UI text appears |
121
+ | `porthole open-url <url>` | Open a URL or Android deep link |
122
+ | `porthole stop-app <package>` | Force-stop an app |
123
+ | `porthole clear-app <package>` | Clear app data |
124
+ | `porthole rotate <orientation>` | Rotate a phone emulator |
125
+ | `porthole emu <args...>` | Pass through to `adb emu` |
126
+ | `porthole doctor` | Diagnose Node/SDK/adb/AVD/session problems |
127
+ | `porthole mcp` | Run the MCP server over stdio |
128
+
129
+ Common options:
130
+
131
+ | Option | Meaning |
132
+ | ----------------------- | ------------------------------------------------------- |
133
+ | `-p, --port <port>` | Preview/control port, default `3200` |
134
+ | `-d, --device <serial>` | Target a running emulator serial; comma-list on `start` |
135
+ | `--host <host>` | Bind address, default `127.0.0.1` |
136
+ | `--no-preview` | Do not open the browser automatically |
137
+ | `--detach` | Start the preview server in the background |
138
+ | `--mjpeg` | Force MJPEG screenshot polling |
139
+ | `-q, --quiet` | Emit one JSON object/array on stdout |
140
+ | `--max-size <px>` | Maximum scrcpy stream dimension |
141
+ | `--max-fps <fps>` | Maximum scrcpy FPS |
142
+ | `--bitrate <bps>` | Scrcpy video bitrate |
143
+ | `--wipe-data` | Wipe emulator data before boot |
144
+ | `--no-snapshot` | Disable loading/saving emulator snapshots |
145
+ | `--cold-boot` | Alias for `--no-snapshot` |
146
+ | `--gpu <mode>` | Pass emulator GPU mode |
147
+ | `--keep-alive` | Leave a Porthole-booted emulator running on exit |
148
+
149
+ Quiet schemas are intentionally simple: `list -q` returns
150
+ `{ "devices": [...], "sessions": [...] }`; single-device `start --detach -q`
151
+ returns the session record with `url`, `pid`, `serial`, `avdName`, `port`, and
152
+ `profile`; multi-device detached starts return `{ "sessions": [...] }`; input
153
+ commands return `{ "ok": true, "session": ... }`; `screenshot -q` returns
154
+ `{ "ok": true, "path": "...", "session": ... }`. Pass `-d <serial>` to
155
+ port-scoped commands when a server is streaming more than one emulator.
156
+
157
+ ## MCP Setup
158
+
159
+ `.mcp.json`:
160
+
161
+ ```json
162
+ {
163
+ "mcpServers": {
164
+ "porthole": {
165
+ "command": "npx",
166
+ "args": ["portholejs", "mcp"]
167
+ }
168
+ }
169
+ }
170
+ ```
171
+
172
+ Claude Code:
173
+
174
+ ```sh
175
+ claude mcp add porthole -- npx portholejs mcp
176
+ ```
177
+
178
+ Useful MCP tools: `list_devices`, `boot_device`, `wait_for_boot`,
179
+ `attach_device`, `tap`, `swipe`, `long_press`, `scroll`, `key`, `remote`,
180
+ `type_text`, `screenshot`, `assert_screen`, `start_recording`, `stop_recording`,
181
+ `dump_ui`, `get_focused`, `focus_on`, `find_element`, `wait_for`, `open_url`,
182
+ `stop_app`, `clear_app`, `get_crashes`, `read_logcat`, and `install_apk`.
183
+
184
+ ## Agent Skill
185
+
186
+ Porthole ships an agent skill (`skills/porthole/`) that teaches agents the full workflow: doctor triage,
187
+ boot/attach, semantic UI assertions, TV navigation, and cleanup.
188
+
189
+ Install it by copying the skill directory into your skills folder — for the
190
+ current project:
191
+
192
+ ```sh
193
+ mkdir -p .claude/skills
194
+ cp -r node_modules/portholejs/skills/porthole .claude/skills/
195
+ ```
196
+
197
+ or for all your projects:
198
+
199
+ ```sh
200
+ mkdir -p ~/.claude/skills
201
+ cp -r node_modules/portholejs/skills/porthole ~/.claude/skills/
202
+ ```
203
+
204
+ From a clone of this repository, copy `skills/porthole` instead. Claude Code
205
+ picks the skill up automatically; ask it to "test my app on the Android
206
+ emulator" and it will follow the Porthole workflow.
207
+
208
+ ## GitHub Action
209
+
210
+ Porthole ships an in-repo GitHub Action for CI smoke tests. It wraps
211
+ `reactivecircus/android-emulator-runner`, starts `npx --yes portholejs` against
212
+ the booted emulator, and runs your script while the emulator is alive.
213
+
214
+ ```yaml
215
+ jobs:
216
+ tv-smoke:
217
+ runs-on: ubuntu-latest
218
+ steps:
219
+ - uses: actions/checkout@v4
220
+ - id: porthole
221
+ uses: giolaq/porthole@main
222
+ with:
223
+ avd-name: porthole-tv
224
+ api-level: "35"
225
+ profile: tv
226
+ script: |
227
+ mkdir -p artifacts
228
+ "$PORTHOLE_CLI" focus-on "Library" --select -q -p "$PORTHOLE_PORT"
229
+ "$PORTHOLE_CLI" screenshot -o artifacts/library.png -q -p "$PORTHOLE_PORT"
230
+ ```
231
+
232
+ The action exposes `url`, `serial`, and `port` outputs, and also sets
233
+ `PORTHOLE_URL`, `PORTHOLE_SERIAL`, `PORTHOLE_PORT`, and `PORTHOLE_CLI` for the
234
+ smoke script. See `docs/github-action-example.yml` for a fuller `focus-on` /
235
+ `assert-screen` workflow that uploads screenshot artifacts on failure.
236
+
237
+ ## Browser UI
238
+
239
+ The preview shows device tabs, stream status, screenshots, copy-to-clipboard,
240
+ stream stats, logcat, drag-and-drop APK install/file push, phone hardware keys,
241
+ and a TV D-pad remote. Switching tabs re-subscribes to that device's stream
242
+ without reloading the page. TV sessions reject touch input server-side.
243
+
244
+ Video uses WebCodecs by default. Browsers without `VideoDecoder` automatically
245
+ fall back to `/stream.mjpeg`, and `--mjpeg` or `?video=mjpeg` forces that mode.
246
+ MJPEG is implemented with shared `adb screencap` polling at roughly 3 fps,
247
+ re-encoded server-side to downscaled JPEG (pure JS, max 800 px) to keep
248
+ per-frame payloads small; it is a compatibility fallback, not a
249
+ high-frame-rate stream.
250
+
251
+ When serving on a LAN with `--host 0.0.0.0`, Porthole prints a tokenized URL.
252
+ Non-local requests must present that token.
253
+
254
+ Two capability notes:
255
+
256
+ - `porthole emu` / `POST /api/emu` is a raw passthrough to the emulator
257
+ console (`adb emu`) — including commands like `kill`. Treat it as
258
+ operator-level access; anyone who can reach the (token-protected) API can
259
+ use it.
260
+ - `porthole focused` / `get_focused` reads D-pad focus, which is a TV/leanback
261
+ concept. On phone profiles it usually returns `null` unless a view holds
262
+ keyboard focus — that is expected, not an error.
263
+
264
+ ## Troubleshooting
265
+
266
+ | Problem | Fix |
267
+ | ----------------------------- | --------------------------------------------------------------------------- |
268
+ | SDK not found | Set `ANDROID_HOME` or `ANDROID_SDK_ROOT` to your Android SDK |
269
+ | `adb devices` shows `offline` | Porthole runs `adb reconnect offline`; if it persists, restart the emulator |
270
+ | Port `3200` is taken | Pass `-p 3201` or another free port |
271
+ | Blank video | Use a WebCodecs-capable browser and check DevTools for decoder errors |
272
+ | TV taps do nothing | Use `porthole remote <button>`; TV profiles reject touch |
273
+
274
+ ## Development
275
+
276
+ ```sh
277
+ npm install
278
+ npm run build
279
+ npm run test
280
+ npm run lint
281
+ npm run typecheck
282
+ ```
283
+
284
+ Integration tests that require a booted emulator are gated behind
285
+ `PORTHOLE_EMU=1`.