doescap 1.0.0__tar.gz

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.
doescap-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GhoSty (https://github.com/ghostypie)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
doescap-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,235 @@
1
+ Metadata-Version: 2.4
2
+ Name: doescap
3
+ Version: 1.0.0
4
+ Summary: DoesCap: Fast, lightweight cross-platform hCaptcha relay and solver library built by GhoSty, supporting Windows, macOS, Linux, and Android (Termux).
5
+ Author: GhoSty
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ghostypie/DoesCap
8
+ Project-URL: Documentation, https://ghostypie.github.io/DoesCap/
9
+ Project-URL: Repository, https://github.com/ghostypie/DoesCap
10
+ Project-URL: Issues, https://github.com/ghostypie/DoesCap/issues
11
+ Project-URL: Author GitHub, https://github.com/ghostypie
12
+ Project-URL: Discord Support, https://discord.com/invite/asMJGgDA7u
13
+ Project-URL: Support / Donate, https://donatr.ee/brutality/
14
+ Keywords: doescap,hcaptcha,captcha,relay,termux,android,cdp,automation
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
+ Classifier: Topic :: Internet :: WWW/HTTP
29
+ Requires-Python: >=3.8
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Provides-Extra: screencast
33
+ Requires-Dist: websocket-client>=1.6.0; extra == "screencast"
34
+ Dynamic: license-file
35
+
36
+ # DoesCap
37
+
38
+ A standalone, high-performance hCaptcha relay and verification library for Python.
39
+
40
+ Built for seamless operation across **Windows**, **macOS**, **Linux**, and **Android (Termux)**.
41
+
42
+ ---
43
+
44
+ ## Author & Community
45
+
46
+ - **Author**: **GhoSty** — [https://github.com/ghostypie](https://github.com/ghostypie)
47
+ - **Discord Support Server**: [https://discord.com/invite/asMJGgDA7u](https://discord.com/invite/asMJGgDA7u)
48
+ - **Support / Donate (Donatree)**: [https://donatr.ee/brutality/](https://donatr.ee/brutality/)
49
+
50
+ ---
51
+
52
+ ## Key Features
53
+
54
+ - **Zero-Latency Direct Solver (Default)**: Renders the official challenge natively in the user's browser with 60Hz/120Hz touch responsiveness. Zero extra CPU or RAM consumption.
55
+ - **Custom Webpage Designs**: Port your own custom HTML, CSS, logos, fonts, and layouts via `custom_html`, `custom_html_path`, and `custom_assets_dir` (including `{{ title }}`, `{{ theme }}`, `{{ sitekey }}`, and `{{ rqdata }}` SSR placeholders).
56
+ - **Universal Android & Termux Support**: Automatically handles Termux URL opening tools (`termux-open-url`, `termux-open`) and native Android activity intents (`am start`).
57
+ - **Modular 2D Documentation**: Multi-page 2D neo-brutalist documentation site with cross-page search, Next/Previous module navigation, and dark mode toggle in the `docs/` folder.
58
+ - **Headless Screencast Mode**: Optional fallback mode that runs a headless Chromium instance (`browser_path`) and mirrors frames over HTTP when `websocket-client` is installed, automatically falling back to Direct Mode if unavailable.
59
+ - **LAN Relay Accessibility**: Automatically determines local network IP address (`get_local_ip`), allowing mobile devices on the same Wi-Fi network to complete challenges running on desktop or remote hosts.
60
+ - **Full Type Hints & Async Support**: Both synchronous (`solve`, `solve_captcha`) and asynchronous (`async_solve`, `async_solve_captcha`) APIs returning string-subclass `SolveResult` objects.
61
+ - **Standalone CLI**: Command-line tool `doescap` for immediate terminal verification.
62
+
63
+ ---
64
+
65
+ ## Documentation
66
+
67
+ Full modular documentation is included in the `docs/` folder:
68
+ - **Offline / Local preview**: Open [docs/index.html](docs/index.html) in any browser, or run:
69
+ ```bash
70
+ python docs/serve.py
71
+ ```
72
+ - Features a ReadTheDocs-style sidebar, cross-page search (`Ctrl+K`), Next/Previous module navigation buttons, REST API specs, parameter tables, and a 2D neo-brutalist light/dark mode toggle.
73
+
74
+ ---
75
+
76
+ ## Installation
77
+
78
+ ```bash
79
+ pip install doescap
80
+ ```
81
+
82
+ To enable headless CDP screencast streaming (optional):
83
+
84
+ ```bash
85
+ pip install "doescap[screencast]"
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Quickstart
91
+
92
+ ### 1. Functional Sync API
93
+
94
+ ```python
95
+ from doescap import solve_captcha
96
+
97
+ token = solve_captcha(
98
+ sitekey="4c672d35-0701-42b2-88c3-78380b0db560",
99
+ rqdata=None,
100
+ port=8787,
101
+ auto_open_browser=True,
102
+ )
103
+
104
+ if token:
105
+ print(f"Verified Token: {token}")
106
+ else:
107
+ print("Verification failed or timed out.")
108
+ ```
109
+
110
+ ### 2. Functional Async API
111
+
112
+ ```python
113
+ import asyncio
114
+ from doescap import async_solve_captcha
115
+
116
+ async def main():
117
+ token = await async_solve_captcha(
118
+ sitekey="4c672d35-0701-42b2-88c3-78380b0db560",
119
+ port=8787,
120
+ )
121
+ print("Token:", token)
122
+
123
+ asyncio.run(main())
124
+ ```
125
+
126
+ ### 3. Object-Oriented Client
127
+
128
+ ```python
129
+ from doescap import DoesCap, RelayConfig
130
+
131
+ config = RelayConfig(
132
+ host="0.0.0.0",
133
+ port=8787,
134
+ auto_open_browser=True,
135
+ timeout=300,
136
+ title="DoesCap Verification Portal",
137
+ theme="dark",
138
+ )
139
+
140
+ with DoesCap(config=config) as relay:
141
+ result = relay.solve(
142
+ sitekey="4c672d35-0701-42b2-88c3-78380b0db560",
143
+ rqdata=None,
144
+ task_name="Verification Challenge",
145
+ )
146
+
147
+ if result:
148
+ print(f"Solved in {result.elapsed_seconds:.2f}s")
149
+ print(f"Token: {result.token}")
150
+ # Compatible directly as a str in headers: {"X-Captcha-Key": result}
151
+ relay.mark_claimed(task_name="Verification Challenge", promo_code="PASS-200")
152
+ ```
153
+
154
+ ### 4. Custom Webpage Design & Branding
155
+
156
+ You can supply your own custom HTML template and static assets:
157
+
158
+ ```python
159
+ from doescap import DoesCap, RelayConfig
160
+
161
+ config = RelayConfig(
162
+ host="0.0.0.0",
163
+ port=8787,
164
+ custom_html_path="path/to/my_template.html",
165
+ custom_assets_dir="path/to/my_assets",
166
+ )
167
+
168
+ with DoesCap(config=config) as relay:
169
+ token = relay.solve(sitekey="YOUR_SITEKEY")
170
+ ```
171
+
172
+ #### Custom HTML Contract
173
+ Your custom HTML can read SSR placeholders (`{{ title }}`, `{{ theme }}`, `{{ sitekey }}`, `{{ rqdata }}`) or communicate with two lightweight endpoints:
174
+ 1. `GET /status`: Returns JSON with active `sitekey`, `rqdata`, `mode`, `task_name`, `promo_code`, and state.
175
+ 2. `POST /solve`: Send `{ "token": token }` once hCaptcha's callback fires.
176
+
177
+ Static files inside `custom_assets_dir` are served securely under `/assets/*`.
178
+
179
+ ---
180
+
181
+ ## Configuration Reference
182
+
183
+ | Parameter | Type | Default | Description |
184
+ | :--- | :--- | :--- | :--- |
185
+ | `host` | `str` | `"0.0.0.0"` | Host IP to bind the relay webserver to. |
186
+ | `port` | `int` | `8787` | Preferred TCP port. Ephemeral port chosen if busy. |
187
+ | `auto_open_browser` | `bool` | `True` | Automatically opens default browser on the device. |
188
+ | `browser_path` | `str \| None` | `None` | Path or binary keyword for headless CDP screencast mode. |
189
+ | `timeout` | `int` | `300` | Max wait time in seconds before returning `None`. |
190
+ | `title` | `str` | `"DoesCap Relay"` | Title string displayed in the web UI header. |
191
+ | `theme` | `str` | `"dark"` | UI theme (`"dark"` or `"light"`). |
192
+ | `allow_firewall_rule` | `bool` | `True` | Attempts Windows Firewall port opening on Windows. |
193
+ | `custom_html` | `str \| None` | `None` | Raw HTML string to serve as the custom UI. |
194
+ | `custom_html_path` | `str \| None` | `None` | Filepath to a custom `.html` template to serve. |
195
+ | `custom_assets_dir` | `str \| None` | `None` | Directory of assets (CSS, images, fonts) served at `/assets/*`. |
196
+
197
+ ---
198
+
199
+ ## Termux Android Usage
200
+
201
+ `DoesCap` works directly in Termux on Android without requiring root or display servers (no X11 / VNC needed).
202
+
203
+ 1. Install Python in Termux:
204
+ ```bash
205
+ pkg update && pkg install python
206
+ ```
207
+ 2. Install package:
208
+ ```bash
209
+ pip install doescap
210
+ ```
211
+ 3. Run or import in your script. When executed, it launches your mobile Chrome or default Android browser via system intents, lets you complete the challenge smoothly with hardware-accelerated touch, and captures the solution token.
212
+
213
+ ---
214
+
215
+ ## CLI & Testing
216
+
217
+ ```bash
218
+ doescap --sitekey "YOUR_SITEKEY" --rqdata "OPTIONAL_RQDATA" --port 8787
219
+ ```
220
+
221
+ With custom HTML and assets:
222
+ ```bash
223
+ doescap --sitekey "YOUR_SITEKEY" --custom-html "./my_ui.html" --assets-dir "./assets"
224
+ ```
225
+
226
+ Run the offline unit test suite:
227
+ ```bash
228
+ pytest
229
+ ```
230
+
231
+ ---
232
+
233
+ ## License
234
+
235
+ MIT License — Copyright (c) 2026 [GhoSty](https://github.com/ghostypie).
@@ -0,0 +1,200 @@
1
+ # DoesCap
2
+
3
+ A standalone, high-performance hCaptcha relay and verification library for Python.
4
+
5
+ Built for seamless operation across **Windows**, **macOS**, **Linux**, and **Android (Termux)**.
6
+
7
+ ---
8
+
9
+ ## Author & Community
10
+
11
+ - **Author**: **GhoSty** — [https://github.com/ghostypie](https://github.com/ghostypie)
12
+ - **Discord Support Server**: [https://discord.com/invite/asMJGgDA7u](https://discord.com/invite/asMJGgDA7u)
13
+ - **Support / Donate (Donatree)**: [https://donatr.ee/brutality/](https://donatr.ee/brutality/)
14
+
15
+ ---
16
+
17
+ ## Key Features
18
+
19
+ - **Zero-Latency Direct Solver (Default)**: Renders the official challenge natively in the user's browser with 60Hz/120Hz touch responsiveness. Zero extra CPU or RAM consumption.
20
+ - **Custom Webpage Designs**: Port your own custom HTML, CSS, logos, fonts, and layouts via `custom_html`, `custom_html_path`, and `custom_assets_dir` (including `{{ title }}`, `{{ theme }}`, `{{ sitekey }}`, and `{{ rqdata }}` SSR placeholders).
21
+ - **Universal Android & Termux Support**: Automatically handles Termux URL opening tools (`termux-open-url`, `termux-open`) and native Android activity intents (`am start`).
22
+ - **Modular 2D Documentation**: Multi-page 2D neo-brutalist documentation site with cross-page search, Next/Previous module navigation, and dark mode toggle in the `docs/` folder.
23
+ - **Headless Screencast Mode**: Optional fallback mode that runs a headless Chromium instance (`browser_path`) and mirrors frames over HTTP when `websocket-client` is installed, automatically falling back to Direct Mode if unavailable.
24
+ - **LAN Relay Accessibility**: Automatically determines local network IP address (`get_local_ip`), allowing mobile devices on the same Wi-Fi network to complete challenges running on desktop or remote hosts.
25
+ - **Full Type Hints & Async Support**: Both synchronous (`solve`, `solve_captcha`) and asynchronous (`async_solve`, `async_solve_captcha`) APIs returning string-subclass `SolveResult` objects.
26
+ - **Standalone CLI**: Command-line tool `doescap` for immediate terminal verification.
27
+
28
+ ---
29
+
30
+ ## Documentation
31
+
32
+ Full modular documentation is included in the `docs/` folder:
33
+ - **Offline / Local preview**: Open [docs/index.html](docs/index.html) in any browser, or run:
34
+ ```bash
35
+ python docs/serve.py
36
+ ```
37
+ - Features a ReadTheDocs-style sidebar, cross-page search (`Ctrl+K`), Next/Previous module navigation buttons, REST API specs, parameter tables, and a 2D neo-brutalist light/dark mode toggle.
38
+
39
+ ---
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install doescap
45
+ ```
46
+
47
+ To enable headless CDP screencast streaming (optional):
48
+
49
+ ```bash
50
+ pip install "doescap[screencast]"
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Quickstart
56
+
57
+ ### 1. Functional Sync API
58
+
59
+ ```python
60
+ from doescap import solve_captcha
61
+
62
+ token = solve_captcha(
63
+ sitekey="4c672d35-0701-42b2-88c3-78380b0db560",
64
+ rqdata=None,
65
+ port=8787,
66
+ auto_open_browser=True,
67
+ )
68
+
69
+ if token:
70
+ print(f"Verified Token: {token}")
71
+ else:
72
+ print("Verification failed or timed out.")
73
+ ```
74
+
75
+ ### 2. Functional Async API
76
+
77
+ ```python
78
+ import asyncio
79
+ from doescap import async_solve_captcha
80
+
81
+ async def main():
82
+ token = await async_solve_captcha(
83
+ sitekey="4c672d35-0701-42b2-88c3-78380b0db560",
84
+ port=8787,
85
+ )
86
+ print("Token:", token)
87
+
88
+ asyncio.run(main())
89
+ ```
90
+
91
+ ### 3. Object-Oriented Client
92
+
93
+ ```python
94
+ from doescap import DoesCap, RelayConfig
95
+
96
+ config = RelayConfig(
97
+ host="0.0.0.0",
98
+ port=8787,
99
+ auto_open_browser=True,
100
+ timeout=300,
101
+ title="DoesCap Verification Portal",
102
+ theme="dark",
103
+ )
104
+
105
+ with DoesCap(config=config) as relay:
106
+ result = relay.solve(
107
+ sitekey="4c672d35-0701-42b2-88c3-78380b0db560",
108
+ rqdata=None,
109
+ task_name="Verification Challenge",
110
+ )
111
+
112
+ if result:
113
+ print(f"Solved in {result.elapsed_seconds:.2f}s")
114
+ print(f"Token: {result.token}")
115
+ # Compatible directly as a str in headers: {"X-Captcha-Key": result}
116
+ relay.mark_claimed(task_name="Verification Challenge", promo_code="PASS-200")
117
+ ```
118
+
119
+ ### 4. Custom Webpage Design & Branding
120
+
121
+ You can supply your own custom HTML template and static assets:
122
+
123
+ ```python
124
+ from doescap import DoesCap, RelayConfig
125
+
126
+ config = RelayConfig(
127
+ host="0.0.0.0",
128
+ port=8787,
129
+ custom_html_path="path/to/my_template.html",
130
+ custom_assets_dir="path/to/my_assets",
131
+ )
132
+
133
+ with DoesCap(config=config) as relay:
134
+ token = relay.solve(sitekey="YOUR_SITEKEY")
135
+ ```
136
+
137
+ #### Custom HTML Contract
138
+ Your custom HTML can read SSR placeholders (`{{ title }}`, `{{ theme }}`, `{{ sitekey }}`, `{{ rqdata }}`) or communicate with two lightweight endpoints:
139
+ 1. `GET /status`: Returns JSON with active `sitekey`, `rqdata`, `mode`, `task_name`, `promo_code`, and state.
140
+ 2. `POST /solve`: Send `{ "token": token }` once hCaptcha's callback fires.
141
+
142
+ Static files inside `custom_assets_dir` are served securely under `/assets/*`.
143
+
144
+ ---
145
+
146
+ ## Configuration Reference
147
+
148
+ | Parameter | Type | Default | Description |
149
+ | :--- | :--- | :--- | :--- |
150
+ | `host` | `str` | `"0.0.0.0"` | Host IP to bind the relay webserver to. |
151
+ | `port` | `int` | `8787` | Preferred TCP port. Ephemeral port chosen if busy. |
152
+ | `auto_open_browser` | `bool` | `True` | Automatically opens default browser on the device. |
153
+ | `browser_path` | `str \| None` | `None` | Path or binary keyword for headless CDP screencast mode. |
154
+ | `timeout` | `int` | `300` | Max wait time in seconds before returning `None`. |
155
+ | `title` | `str` | `"DoesCap Relay"` | Title string displayed in the web UI header. |
156
+ | `theme` | `str` | `"dark"` | UI theme (`"dark"` or `"light"`). |
157
+ | `allow_firewall_rule` | `bool` | `True` | Attempts Windows Firewall port opening on Windows. |
158
+ | `custom_html` | `str \| None` | `None` | Raw HTML string to serve as the custom UI. |
159
+ | `custom_html_path` | `str \| None` | `None` | Filepath to a custom `.html` template to serve. |
160
+ | `custom_assets_dir` | `str \| None` | `None` | Directory of assets (CSS, images, fonts) served at `/assets/*`. |
161
+
162
+ ---
163
+
164
+ ## Termux Android Usage
165
+
166
+ `DoesCap` works directly in Termux on Android without requiring root or display servers (no X11 / VNC needed).
167
+
168
+ 1. Install Python in Termux:
169
+ ```bash
170
+ pkg update && pkg install python
171
+ ```
172
+ 2. Install package:
173
+ ```bash
174
+ pip install doescap
175
+ ```
176
+ 3. Run or import in your script. When executed, it launches your mobile Chrome or default Android browser via system intents, lets you complete the challenge smoothly with hardware-accelerated touch, and captures the solution token.
177
+
178
+ ---
179
+
180
+ ## CLI & Testing
181
+
182
+ ```bash
183
+ doescap --sitekey "YOUR_SITEKEY" --rqdata "OPTIONAL_RQDATA" --port 8787
184
+ ```
185
+
186
+ With custom HTML and assets:
187
+ ```bash
188
+ doescap --sitekey "YOUR_SITEKEY" --custom-html "./my_ui.html" --assets-dir "./assets"
189
+ ```
190
+
191
+ Run the offline unit test suite:
192
+ ```bash
193
+ pytest
194
+ ```
195
+
196
+ ---
197
+
198
+ ## License
199
+
200
+ MIT License — Copyright (c) 2026 [GhoSty](https://github.com/ghostypie).
@@ -0,0 +1,26 @@
1
+ """
2
+ DoesCap: A lightweight, cross-platform hCaptcha relay and solver library.
3
+
4
+ Works natively on Windows, macOS, Linux, and Android (Termux).
5
+ Provides both Direct In-Browser solving (zero overhead, 60/120Hz native touch)
6
+ and Headless CDP Screencast mode.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from .config import RelayConfig, SolveResult
12
+ from .client import DoesCap, HCaptchaRelay, solve_captcha, async_solve_captcha
13
+ from .network import get_local_ip
14
+
15
+ __version__ = "1.0.0"
16
+ __author__ = "GhoSty"
17
+ __all__ = [
18
+ "DoesCap",
19
+ "HCaptchaRelay",
20
+ "RelayConfig",
21
+ "SolveResult",
22
+ "solve_captcha",
23
+ "async_solve_captcha",
24
+ "get_local_ip",
25
+ "__version__",
26
+ ]
@@ -0,0 +1,187 @@
1
+ """Cross-platform browser launcher and binary detector."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shutil
7
+ import subprocess
8
+ import sys
9
+ import webbrowser
10
+ from typing import Optional, Tuple
11
+
12
+
13
+ def is_android_termux() -> bool:
14
+ """Check if execution environment is running inside Android or Termux."""
15
+ return (
16
+ "ANDROID_ROOT" in os.environ
17
+ or "TERMUX_VERSION" in os.environ
18
+ or "com.termux" in os.environ.get("PREFIX", "")
19
+ )
20
+
21
+
22
+ def open_browser(url: str) -> bool:
23
+ """Open the given URL in the default browser across all operating systems.
24
+
25
+ Supports Android/Termux via termux tools and Android Activity Manager (am),
26
+ Linux via xdg-open, and standard systems via Python's webbrowser module.
27
+
28
+ Args:
29
+ url: Full HTTP/HTTPS URL string to open.
30
+
31
+ Returns:
32
+ True if an opener command was initiated successfully, False otherwise.
33
+ """
34
+ candidates = [
35
+ # Termux URL openers
36
+ ["termux-open-url", url],
37
+ ["termux-open", url],
38
+ # Android Chrome intent
39
+ ["am", "start", "--user", "0", "-a", "android.intent.action.VIEW", "-d", url, "-n", "com.android.chrome/com.google.android.apps.chrome.Main"],
40
+ ["am", "start", "-a", "android.intent.action.VIEW", "-d", url, "-n", "com.android.chrome/com.google.android.apps.chrome.Main"],
41
+ # Android generic VIEW intent
42
+ ["am", "start", "--user", "0", "-a", "android.intent.action.VIEW", "-d", url],
43
+ ["am", "start", "-a", "android.intent.action.VIEW", "-d", url],
44
+ # Explicit system path for am on rooted or restricted devices
45
+ ["/system/bin/am", "start", "--user", "0", "-a", "android.intent.action.VIEW", "-d", url, "-n", "com.android.chrome/com.google.android.apps.chrome.Main"],
46
+ ["/system/bin/am", "start", "-a", "android.intent.action.VIEW", "-d", url, "-n", "com.android.chrome/com.google.android.apps.chrome.Main"],
47
+ ["/system/bin/am", "start", "--user", "0", "-a", "android.intent.action.VIEW", "-d", url],
48
+ ["/system/bin/am", "start", "-a", "android.intent.action.VIEW", "-d", url],
49
+ # Linux desktop
50
+ ["xdg-open", url],
51
+ ]
52
+
53
+ for cmd in candidates:
54
+ try:
55
+ exe = shutil.which(cmd[0]) or (cmd[0] if os.path.exists(cmd[0]) else None)
56
+ if exe:
57
+ subprocess.Popen(
58
+ [exe] + cmd[1:],
59
+ stdout=subprocess.DEVNULL,
60
+ stderr=subprocess.DEVNULL,
61
+ )
62
+ return True
63
+ except Exception:
64
+ continue
65
+
66
+ # Fallback to standard Python webbrowser
67
+ try:
68
+ webbrowser.open(url, new=2)
69
+ return True
70
+ except Exception:
71
+ return False
72
+
73
+
74
+ def find_browser(override_path: Optional[str] = None) -> Tuple[Optional[str], Optional[str]]:
75
+ """Locate an installed Chromium-compatible browser executable.
76
+
77
+ Args:
78
+ override_path: Optional explicit file path or keyword binary name.
79
+
80
+ Returns:
81
+ Tuple of (executable_path, friendly_name), or (None, None) if not found.
82
+ """
83
+ if override_path:
84
+ clean = override_path.strip().strip('"').strip("'")
85
+ if os.path.isfile(clean):
86
+ return clean, "Custom Browser"
87
+
88
+ kw = clean.lower()
89
+ which_path = shutil.which(kw)
90
+ if which_path and "WindowsApps" not in which_path and os.path.isfile(which_path):
91
+ return which_path, f"{kw.capitalize()} (PATH)"
92
+
93
+ # Termux does not host full desktop Chromium with CDP by default
94
+ if is_android_termux():
95
+ return None, None
96
+
97
+ if os.name == "nt":
98
+ prog = os.environ.get("PROGRAMFILES", r"C:\Program Files")
99
+ prog86 = os.environ.get("PROGRAMFILES(X86)", r"C:\Program Files (x86)")
100
+ local = os.environ.get("LOCALAPPDATA", "")
101
+
102
+ chrome_candidates = [
103
+ os.path.join(prog, "Google", "Chrome", "Application", "chrome.exe"),
104
+ os.path.join(prog86, "Google", "Chrome", "Application", "chrome.exe"),
105
+ os.path.join(local, "Google", "Chrome", "Application", "chrome.exe"),
106
+ os.path.join(local, "Google", "Chrome SxS", "Application", "chrome.exe"),
107
+ ]
108
+ for p in chrome_candidates:
109
+ if os.path.isfile(p):
110
+ return p, "Google Chrome"
111
+
112
+ brave_candidates = [
113
+ os.path.join(prog, "BraveSoftware", "Brave-Browser", "Application", "brave.exe"),
114
+ os.path.join(local, "BraveSoftware", "Brave-Browser", "Application", "brave.exe"),
115
+ os.path.join(prog86, "BraveSoftware", "Brave-Browser", "Application", "brave.exe"),
116
+ ]
117
+ for p in brave_candidates:
118
+ if os.path.isfile(p):
119
+ return p, "Brave Browser"
120
+
121
+ chromium_candidates = [
122
+ os.path.join(local, "Chromium", "Application", "chrome.exe"),
123
+ os.path.join(prog, "Chromium", "Application", "chrome.exe"),
124
+ os.path.join(prog86, "Chromium", "Application", "chrome.exe"),
125
+ ]
126
+ for p in chromium_candidates:
127
+ if os.path.isfile(p):
128
+ return p, "Chromium"
129
+
130
+ edge_candidates = [
131
+ os.path.join(prog86, "Microsoft", "Edge", "Application", "msedge.exe"),
132
+ os.path.join(prog, "Microsoft", "Edge", "Application", "msedge.exe"),
133
+ os.path.join(local, "Microsoft", "Edge", "Application", "msedge.exe"),
134
+ ]
135
+ for p in edge_candidates:
136
+ if os.path.isfile(p):
137
+ return p, "Microsoft Edge"
138
+
139
+ opera_candidates = [
140
+ os.path.join(local, "Programs", "Opera", "opera.exe"),
141
+ os.path.join(local, "Programs", "Opera GX", "opera.exe"),
142
+ os.path.join(prog, "Opera", "launcher.exe"),
143
+ os.path.join(prog86, "Opera", "launcher.exe"),
144
+ ]
145
+ for p in opera_candidates:
146
+ if os.path.isfile(p):
147
+ return p, "Opera"
148
+
149
+ vivaldi_candidates = [
150
+ os.path.join(local, "Vivaldi", "Application", "vivaldi.exe"),
151
+ os.path.join(prog, "Vivaldi", "Application", "vivaldi.exe"),
152
+ os.path.join(prog86, "Vivaldi", "Application", "vivaldi.exe"),
153
+ ]
154
+ for p in vivaldi_candidates:
155
+ if os.path.isfile(p):
156
+ return p, "Vivaldi"
157
+
158
+ if sys.platform == "darwin":
159
+ mac_paths = [
160
+ ("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "Google Chrome"),
161
+ ("/Applications/Brave Browser.app/Contents/MacOS/Brave Browser", "Brave Browser"),
162
+ ("/Applications/Chromium.app/Contents/MacOS/Chromium", "Chromium"),
163
+ ("/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", "Microsoft Edge"),
164
+ ("/Applications/Opera.app/Contents/MacOS/Opera", "Opera"),
165
+ ("/Applications/Vivaldi.app/Contents/MacOS/Vivaldi", "Vivaldi"),
166
+ ]
167
+ for p, name in mac_paths:
168
+ if os.path.isfile(p):
169
+ return p, name
170
+
171
+ linux_names = [
172
+ ("google-chrome-stable", "Google Chrome"),
173
+ ("google-chrome", "Google Chrome"),
174
+ ("brave-browser", "Brave Browser"),
175
+ ("brave", "Brave Browser"),
176
+ ("chromium", "Chromium"),
177
+ ("chromium-browser", "Chromium"),
178
+ ("msedge", "Microsoft Edge"),
179
+ ("opera", "Opera"),
180
+ ("vivaldi", "Vivaldi"),
181
+ ]
182
+ for binary_name, friendly_name in linux_names:
183
+ p = shutil.which(binary_name)
184
+ if p and "WindowsApps" not in p and os.path.isfile(p):
185
+ return p, friendly_name
186
+
187
+ return None, None