localimage 0.1.0__py3-none-win_amd64.whl

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.
localimage/__init__.py ADDED
@@ -0,0 +1,166 @@
1
+ import json
2
+ import os
3
+ import urllib.error
4
+ import urllib.parse
5
+ import urllib.request
6
+ from dataclasses import dataclass
7
+ from typing import Optional
8
+
9
+ DEFAULT_ADDR = os.environ.get("LOCALIMAGE_ADDR", "127.0.0.1:7777")
10
+
11
+
12
+ @dataclass
13
+ class Session:
14
+ id: str
15
+ browser: str
16
+ protocol: str # "cdp" (chromium) or "playwright" (firefox)
17
+ connect_url: str
18
+ live_url: str # interactive: can control the browser
19
+ view_url: str # read-only: watch only
20
+ profile: Optional[str]
21
+ extensions: list
22
+ expires_at: str
23
+ _client: "LocalImage"
24
+
25
+ def connect(self, playwright):
26
+ """Attach a Playwright instance (from sync_playwright()) to this session."""
27
+ if self.protocol == "cdp":
28
+ return playwright.chromium.connect_over_cdp(self.connect_url)
29
+ return getattr(playwright, self.browser).connect(self.connect_url)
30
+
31
+ def screenshot(self, region: Optional[dict] = None) -> bytes:
32
+ """PNG of the display; pass {"x", "y", "width", "height"} to crop."""
33
+ q = ("?" + urllib.parse.urlencode(region)) if region else ""
34
+ return self._client._raw("GET", f"/v1/sessions/{self.id}/screenshot{q}")
35
+
36
+ # Computer controls act on the whole display (screen coordinates), not a page.
37
+ def _computer(self, action: str, body: dict) -> None:
38
+ self._client._call("POST", f"/v1/sessions/{self.id}/computer/{action}", body)
39
+
40
+ def click(self, x: int, y: int, button: str = "left", num_clicks: int = 1) -> None:
41
+ self._computer("click", {"x": x, "y": y, "button": button, "num_clicks": num_clicks})
42
+
43
+ def move_mouse(self, x: int, y: int) -> None:
44
+ self._computer("move", {"x": x, "y": y})
45
+
46
+ def type(self, text: str, delay_ms: int = 0) -> None:
47
+ self._computer("type", {"text": text, "delay_ms": delay_ms})
48
+
49
+ def press_key(self, *keys: str) -> None:
50
+ self._computer("key", {"keys": list(keys)})
51
+
52
+ def scroll(self, x: int, y: int, delta_x: int = 0, delta_y: int = 0) -> None:
53
+ self._computer("scroll", {"x": x, "y": y, "delta_x": delta_x, "delta_y": delta_y})
54
+
55
+ def drag(self, path: list, button: str = "left") -> None:
56
+ self._computer("drag", {"path": path, "button": button})
57
+
58
+ def start_recording(self) -> dict:
59
+ """Begin a recording; returns {"replay_id", "status"}. One can run at a time."""
60
+ return self._client._call("POST", f"/v1/sessions/{self.id}/recording/start")
61
+
62
+ def stop_recording(self, replay_id: Optional[str] = None) -> dict:
63
+ body = {"replay_id": replay_id} if replay_id else None
64
+ return self._client._call("POST", f"/v1/sessions/{self.id}/recording/stop", body)
65
+
66
+ def recordings(self) -> list:
67
+ return self._client._call("GET", f"/v1/sessions/{self.id}/recordings")
68
+
69
+ def download_recording(self, replay_id: Optional[str] = None) -> bytes:
70
+ """MP4 bytes of a recording; the latest if replay_id is omitted."""
71
+ path = f"/recordings/{replay_id}" if replay_id else "/recording"
72
+ return self._client._raw("GET", f"/v1/sessions/{self.id}{path}")
73
+
74
+ def exec(self, command: list, cwd: Optional[str] = None, timeout_seconds: int = 0) -> dict:
75
+ """Run a command in the session container as the browser user (no shell)."""
76
+ return self._client._call("POST", f"/v1/sessions/{self.id}/process/exec",
77
+ {"command": command, "cwd": cwd or "", "timeout_seconds": timeout_seconds})
78
+
79
+ def upload_file(self, path: str, data: bytes) -> dict:
80
+ q = urllib.parse.urlencode({"path": path})
81
+ return json.loads(self._client._open("PUT", f"/v1/sessions/{self.id}/files?{q}", data=data))
82
+
83
+ def download_file(self, path: str) -> bytes:
84
+ q = urllib.parse.urlencode({"path": path})
85
+ return self._client._raw("GET", f"/v1/sessions/{self.id}/files?{q}")
86
+
87
+ def list_files(self, path: str) -> list:
88
+ q = urllib.parse.urlencode({"path": path})
89
+ return self._client._call("GET", f"/v1/sessions/{self.id}/files/list?{q}")
90
+
91
+ def close(self) -> None:
92
+ self._client.delete(self.id)
93
+
94
+ def __enter__(self) -> "Session":
95
+ return self
96
+
97
+ def __exit__(self, *exc) -> None:
98
+ self.close()
99
+
100
+
101
+ class LocalImage:
102
+ def __init__(self, addr: str = DEFAULT_ADDR, api_key: Optional[str] = None):
103
+ self.addr = addr
104
+ self.api_key = api_key or os.environ.get("LOCALIMAGE_API_KEY")
105
+
106
+ def _open(self, method: str, path: str, body: Optional[dict] = None,
107
+ data: Optional[bytes] = None) -> bytes:
108
+ if data is None and body is not None:
109
+ data = json.dumps(body).encode()
110
+ req = urllib.request.Request(
111
+ f"http://{self.addr}{path}", data=data, method=method,
112
+ headers={"Content-Type": "application/octet-stream" if body is None and data is not None
113
+ else "application/json",
114
+ **({"Authorization": f"Bearer {self.api_key}"} if self.api_key else {})},
115
+ )
116
+ try:
117
+ with urllib.request.urlopen(req, timeout=300) as r:
118
+ return r.read()
119
+ except urllib.error.HTTPError as e:
120
+ msg = json.loads(e.read() or b"{}").get("error", f"HTTP {e.code}")
121
+ raise RuntimeError(msg) from None
122
+ except urllib.error.URLError as e:
123
+ raise RuntimeError(
124
+ f"localimage daemon not reachable at {self.addr}; run `localimage start` ({e.reason})"
125
+ ) from None
126
+
127
+ def _call(self, method: str, path: str, body: Optional[dict] = None):
128
+ raw = self._open(method, path, body)
129
+ return json.loads(raw) if raw else None
130
+
131
+ def _raw(self, method: str, path: str) -> bytes:
132
+ return self._open(method, path)
133
+
134
+ def create(self, browser: str = "chromium", screen: Optional[str] = None,
135
+ ttl_seconds: Optional[int] = None, profile: Optional[str] = None,
136
+ memory_mb: Optional[int] = None, cpus: Optional[float] = None,
137
+ kiosk: bool = False, extensions: Optional[list] = None) -> Session:
138
+ s = self._call("POST", "/v1/sessions", {
139
+ "browser": browser, "screen": screen or "", "ttl_seconds": ttl_seconds or 0,
140
+ "profile": profile or "", "memory_mb": memory_mb or 0, "cpus": cpus or 0,
141
+ "kiosk": kiosk, "extensions": extensions or []})
142
+ return Session(s["id"], s["browser"], s["protocol"], s["connect_url"], s["live_url"],
143
+ s["view_url"], s.get("profile"), s.get("extensions") or [], s["expires_at"], self)
144
+
145
+ def list(self) -> list:
146
+ return self._call("GET", "/v1/sessions")
147
+
148
+ def upload_extension(self, name: str, zip_bytes: bytes) -> dict:
149
+ """Upload an unpacked Chromium extension as a zip (manifest.json at the root or in one folder)."""
150
+ q = urllib.parse.urlencode({"name": name})
151
+ return json.loads(self._open("POST", f"/v1/extensions?{q}", data=zip_bytes))
152
+
153
+ def extensions(self) -> list:
154
+ return self._call("GET", "/v1/extensions")
155
+
156
+ def delete_extension(self, name: str) -> None:
157
+ self._call("DELETE", f"/v1/extensions/{name}")
158
+
159
+ def profiles(self) -> list:
160
+ return self._call("GET", "/v1/profiles")
161
+
162
+ def delete_profile(self, name: str) -> None:
163
+ self._call("DELETE", f"/v1/profiles/{name}")
164
+
165
+ def delete(self, session_id: str) -> None:
166
+ self._call("DELETE", f"/v1/sessions/{session_id}")
Binary file
localimage/cli.py ADDED
@@ -0,0 +1,17 @@
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+ import sys
5
+
6
+
7
+ def main() -> None:
8
+ """Run the bundled Go binary (shipped in platform wheels) or LOCALIMAGE_BIN."""
9
+ binary = os.environ.get("LOCALIMAGE_BIN")
10
+ if not binary:
11
+ here = os.path.dirname(__file__)
12
+ exe = "localimage.exe" if sys.platform == "win32" else "localimage"
13
+ bundled = os.path.join(here, "bin", exe)
14
+ binary = bundled if os.path.exists(bundled) else shutil.which("localimage")
15
+ if not binary:
16
+ sys.exit("localimage: no binary found. Set LOCALIMAGE_BIN to a built binary.")
17
+ sys.exit(subprocess.call([binary, *sys.argv[1:]]))
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.1
2
+ Name: localimage
3
+ Version: 0.1.0
4
+ Summary: Run headful browsers in Docker with live view, locally. CLI + SDK.
5
+ License: Apache-2.0
6
+ Requires-Python: >=3.9
7
+ Project-URL: Homepage, https://github.com/LocalImages/LocalImage
8
+ Project-URL: Source, https://github.com/LocalImages/LocalImage
9
+ Project-URL: Issues, https://github.com/LocalImages/LocalImage/issues
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Software Development :: Testing
13
+ Description-Content-Type: text/markdown
14
+
15
+ # localimage
16
+
17
+ Run real, headful browsers in Docker on your own machine — with a live view you can watch and
18
+ control, recordings, and a Playwright-friendly connection URL. Built for end-to-end testing and
19
+ browser agents that need a visible browser, without a hosted service.
20
+
21
+ - **Chromium and Firefox**, each in its own container with a virtual display
22
+ - **Live view over WebRTC** (smooth video), interactive for you, **read-only** for everyone else
23
+ - **Playwright / Puppeteer** connect over CDP (Chromium) or the Playwright protocol (Firefox)
24
+ - **Recordings** (MP4), **screenshots**, **computer controls** (click, type, scroll, drag),
25
+ **command exec** and **file upload/download** inside the session
26
+ - **Persistent profiles** and **Chromium extensions**
27
+ - One small daemon, a CLI, and SDKs for **Node** and **Python**
28
+
29
+ > Built on [Neko](https://github.com/m1k1o/neko) for the virtual display and WebRTC streaming.
30
+
31
+ ## Requirements
32
+
33
+ - **Docker**, running, and your user allowed to use it (`docker ps` works)
34
+ - Internet access on first use: the browser images are built locally the first time you ask for
35
+ that browser (about 1 minute for Chromium, a few minutes for Firefox), then cached
36
+ - Node 18+ **or** Python 3.9+ for the SDKs (tested on Node 24 and Python 3.14). The `localimage`
37
+ binary itself needs neither.
38
+
39
+ Check your setup any time with `localimage doctor`.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ npm install -g localimage # CLI + Node SDK
45
+ pip install localimage # CLI + Python SDK
46
+ ```
47
+
48
+ Both ship the same prebuilt `localimage` binary for Linux (x64, arm64), macOS (x64, arm64) and
49
+ Windows (x64). Tested on Linux x64; see [Status](#status).
50
+
51
+ ## Quick start
52
+
53
+ ```bash
54
+ localimage doctor # check Docker and the environment
55
+ localimage start # run the daemon (leave it running)
56
+ ```
57
+
58
+ In another terminal:
59
+
60
+ ```bash
61
+ localimage create # prints the session id and URLs
62
+ ```
63
+
64
+ ```jsonc
65
+ {
66
+ "id": "4a7be405",
67
+ "browser": "chromium",
68
+ "protocol": "cdp",
69
+ "connect_url": "http://127.0.0.1:7777/t/<token>/cdp", // for Playwright / Puppeteer
70
+ "live_url": "http://127.0.0.1:7777/t/<token>/live/?...", // open in a browser: control it
71
+ "view_url": "http://127.0.0.1:7777/v/<token>/?..." // open in a browser: watch only
72
+ }
73
+ ```
74
+
75
+ Open `live_url`: you see the browser and can use it straight away (it takes control on your first
76
+ click or keypress). Open `view_url` in another tab: same picture, but nothing you do there reaches
77
+ the browser.
78
+
79
+ ### Node
80
+
81
+ ```js
82
+ import { LocalImage } from 'localimage';
83
+ import * as pw from 'playwright-core';
84
+
85
+ const li = new LocalImage();
86
+ const session = await li.create({ browser: 'chromium' });
87
+ console.log('watch:', session.liveUrl);
88
+
89
+ const browser = await session.connect(pw); // connectOverCDP / firefox.connect for you
90
+ const page = browser.contexts()[0].pages()[0] ?? await browser.contexts()[0].newPage();
91
+ await page.goto('https://example.com');
92
+
93
+ await session.startRecording();
94
+ // ... drive the page ...
95
+ await session.stopRecording();
96
+ const mp4 = await session.downloadRecording(); // Buffer
97
+
98
+ await browser.close();
99
+ await session.close(); // removes the container
100
+ ```
101
+
102
+ ### Python
103
+
104
+ ```python
105
+ from localimage import LocalImage
106
+ from playwright.sync_api import sync_playwright
107
+
108
+ with sync_playwright() as pw, LocalImage().create(browser="firefox") as session:
109
+ print("watch:", session.live_url)
110
+ browser = session.connect(pw)
111
+ page = browser.new_page()
112
+ page.goto("https://example.com")
113
+ open("shot.png", "wb").write(session.screenshot())
114
+ ```
115
+
116
+ ### Firefox needs a matching Playwright
117
+
118
+ Firefox is driven through Playwright's own server inside the container, so your client's
119
+ `playwright` / `playwright-core` version must match the one in the image, currently **1.63.0**.
120
+ Chromium uses plain CDP and works with any Playwright version.
121
+
122
+ ## Sessions and options
123
+
124
+ `create` / `LocalImage.create(...)` accept:
125
+
126
+ | Option | Meaning |
127
+ |---|---|
128
+ | `browser` | `chromium` (default) or `firefox` |
129
+ | `ttl` / `ttlSeconds` | lifetime in seconds; the session is removed after it (default 30 min) |
130
+ | `profile` | named persistent profile (cookies, storage, …). Chromium only. One live session per profile |
131
+ | `extensions` | names of uploaded extensions to load. Chromium only |
132
+ | `kiosk` | Chromium without tabs or address bar |
133
+ | `screen` | display size, e.g. `1440x900@30` (default) |
134
+ | `memoryMb`, `cpus` | resource limits for the container |
135
+
136
+ Sessions are Docker containers named `localimage-<id>`. They are removed on `close()`, on `rm`, or
137
+ when their TTL expires while the daemon runs.
138
+
139
+ ## Features
140
+
141
+ - **Recordings:** `startRecording` / `stopRecording`, several per session, one running at a time;
142
+ list and download each as MP4.
143
+ - **Screenshots:** whole display or a cropped region.
144
+ - **Computer controls:** `click`, `moveMouse`, `type`, `pressKey`, `scroll`, `drag`. These act on
145
+ the whole display in screen coordinates (not page coordinates) and work for both browsers.
146
+ - **Exec:** run a command inside the session as the browser user (no shell unless you pass
147
+ `["sh", "-c", ...]`), with a timeout and capped output.
148
+ - **Files:** upload, download and list files inside the session (e.g. the browser's Downloads).
149
+ - **Profiles:** `localimage create --profile work` keeps cookies and storage between sessions.
150
+ - **Extensions:** `localimage extension upload my-ext ./my-ext-dir`, then
151
+ `localimage create --extension my-ext`.
152
+
153
+ ## CLI
154
+
155
+ ```
156
+ localimage start [-addr host:port] run the daemon (default 127.0.0.1:7777)
157
+ localimage doctor check Docker, images and the daemon
158
+ localimage create [flags] start a session
159
+ localimage ls | rm <id> list / delete sessions
160
+ localimage exec <id> -- <cmd...> run a command in a session
161
+ localimage screenshot <id> [-o file]
162
+ localimage record start|stop|get <id> [-o file]
163
+ localimage profile ls | rm <name>
164
+ localimage extension upload <name> <dir-or-zip> | ls | rm <name>
165
+ ```
166
+
167
+ Run `localimage help` for every flag.
168
+
169
+ ## HTTP API
170
+
171
+ The daemon exposes a JSON API (default `http://127.0.0.1:7777`):
172
+
173
+ | | |
174
+ |---|---|
175
+ | `POST/GET /v1/sessions`, `GET/DELETE /v1/sessions/{id}` | create, list, inspect, delete |
176
+ | `POST /v1/sessions/{id}/recording/start`, `.../stop`; `GET .../recording`, `.../recordings[/{rid}]` | recordings |
177
+ | `GET /v1/sessions/{id}/screenshot[?x=&y=&width=&height=]` | PNG |
178
+ | `POST /v1/sessions/{id}/computer/{click,move,type,key,scroll,drag}` | input |
179
+ | `POST /v1/sessions/{id}/process/exec` | run a command |
180
+ | `PUT/GET /v1/sessions/{id}/files?path=`, `GET .../files/list?path=` | file I/O |
181
+ | `POST/GET /v1/extensions`, `DELETE /v1/extensions/{name}` | extensions (zip upload) |
182
+ | `GET /v1/profiles`, `DELETE /v1/profiles/{name}` | profiles |
183
+ | `GET /healthz` | liveness |
184
+
185
+ ## Configuration
186
+
187
+ | Variable | Default | |
188
+ |---|---|---|
189
+ | `LOCALIMAGE_ADDR` | `127.0.0.1:7777` | daemon address (CLI and SDKs) |
190
+ | `LOCALIMAGE_API_KEY` | unset | if set, the control API requires `Authorization: Bearer <key>` |
191
+ | `LOCALIMAGE_PUBLIC_IP` | `127.0.0.1` | address clients use for WebRTC media (see below) |
192
+ | `LOCALIMAGE_MAX_SESSIONS` | `10` | concurrent sessions allowed |
193
+ | `LOCALIMAGE_MAX_TTL_SECONDS` | `86400` | longest session lifetime allowed |
194
+
195
+ ## Security model
196
+
197
+ - The daemon listens on **loopback only** by default and **refuses to listen on any other address
198
+ unless `LOCALIMAGE_API_KEY` is set**.
199
+ - Each session has a random secret in its URLs. `connect_url` and `live_url` give full control of
200
+ the browser; `view_url` uses a different secret and a viewer login that cannot control anything
201
+ and cannot reach CDP. **Treat these URLs like passwords.**
202
+ - Anyone with the API key can run commands and read files in your session containers. Sessions are
203
+ containers, not a hardened sandbox for hostile code.
204
+ - WebRTC video cannot go through the HTTP proxy: each session also opens one media port on the
205
+ host (the same number inside and outside the container).
206
+ - Sessions are not encrypted on the wire: there is no TLS. Do not expose the daemon to untrusted
207
+ networks.
208
+
209
+ ## Troubleshooting
210
+
211
+ - **`localimage doctor`** explains most setup problems.
212
+ - **Black or frozen live view:** a VPN, firewall or browser extension that blocks WebRTC. Try a
213
+ private window with extensions off, and open the page at `127.0.0.1:7777`.
214
+ - **Remote use:** set `LOCALIMAGE_PUBLIC_IP` to an address the viewer can reach, bind the daemon
215
+ to a non-loopback address and set `LOCALIMAGE_API_KEY`. This setup is not tested yet.
216
+ - **"profile is already in use":** a Chromium profile can only be open in one session at a time.
217
+ - **Firefox connect fails with a version error:** match Playwright to the image's version.
218
+
219
+ ## Status
220
+
221
+ Early (0.x). Tested end to end on Linux x64 with Docker: both browsers, live view video and
222
+ control in Chrome, read-only enforcement, recordings, profiles, extensions, exec and files.
223
+ The macOS and Windows builds compile but have not been run. Not implemented: warm browser pools,
224
+ standby/resume, stealth and proxy options, WebKit, TLS, multi-host scaling.
225
+
226
+ ## Development
227
+
228
+ ```bash
229
+ go vet ./... && go test ./... # unit tests (Go version: see go.mod)
230
+ go build -o bin/localimage ./cmd/localimage
231
+
232
+ localimage start & # then, in packages/npm:
233
+ npm install && npm test # end-to-end tests (needs Docker + network;
234
+ # the live-view test also needs Chrome/Chromium)
235
+
236
+ python3 scripts/package.py # build binaries, npm packages and wheels into dist/
237
+ python3 scripts/bump-version.py 0.2.0 # set the version everywhere
238
+ ```
239
+
240
+ See [RELEASING.md](RELEASING.md) for the release process.
241
+
242
+ ## Acknowledgements
243
+
244
+ Streaming and the virtual display come from [Neko](https://github.com/m1k1o/neko) (Apache-2.0).
245
+ Firefox automation uses [Playwright](https://playwright.dev) (Apache-2.0). The browser images are
246
+ built locally on your machine from upstream Debian packages and the Neko base images.
247
+
248
+ ## License
249
+
250
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,8 @@
1
+ localimage/__init__.py,sha256=uXCghJvzfI9pEFhKHZZ95Qp5NQAe3vxH91V-9cXl45E,7369
2
+ localimage/cli.py,sha256=6mtErpCG-WoGr15JcNBGD8wGuItgS2nLUt04AaqJJ5Q,635
3
+ localimage/bin/localimage.exe,sha256=pyzSTbvNyfpO1XSEaT_UXySQbJwu7eBgfmP0hZ2FQj4,9555456
4
+ localimage-0.1.0.dist-info/METADATA,sha256=a2tLz6thoq-UYSb-ITZSHfdftCjMNSC8YQYWM67Ffp0,10676
5
+ localimage-0.1.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
6
+ localimage-0.1.0.dist-info/WHEEL,sha256=MNa-DEtQPIqhVZKuL7NqnI1k-YYMQ1MICedu76NKZ80,96
7
+ localimage-0.1.0.dist-info/entry_points.txt,sha256=BPMLiDLHFgIqSAHIIER2-ME8OxzS2nh5n770WE6RCGY,51
8
+ localimage-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: localimage-package
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ localimage = localimage.cli:main