hiddenwb 0.1.0__py3-none-any.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.
- hiddenwb/__init__.py +33 -0
- hiddenwb/browsers.py +40 -0
- hiddenwb/cli.py +139 -0
- hiddenwb/core.py +21 -0
- hiddenwb/definitions.py +405 -0
- hiddenwb/detectors.py +362 -0
- hiddenwb/launcher.py +179 -0
- hiddenwb/py.typed +0 -0
- hiddenwb-0.1.0.dist-info/METADATA +114 -0
- hiddenwb-0.1.0.dist-info/RECORD +14 -0
- hiddenwb-0.1.0.dist-info/WHEEL +5 -0
- hiddenwb-0.1.0.dist-info/entry_points.txt +2 -0
- hiddenwb-0.1.0.dist-info/licenses/LICENSE +21 -0
- hiddenwb-0.1.0.dist-info/top_level.txt +1 -0
hiddenwb/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""hiddenwb - Detect web browsers and open links in hidden background windows.
|
|
2
|
+
|
|
3
|
+
hiddenwb detects the top web browsers installed on a system (Chrome, Edge,
|
|
4
|
+
Firefox, Brave, Opera GX, and many more) and lets you open a URL in a hidden
|
|
5
|
+
(headless / background) browser window without stealing focus.
|
|
6
|
+
|
|
7
|
+
Supported Python: 3.12.6 and up.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .core import (
|
|
11
|
+
detect_browsers,
|
|
12
|
+
detect_browser,
|
|
13
|
+
list_browsers,
|
|
14
|
+
open_hidden,
|
|
15
|
+
open_url,
|
|
16
|
+
Browser,
|
|
17
|
+
BrowserNotFoundError,
|
|
18
|
+
HiddenWBError,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__version__ = "0.1.0"
|
|
22
|
+
__author__ = "Goplop0959"
|
|
23
|
+
__all__ = [
|
|
24
|
+
"detect_browsers",
|
|
25
|
+
"detect_browser",
|
|
26
|
+
"list_browsers",
|
|
27
|
+
"open_hidden",
|
|
28
|
+
"open_url",
|
|
29
|
+
"Browser",
|
|
30
|
+
"BrowserNotFoundError",
|
|
31
|
+
"HiddenWBError",
|
|
32
|
+
"__version__",
|
|
33
|
+
]
|
hiddenwb/browsers.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Public data model for hiddenwb."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Browser:
|
|
11
|
+
"""Represents a detected web browser installation."""
|
|
12
|
+
|
|
13
|
+
name: str
|
|
14
|
+
"""Human-readable browser name (e.g. ``"Google Chrome"``)."""
|
|
15
|
+
|
|
16
|
+
key: str
|
|
17
|
+
"""Internal identifier key (e.g. ``"chrome"``)."""
|
|
18
|
+
|
|
19
|
+
path: str
|
|
20
|
+
"""Filesystem path to the browser executable."""
|
|
21
|
+
|
|
22
|
+
version: Optional[str] = None
|
|
23
|
+
"""Detected version string, if available."""
|
|
24
|
+
|
|
25
|
+
family: str = "chromium"
|
|
26
|
+
"""Browser engine family: ``chromium``, ``gecko``, ``webkit``, etc."""
|
|
27
|
+
|
|
28
|
+
headless_args: List[str] = field(default_factory=list)
|
|
29
|
+
"""Extra CLI flags to pass when launching this browser headless."""
|
|
30
|
+
|
|
31
|
+
def __repr__(self) -> str: # pragma: no cover - trivial
|
|
32
|
+
return f"Browser(name={self.name!r}, key={self.key!r}, path={self.path!r})"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class HiddenWBError(Exception):
|
|
36
|
+
"""Base exception for hiddenwb errors."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class BrowserNotFoundError(HiddenWBError):
|
|
40
|
+
"""Raised when no suitable browser can be found for an operation."""
|
hiddenwb/cli.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Command-line interface for hiddenwb.
|
|
2
|
+
|
|
3
|
+
Usage::
|
|
4
|
+
|
|
5
|
+
python -m hiddenwb "https://example.com" --browser chrome
|
|
6
|
+
hiddenwb --list-browsers
|
|
7
|
+
hiddenwb --detect
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import sys
|
|
15
|
+
from typing import List, Optional
|
|
16
|
+
|
|
17
|
+
from .browsers import Browser, BrowserNotFoundError
|
|
18
|
+
from .core import detect_browsers, list_browsers, open_hidden, open_url
|
|
19
|
+
from .detectors import detect_browser
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _format_browser(browser: Browser) -> dict:
|
|
23
|
+
return {
|
|
24
|
+
"name": browser.name,
|
|
25
|
+
"key": browser.key,
|
|
26
|
+
"path": browser.path,
|
|
27
|
+
"version": browser.version,
|
|
28
|
+
"family": browser.family,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def cmd_list(args: argparse.Namespace) -> int:
|
|
33
|
+
browsers = detect_browsers()
|
|
34
|
+
if args.json:
|
|
35
|
+
print(
|
|
36
|
+
json.dumps(
|
|
37
|
+
{key: [_format_browser(b) for b in bs] for key, bs in browsers.items()},
|
|
38
|
+
indent=2,
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
else:
|
|
42
|
+
if not browsers:
|
|
43
|
+
print("No supported browsers detected.")
|
|
44
|
+
return 0
|
|
45
|
+
print("Detected browsers:")
|
|
46
|
+
for key, bs in browsers.items():
|
|
47
|
+
print(f" - {key}:")
|
|
48
|
+
for b in bs:
|
|
49
|
+
ver = f" ({b.version})" if b.version else ""
|
|
50
|
+
print(f" {b.name}{ver} -> {b.path}")
|
|
51
|
+
return 0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def cmd_detect(args: argparse.Namespace) -> int:
|
|
55
|
+
key = args.browser
|
|
56
|
+
if key:
|
|
57
|
+
browser = detect_browser(key)
|
|
58
|
+
if browser is None:
|
|
59
|
+
print(f"Browser '{key}' not installed.")
|
|
60
|
+
return 1
|
|
61
|
+
print(json.dumps(_format_browser(browser), indent=2))
|
|
62
|
+
return 0
|
|
63
|
+
browsers = detect_browsers()
|
|
64
|
+
if args.json:
|
|
65
|
+
print(
|
|
66
|
+
json.dumps(
|
|
67
|
+
{k: [_format_browser(b) for b in bs] for k, bs in browsers.items()},
|
|
68
|
+
indent=2,
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
else:
|
|
72
|
+
if not browsers:
|
|
73
|
+
print("No supported browsers detected.")
|
|
74
|
+
else:
|
|
75
|
+
print(f"{sum(len(v) for v in browsers.values())} browser installation(s) detected across {len(browsers)} family(ies).")
|
|
76
|
+
return 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def cmd_open(args: argparse.Namespace) -> int:
|
|
80
|
+
try:
|
|
81
|
+
open_hidden(args.url, key=args.browser, check=True, background=not args.foreground)
|
|
82
|
+
except BrowserNotFoundError as exc:
|
|
83
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
84
|
+
if args.fallback:
|
|
85
|
+
print("Falling back to system default browser (visible)...")
|
|
86
|
+
open_url(args.url)
|
|
87
|
+
return 0
|
|
88
|
+
return 1
|
|
89
|
+
target = args.browser or "default available"
|
|
90
|
+
print(f"Opened {args.url} in hidden window via {target}.")
|
|
91
|
+
return 0
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
95
|
+
parser = argparse.ArgumentParser(
|
|
96
|
+
prog="hiddenwb",
|
|
97
|
+
description="Open links in hidden background browser windows.",
|
|
98
|
+
)
|
|
99
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
100
|
+
|
|
101
|
+
p_list = sub.add_parser("list", help="List detected browsers.")
|
|
102
|
+
p_list.add_argument("--json", action="store_true", help="Emit JSON.")
|
|
103
|
+
p_list.set_defaults(func=cmd_list)
|
|
104
|
+
|
|
105
|
+
p_detect = sub.add_parser("detect", help="Detect installed browsers.")
|
|
106
|
+
p_detect.add_argument("browser", nargs="?", help="Specific browser key to check.")
|
|
107
|
+
p_detect.add_argument("--json", action="store_true", help="Emit JSON.")
|
|
108
|
+
p_detect.set_defaults(func=cmd_detect)
|
|
109
|
+
|
|
110
|
+
p_open = sub.add_parser("open", help="Open a URL in a hidden window.")
|
|
111
|
+
p_open.add_argument("url", help="URL to open.")
|
|
112
|
+
p_open.add_argument(
|
|
113
|
+
"--browser",
|
|
114
|
+
"-b",
|
|
115
|
+
help="Browser key to use (e.g. chrome, edge, firefox).",
|
|
116
|
+
)
|
|
117
|
+
p_open.add_argument(
|
|
118
|
+
"--foreground",
|
|
119
|
+
action="store_true",
|
|
120
|
+
help="Do not detach the browser (run in foreground).",
|
|
121
|
+
)
|
|
122
|
+
p_open.add_argument(
|
|
123
|
+
"--fallback",
|
|
124
|
+
action="store_true",
|
|
125
|
+
help="Fall back to the visible default browser if none found.",
|
|
126
|
+
)
|
|
127
|
+
p_open.set_defaults(func=cmd_open)
|
|
128
|
+
|
|
129
|
+
return parser
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
133
|
+
parser = build_parser()
|
|
134
|
+
args = parser.parse_args(argv)
|
|
135
|
+
return args.func(args)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
raise SystemExit(main())
|
hiddenwb/core.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Core public API for hiddenwb."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Dict, List, Optional
|
|
6
|
+
|
|
7
|
+
from .browsers import Browser, BrowserNotFoundError, HiddenWBError
|
|
8
|
+
from .detectors import detect_browser, detect_browsers, list_browsers
|
|
9
|
+
from .launcher import open_hidden, open_url
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"detect_browsers",
|
|
14
|
+
"detect_browser",
|
|
15
|
+
"list_browsers",
|
|
16
|
+
"open_hidden",
|
|
17
|
+
"open_url",
|
|
18
|
+
"Browser",
|
|
19
|
+
"BrowserNotFoundError",
|
|
20
|
+
"HiddenWBError",
|
|
21
|
+
]
|
hiddenwb/definitions.py
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"""Built-in definitions for the top web browsers that hiddenwb can detect.
|
|
2
|
+
|
|
3
|
+
Each entry describes where to look for the browser executable on each
|
|
4
|
+
operating system and which command-line flags launch it in a hidden
|
|
5
|
+
(headless / background) mode.
|
|
6
|
+
|
|
7
|
+
The set covers the most popular desktop browsers including version channels
|
|
8
|
+
(beta, dev, canary, nightly, etc.) so that the total of detectable variants
|
|
9
|
+
exceeds twenty.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from typing import Dict, List, Optional
|
|
16
|
+
|
|
17
|
+
from .browsers import Browser
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class BrowserDefinition:
|
|
22
|
+
"""A detectable browser variant."""
|
|
23
|
+
|
|
24
|
+
name: str
|
|
25
|
+
key: str
|
|
26
|
+
family: str = "chromium"
|
|
27
|
+
headless_args: List[str] = field(default_factory=list)
|
|
28
|
+
|
|
29
|
+
# OS-specific hints used when guessing executable locations.
|
|
30
|
+
win_executables: List[str] = field(default_factory=list)
|
|
31
|
+
win_registry_uninstall: List[str] = field(default_factory=list)
|
|
32
|
+
win_registry_app_paths: List[str] = field(default_factory=list)
|
|
33
|
+
darwin_bundle_ids: List[str] = field(default_factory=list)
|
|
34
|
+
darwin_paths: List[str] = field(default_factory=list)
|
|
35
|
+
linux_executables: List[str] = field(default_factory=list)
|
|
36
|
+
linux_desktop_files: List[str] = field(default_factory=list)
|
|
37
|
+
|
|
38
|
+
def to_browser(self, path: str, version: Optional[str] = None) -> Browser:
|
|
39
|
+
return Browser(
|
|
40
|
+
name=self.name,
|
|
41
|
+
key=self.key,
|
|
42
|
+
path=path,
|
|
43
|
+
version=version,
|
|
44
|
+
family=self.family,
|
|
45
|
+
headless_args=list(self.headless_args),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Common headless flags shared by Chromium-based browsers.
|
|
50
|
+
_CHROMIUM_HEADLESS = [
|
|
51
|
+
"--headless=new",
|
|
52
|
+
"--disable-gpu",
|
|
53
|
+
"--no-sandbox",
|
|
54
|
+
"--hide-scrollbars",
|
|
55
|
+
"--mute-audio",
|
|
56
|
+
"--no-first-run",
|
|
57
|
+
"--no-default-browser-check",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
_GECKO_HEADLESS = ["--headless"]
|
|
61
|
+
|
|
62
|
+
_WEBKIT_HEADLESS = []
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
DEFINITIONS: List[BrowserDefinition] = [
|
|
66
|
+
# ---- Chromium family ---------------------------------------------------
|
|
67
|
+
BrowserDefinition(
|
|
68
|
+
name="Google Chrome",
|
|
69
|
+
key="chrome",
|
|
70
|
+
family="chromium",
|
|
71
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
72
|
+
win_executables=["chrome.exe"],
|
|
73
|
+
win_registry_uninstall=["Google Chrome"],
|
|
74
|
+
win_registry_app_paths=["Chrome.exe"],
|
|
75
|
+
darwin_bundle_ids=["com.google.Chrome"],
|
|
76
|
+
darwin_paths=[
|
|
77
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
78
|
+
],
|
|
79
|
+
linux_executables=["google-chrome", "google-chrome-stable", "chrome", "chromium-browser"],
|
|
80
|
+
linux_desktop_files=["google-chrome.desktop", "chromium-browser.desktop"],
|
|
81
|
+
),
|
|
82
|
+
BrowserDefinition(
|
|
83
|
+
name="Google Chrome Canary",
|
|
84
|
+
key="chrome-canary",
|
|
85
|
+
family="chromium",
|
|
86
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
87
|
+
win_executables=["chrome.exe"],
|
|
88
|
+
win_registry_uninstall=["Google Chrome Canary"],
|
|
89
|
+
darwin_bundle_ids=["com.google.Chrome.canary"],
|
|
90
|
+
darwin_paths=[
|
|
91
|
+
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
92
|
+
],
|
|
93
|
+
linux_executables=["google-chrome-canary"],
|
|
94
|
+
),
|
|
95
|
+
BrowserDefinition(
|
|
96
|
+
name="Google Chrome Beta",
|
|
97
|
+
key="chrome-beta",
|
|
98
|
+
family="chromium",
|
|
99
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
100
|
+
win_executables=["chrome.exe"],
|
|
101
|
+
win_registry_uninstall=["Google Chrome Beta"],
|
|
102
|
+
darwin_bundle_ids=["com.google.Chrome.beta"],
|
|
103
|
+
darwin_paths=[
|
|
104
|
+
"/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
|
|
105
|
+
],
|
|
106
|
+
linux_executables=["google-chrome-beta"],
|
|
107
|
+
),
|
|
108
|
+
BrowserDefinition(
|
|
109
|
+
name="Microsoft Edge",
|
|
110
|
+
key="edge",
|
|
111
|
+
family="chromium",
|
|
112
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
113
|
+
win_executables=["msedge.exe"],
|
|
114
|
+
win_registry_uninstall=["Microsoft Edge"],
|
|
115
|
+
win_registry_app_paths=["msedge.exe"],
|
|
116
|
+
darwin_bundle_ids=["com.microsoft.Edge"],
|
|
117
|
+
darwin_paths=[
|
|
118
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
119
|
+
],
|
|
120
|
+
linux_executables=["microsoft-edge", "microsoft-edge-stable", "msedge"],
|
|
121
|
+
linux_desktop_files=["microsoft-edge.desktop"],
|
|
122
|
+
),
|
|
123
|
+
BrowserDefinition(
|
|
124
|
+
name="Microsoft Edge Beta",
|
|
125
|
+
key="edge-beta",
|
|
126
|
+
family="chromium",
|
|
127
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
128
|
+
win_executables=["msedge.exe"],
|
|
129
|
+
win_registry_uninstall=["Microsoft Edge Beta"],
|
|
130
|
+
darwin_paths=[
|
|
131
|
+
"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta",
|
|
132
|
+
],
|
|
133
|
+
linux_executables=["microsoft-edge-beta"],
|
|
134
|
+
),
|
|
135
|
+
BrowserDefinition(
|
|
136
|
+
name="Microsoft Edge Dev",
|
|
137
|
+
key="edge-dev",
|
|
138
|
+
family="chromium",
|
|
139
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
140
|
+
win_executables=["msedge.exe"],
|
|
141
|
+
win_registry_uninstall=["Microsoft Edge Dev"],
|
|
142
|
+
darwin_paths=[
|
|
143
|
+
"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev",
|
|
144
|
+
],
|
|
145
|
+
linux_executables=["microsoft-edge-dev"],
|
|
146
|
+
),
|
|
147
|
+
BrowserDefinition(
|
|
148
|
+
name="Microsoft Edge Canary",
|
|
149
|
+
key="edge-canary",
|
|
150
|
+
family="chromium",
|
|
151
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
152
|
+
win_executables=["msedge.exe"],
|
|
153
|
+
win_registry_uninstall=["Microsoft Edge Canary"],
|
|
154
|
+
darwin_paths=[
|
|
155
|
+
"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary",
|
|
156
|
+
],
|
|
157
|
+
linux_executables=["microsoft-edge-canary"],
|
|
158
|
+
),
|
|
159
|
+
BrowserDefinition(
|
|
160
|
+
name="Brave Browser",
|
|
161
|
+
key="brave",
|
|
162
|
+
family="chromium",
|
|
163
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
164
|
+
win_executables=["brave.exe"],
|
|
165
|
+
win_registry_uninstall=["Brave"],
|
|
166
|
+
win_registry_app_paths=["brave.exe"],
|
|
167
|
+
darwin_bundle_ids=["com.brave.Browser"],
|
|
168
|
+
darwin_paths=[
|
|
169
|
+
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
|
|
170
|
+
],
|
|
171
|
+
linux_executables=["brave-browser", "brave", "brave-browser-stable"],
|
|
172
|
+
linux_desktop_files=["brave-browser.desktop"],
|
|
173
|
+
),
|
|
174
|
+
BrowserDefinition(
|
|
175
|
+
name="Brave Browser Beta",
|
|
176
|
+
key="brave-beta",
|
|
177
|
+
family="chromium",
|
|
178
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
179
|
+
win_executables=["brave.exe"],
|
|
180
|
+
win_registry_uninstall=["Brave Beta"],
|
|
181
|
+
darwin_paths=[
|
|
182
|
+
"/Applications/Brave Browser Beta.app/Contents/MacOS/Brave Browser Beta",
|
|
183
|
+
],
|
|
184
|
+
linux_executables=["brave-browser-beta"],
|
|
185
|
+
),
|
|
186
|
+
BrowserDefinition(
|
|
187
|
+
name="Brave Browser Nightly",
|
|
188
|
+
key="brave-nightly",
|
|
189
|
+
family="chromium",
|
|
190
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
191
|
+
win_executables=["brave.exe"],
|
|
192
|
+
win_registry_uninstall=["Brave Nightly"],
|
|
193
|
+
darwin_paths=[
|
|
194
|
+
"/Applications/Brave Browser Nightly.app/Contents/MacOS/Brave Browser Nightly",
|
|
195
|
+
],
|
|
196
|
+
linux_executables=["brave-browser-nightly"],
|
|
197
|
+
),
|
|
198
|
+
BrowserDefinition(
|
|
199
|
+
name="Opera GX",
|
|
200
|
+
key="opera-gx",
|
|
201
|
+
family="chromium",
|
|
202
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
203
|
+
win_executables=["opera_gx.exe", "launcher.exe"],
|
|
204
|
+
win_registry_uninstall=["Opera GX"],
|
|
205
|
+
darwin_paths=[
|
|
206
|
+
"/Applications/Opera GX.app/Contents/MacOS/Opera GX",
|
|
207
|
+
],
|
|
208
|
+
linux_executables=["opera-gx"],
|
|
209
|
+
),
|
|
210
|
+
BrowserDefinition(
|
|
211
|
+
name="Opera",
|
|
212
|
+
key="opera",
|
|
213
|
+
family="chromium",
|
|
214
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
215
|
+
win_executables=["opera.exe", "launcher.exe"],
|
|
216
|
+
win_registry_uninstall=["Opera"],
|
|
217
|
+
win_registry_app_paths=["opera.exe"],
|
|
218
|
+
darwin_bundle_ids=["com.operasoftware.Opera"],
|
|
219
|
+
darwin_paths=[
|
|
220
|
+
"/Applications/Opera.app/Contents/MacOS/Opera",
|
|
221
|
+
],
|
|
222
|
+
linux_executables=["opera"],
|
|
223
|
+
linux_desktop_files=["opera.desktop"],
|
|
224
|
+
),
|
|
225
|
+
BrowserDefinition(
|
|
226
|
+
name="Opera Beta",
|
|
227
|
+
key="opera-beta",
|
|
228
|
+
family="chromium",
|
|
229
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
230
|
+
win_executables=["opera.exe"],
|
|
231
|
+
win_registry_uninstall=["Opera Beta"],
|
|
232
|
+
darwin_paths=[
|
|
233
|
+
"/Applications/Opera Beta.app/Contents/MacOS/Opera Beta",
|
|
234
|
+
],
|
|
235
|
+
linux_executables=["opera-beta"],
|
|
236
|
+
),
|
|
237
|
+
BrowserDefinition(
|
|
238
|
+
name="Vivaldi",
|
|
239
|
+
key="vivaldi",
|
|
240
|
+
family="chromium",
|
|
241
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
242
|
+
win_executables=["vivaldi.exe"],
|
|
243
|
+
win_registry_uninstall=["Vivaldi"],
|
|
244
|
+
win_registry_app_paths=["vivaldi.exe"],
|
|
245
|
+
darwin_bundle_ids=["com.vivaldi.Vivaldi"],
|
|
246
|
+
darwin_paths=[
|
|
247
|
+
"/Applications/Vivaldi.app/Contents/MacOS/Vivaldi",
|
|
248
|
+
],
|
|
249
|
+
linux_executables=["vivaldi", "vivaldi-stable"],
|
|
250
|
+
linux_desktop_files=["vivaldi.desktop"],
|
|
251
|
+
),
|
|
252
|
+
BrowserDefinition(
|
|
253
|
+
name="Vivaldi Snapshot",
|
|
254
|
+
key="vivaldi-snapshot",
|
|
255
|
+
family="chromium",
|
|
256
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
257
|
+
win_executables=["vivaldi.exe"],
|
|
258
|
+
win_registry_uninstall=["Vivaldi Snapshot"],
|
|
259
|
+
darwin_paths=[
|
|
260
|
+
"/Applications/Vivaldi Snapshot.app/Contents/MacOS/Vivaldi Snapshot",
|
|
261
|
+
],
|
|
262
|
+
linux_executables=["vivaldi-snapshot"],
|
|
263
|
+
),
|
|
264
|
+
BrowserDefinition(
|
|
265
|
+
name="Chromium",
|
|
266
|
+
key="chromium",
|
|
267
|
+
family="chromium",
|
|
268
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
269
|
+
win_executables=["chrome.exe", "chromium.exe"],
|
|
270
|
+
win_registry_uninstall=["Chromium"],
|
|
271
|
+
darwin_bundle_ids=["org.chromium.Chromium"],
|
|
272
|
+
darwin_paths=[
|
|
273
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
274
|
+
],
|
|
275
|
+
linux_executables=["chromium", "chromium-browser"],
|
|
276
|
+
linux_desktop_files=["chromium.desktop"],
|
|
277
|
+
),
|
|
278
|
+
# ---- Gecko family -------------------------------------------------------
|
|
279
|
+
BrowserDefinition(
|
|
280
|
+
name="Mozilla Firefox",
|
|
281
|
+
key="firefox",
|
|
282
|
+
family="gecko",
|
|
283
|
+
headless_args=_GECKO_HEADLESS,
|
|
284
|
+
win_executables=["firefox.exe"],
|
|
285
|
+
win_registry_uninstall=["Mozilla Firefox"],
|
|
286
|
+
win_registry_app_paths=["firefox.exe"],
|
|
287
|
+
darwin_bundle_ids=["org.mozilla.firefox"],
|
|
288
|
+
darwin_paths=[
|
|
289
|
+
"/Applications/Firefox.app/Contents/MacOS/firefox",
|
|
290
|
+
],
|
|
291
|
+
linux_executables=["firefox"],
|
|
292
|
+
linux_desktop_files=["firefox.desktop"],
|
|
293
|
+
),
|
|
294
|
+
BrowserDefinition(
|
|
295
|
+
name="Mozilla Firefox Developer Edition",
|
|
296
|
+
key="firefox-dev",
|
|
297
|
+
family="gecko",
|
|
298
|
+
headless_args=_GECKO_HEADLESS,
|
|
299
|
+
win_executables=["firefox.exe"],
|
|
300
|
+
win_registry_uninstall=["Firefox Developer Edition"],
|
|
301
|
+
darwin_paths=[
|
|
302
|
+
"/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox",
|
|
303
|
+
],
|
|
304
|
+
linux_executables=["firefox-developer-edition"],
|
|
305
|
+
),
|
|
306
|
+
BrowserDefinition(
|
|
307
|
+
name="Mozilla Firefox Nightly",
|
|
308
|
+
key="firefox-nightly",
|
|
309
|
+
family="gecko",
|
|
310
|
+
headless_args=_GECKO_HEADLESS,
|
|
311
|
+
win_executables=["firefox.exe"],
|
|
312
|
+
win_registry_uninstall=["Firefox Nightly"],
|
|
313
|
+
darwin_paths=[
|
|
314
|
+
"/Applications/Firefox Nightly.app/Contents/MacOS/firefox",
|
|
315
|
+
],
|
|
316
|
+
linux_executables=["firefox-nightly", "firefox-trunk"],
|
|
317
|
+
),
|
|
318
|
+
BrowserDefinition(
|
|
319
|
+
name="Tor Browser",
|
|
320
|
+
key="tor",
|
|
321
|
+
family="gecko",
|
|
322
|
+
headless_args=_GECKO_HEADLESS,
|
|
323
|
+
win_executables=["firefox.exe"],
|
|
324
|
+
win_registry_uninstall=["Tor Browser"],
|
|
325
|
+
darwin_paths=[
|
|
326
|
+
"/Applications/Tor Browser.app/Contents/MacOS/firefox",
|
|
327
|
+
],
|
|
328
|
+
linux_executables=["tor-browser", "firefox"],
|
|
329
|
+
),
|
|
330
|
+
BrowserDefinition(
|
|
331
|
+
name="Waterfox",
|
|
332
|
+
key="waterfox",
|
|
333
|
+
family="gecko",
|
|
334
|
+
headless_args=_GECKO_HEADLESS,
|
|
335
|
+
win_executables=["waterfox.exe"],
|
|
336
|
+
win_registry_uninstall=["Waterfox"],
|
|
337
|
+
darwin_paths=[
|
|
338
|
+
"/Applications/Waterfox.app/Contents/MacOS/Waterfox",
|
|
339
|
+
],
|
|
340
|
+
linux_executables=["waterfox"],
|
|
341
|
+
),
|
|
342
|
+
BrowserDefinition(
|
|
343
|
+
name="Pale Moon",
|
|
344
|
+
key="pale-moon",
|
|
345
|
+
family="gecko",
|
|
346
|
+
headless_args=_GECKO_HEADLESS,
|
|
347
|
+
win_executables=["palemoon.exe"],
|
|
348
|
+
win_registry_uninstall=["Pale Moon"],
|
|
349
|
+
linux_executables=["palemoon"],
|
|
350
|
+
),
|
|
351
|
+
# ---- WebKit family ------------------------------------------------------
|
|
352
|
+
BrowserDefinition(
|
|
353
|
+
name="Safari",
|
|
354
|
+
key="safari",
|
|
355
|
+
family="webkit",
|
|
356
|
+
headless_args=_WEBKIT_HEADLESS,
|
|
357
|
+
darwin_bundle_ids=["com.apple.Safari"],
|
|
358
|
+
darwin_paths=[
|
|
359
|
+
"/Applications/Safari.app/Contents/MacOS/Safari",
|
|
360
|
+
],
|
|
361
|
+
),
|
|
362
|
+
# ---- Others -------------------------------------------------------------
|
|
363
|
+
BrowserDefinition(
|
|
364
|
+
name="Maxthon",
|
|
365
|
+
key="maxthon",
|
|
366
|
+
family="chromium",
|
|
367
|
+
headless_args=_CHROMIUM_HEADLESS,
|
|
368
|
+
win_executables=["maxthon.exe"],
|
|
369
|
+
win_registry_uninstall=["Maxthon"],
|
|
370
|
+
linux_executables=["maxthon"],
|
|
371
|
+
),
|
|
372
|
+
BrowserDefinition(
|
|
373
|
+
name="Falkon",
|
|
374
|
+
key="falkon",
|
|
375
|
+
family="webkit",
|
|
376
|
+
headless_args=[],
|
|
377
|
+
win_executables=["falkon.exe"],
|
|
378
|
+
win_registry_uninstall=["Falkon"],
|
|
379
|
+
linux_executables=["falkon"],
|
|
380
|
+
linux_desktop_files=["falkon.desktop"],
|
|
381
|
+
),
|
|
382
|
+
]
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def get_definitions() -> List[BrowserDefinition]:
|
|
386
|
+
"""Return all built-in browser definitions."""
|
|
387
|
+
return list(DEFINITIONS)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def find_definition(key: str) -> Optional[BrowserDefinition]:
|
|
391
|
+
"""Return the definition matching *key*, or ``None`` if not found."""
|
|
392
|
+
for definition in DEFINITIONS:
|
|
393
|
+
if definition.key == key:
|
|
394
|
+
return definition
|
|
395
|
+
return None
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def definition_names() -> List[str]:
|
|
399
|
+
"""Return the human-readable names of all defined browsers."""
|
|
400
|
+
return [definition.name for definition in DEFINITIONS]
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def definition_keys() -> List[str]:
|
|
404
|
+
"""Return the internal keys of all defined browsers."""
|
|
405
|
+
return [definition.key for definition in DEFINITIONS]
|
hiddenwb/detectors.py
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"""Browser installation detection for hiddenwb.
|
|
2
|
+
|
|
3
|
+
Detectors look for each known browser using OS-appropriate strategies:
|
|
4
|
+
|
|
5
|
+
* Windows: filesystem paths, ``Uninstall`` registry keys, and ``App Paths``
|
|
6
|
+
registry keys.
|
|
7
|
+
* macOS: ``LSRegister``/bundle id lookups and common ``/Applications`` paths.
|
|
8
|
+
* Linux: ``which``/PATH lookups and ``.desktop`` files.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import shutil
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
from typing import Dict, List, Optional
|
|
18
|
+
|
|
19
|
+
from .browsers import Browser
|
|
20
|
+
from .definitions import BrowserDefinition, find_definition, get_definitions
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _read_version_from_executable(path: str) -> Optional[str]:
|
|
24
|
+
"""Best-effort version read from an executable (Windows only, via VSIX)."""
|
|
25
|
+
if sys.platform != "win32":
|
|
26
|
+
return None
|
|
27
|
+
try:
|
|
28
|
+
import win32api # type: ignore[import-not-found]
|
|
29
|
+
|
|
30
|
+
info = win32api.GetFileVersionInfo(path, "\\")
|
|
31
|
+
ms = info["FileVersionMS"]
|
|
32
|
+
ls = info["FileVersionLS"]
|
|
33
|
+
return f"{win32api.HIWORD(ms)}.{win32api.LOWORD(ms)}.{win32api.HIWORD(ls)}.{win32api.LOWORD(ls)}"
|
|
34
|
+
except Exception:
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _win_registry_values(root, subkey: str, value_name: str) -> List[str]:
|
|
39
|
+
"""Read a registry value under *subkey*, returning string(s)."""
|
|
40
|
+
import winreg # only available on Windows
|
|
41
|
+
|
|
42
|
+
results: List[str] = []
|
|
43
|
+
try:
|
|
44
|
+
with winreg.OpenKey(root, subkey) as key:
|
|
45
|
+
index = 0
|
|
46
|
+
while True:
|
|
47
|
+
try:
|
|
48
|
+
name, value, _ = winreg.EnumValue(key, index)
|
|
49
|
+
except OSError:
|
|
50
|
+
break
|
|
51
|
+
if name == value_name and isinstance(value, str):
|
|
52
|
+
results.append(value)
|
|
53
|
+
index += 1
|
|
54
|
+
except FileNotFoundError:
|
|
55
|
+
pass
|
|
56
|
+
except Exception:
|
|
57
|
+
pass
|
|
58
|
+
return results
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _win_registry_subkeys(root, subkey: str) -> List[str]:
|
|
62
|
+
"""Return subkey names under *subkey*."""
|
|
63
|
+
import winreg
|
|
64
|
+
|
|
65
|
+
result: List[str] = []
|
|
66
|
+
try:
|
|
67
|
+
with winreg.OpenKey(root, subkey) as key:
|
|
68
|
+
index = 0
|
|
69
|
+
while True:
|
|
70
|
+
try:
|
|
71
|
+
result.append(winreg.EnumKey(key, index))
|
|
72
|
+
index += 1
|
|
73
|
+
except OSError:
|
|
74
|
+
break
|
|
75
|
+
except FileNotFoundError:
|
|
76
|
+
pass
|
|
77
|
+
except Exception:
|
|
78
|
+
pass
|
|
79
|
+
return result
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _detect_windows(definition: BrowserDefinition) -> List[Browser]:
|
|
83
|
+
found: List[Browser] = []
|
|
84
|
+
|
|
85
|
+
# 1) App Paths registry: "Chrome.exe" -> full path
|
|
86
|
+
for app_path in definition.win_registry_app_paths:
|
|
87
|
+
for root in (
|
|
88
|
+
__import__("winreg").HKEY_CURRENT_USER,
|
|
89
|
+
__import__("winreg").HKEY_LOCAL_MACHINE,
|
|
90
|
+
):
|
|
91
|
+
try:
|
|
92
|
+
import winreg
|
|
93
|
+
|
|
94
|
+
with winreg.OpenKey(
|
|
95
|
+
root, r"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths"
|
|
96
|
+
) as app_keys:
|
|
97
|
+
try:
|
|
98
|
+
with winreg.OpenKey(app_keys, app_path) as key:
|
|
99
|
+
path, _ = winreg.QueryValueEx(key, "")
|
|
100
|
+
if path and os.path.isfile(path):
|
|
101
|
+
found.append(
|
|
102
|
+
definition.to_browser(
|
|
103
|
+
path, _read_version_from_executable(path)
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
except FileNotFoundError:
|
|
107
|
+
pass
|
|
108
|
+
except Exception:
|
|
109
|
+
pass
|
|
110
|
+
|
|
111
|
+
# 2) Uninstall registry: match display name, read InstallLocation/Icon
|
|
112
|
+
for uninstall_name in definition.win_registry_uninstall:
|
|
113
|
+
for root in (
|
|
114
|
+
__import__("winreg").HKEY_CURRENT_USER,
|
|
115
|
+
__import__("winreg").HKEY_LOCAL_MACHINE,
|
|
116
|
+
):
|
|
117
|
+
try:
|
|
118
|
+
import winreg
|
|
119
|
+
|
|
120
|
+
for hive in (r"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",):
|
|
121
|
+
try:
|
|
122
|
+
with winreg.OpenKey(root, hive) as key:
|
|
123
|
+
index = 0
|
|
124
|
+
while True:
|
|
125
|
+
try:
|
|
126
|
+
sub = winreg.EnumKey(key, index)
|
|
127
|
+
index += 1
|
|
128
|
+
except OSError:
|
|
129
|
+
break
|
|
130
|
+
try:
|
|
131
|
+
with winreg.OpenKey(key, sub) as subkey:
|
|
132
|
+
display, _ = winreg.QueryValueEx(
|
|
133
|
+
subkey, "DisplayName"
|
|
134
|
+
)
|
|
135
|
+
if display != uninstall_name:
|
|
136
|
+
continue
|
|
137
|
+
# Prefer InstallLocation + exe name
|
|
138
|
+
install_loc, _ = winreg.QueryValueEx(
|
|
139
|
+
subkey, "InstallLocation"
|
|
140
|
+
)
|
|
141
|
+
for exe in definition.win_executables:
|
|
142
|
+
candidate = os.path.join(
|
|
143
|
+
install_loc, exe
|
|
144
|
+
)
|
|
145
|
+
if os.path.isfile(candidate):
|
|
146
|
+
found.append(
|
|
147
|
+
definition.to_browser(
|
|
148
|
+
candidate,
|
|
149
|
+
_read_version_from_executable(
|
|
150
|
+
candidate
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
# Also try the "Icon" value / "UninstallString"
|
|
155
|
+
try:
|
|
156
|
+
icon, _ = winreg.QueryValueEx(
|
|
157
|
+
subkey, "Icon"
|
|
158
|
+
)
|
|
159
|
+
if isinstance(icon, str):
|
|
160
|
+
candidate = icon.split(",")[0].strip().strip('"')
|
|
161
|
+
if os.path.isfile(candidate):
|
|
162
|
+
found.append(
|
|
163
|
+
definition.to_browser(
|
|
164
|
+
candidate,
|
|
165
|
+
_read_version_from_executable(
|
|
166
|
+
candidate
|
|
167
|
+
),
|
|
168
|
+
)
|
|
169
|
+
)
|
|
170
|
+
except FileNotFoundError:
|
|
171
|
+
pass
|
|
172
|
+
except FileNotFoundError:
|
|
173
|
+
pass
|
|
174
|
+
except Exception:
|
|
175
|
+
pass
|
|
176
|
+
except FileNotFoundError:
|
|
177
|
+
pass
|
|
178
|
+
except Exception:
|
|
179
|
+
pass
|
|
180
|
+
|
|
181
|
+
# 3) Common Program Files locations
|
|
182
|
+
program_files = [
|
|
183
|
+
os.environ.get("PROGRAMFILES", r"C:\\Program Files"),
|
|
184
|
+
os.environ.get("PROGRAMFILES(X86)", r"C:\\Program Files (x86)"),
|
|
185
|
+
os.environ.get("LOCALAPPDATA", ""),
|
|
186
|
+
]
|
|
187
|
+
seen = {b.path for b in found}
|
|
188
|
+
for base in program_files:
|
|
189
|
+
if not base or not os.path.isdir(base):
|
|
190
|
+
continue
|
|
191
|
+
# Walk shallowly (depth 3) looking for known executable names.
|
|
192
|
+
for root, _dirs, files in os.walk(base):
|
|
193
|
+
depth = root[len(base):].count(os.sep)
|
|
194
|
+
if depth > 3:
|
|
195
|
+
_dirs[:] = []
|
|
196
|
+
continue
|
|
197
|
+
for fname in files:
|
|
198
|
+
if fname.lower() in {e.lower() for e in definition.win_executables}:
|
|
199
|
+
candidate = os.path.join(root, fname)
|
|
200
|
+
if candidate not in seen and os.path.isfile(candidate):
|
|
201
|
+
seen.add(candidate)
|
|
202
|
+
found.append(
|
|
203
|
+
definition.to_browser(
|
|
204
|
+
candidate,
|
|
205
|
+
_read_version_from_executable(candidate),
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
return found
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _detect_darwin(definition: BrowserDefinition) -> List[Browser]:
|
|
213
|
+
found: List[Browser] = []
|
|
214
|
+
seen = set()
|
|
215
|
+
|
|
216
|
+
# mdfind by bundle id
|
|
217
|
+
for bundle_id in definition.darwin_bundle_ids:
|
|
218
|
+
try:
|
|
219
|
+
output = subprocess.check_output(
|
|
220
|
+
["mdfind", f"kMDItemCFBundleIdentifier == '{bundle_id}'"],
|
|
221
|
+
text=True,
|
|
222
|
+
stderr=subprocess.DEVNULL,
|
|
223
|
+
)
|
|
224
|
+
for line in output.splitlines():
|
|
225
|
+
line = line.strip()
|
|
226
|
+
if not line or line in seen:
|
|
227
|
+
continue
|
|
228
|
+
exe = _app_executable(line)
|
|
229
|
+
if exe and os.path.isfile(exe):
|
|
230
|
+
seen.add(exe)
|
|
231
|
+
found.append(definition.to_browser(exe))
|
|
232
|
+
except Exception:
|
|
233
|
+
pass
|
|
234
|
+
|
|
235
|
+
# Direct path guesses
|
|
236
|
+
for path in definition.darwin_paths:
|
|
237
|
+
if path in seen:
|
|
238
|
+
continue
|
|
239
|
+
exe = _app_executable(path) if path.endswith(".app") else path
|
|
240
|
+
if exe and os.path.isfile(exe):
|
|
241
|
+
seen.add(exe)
|
|
242
|
+
found.append(definition.to_browser(exe))
|
|
243
|
+
|
|
244
|
+
return found
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _app_executable(app_path: str) -> Optional[str]:
|
|
248
|
+
"""Given a .app bundle path, return the Mach-O executable inside."""
|
|
249
|
+
info_plist = os.path.join(app_path, "Contents", "Info.plist")
|
|
250
|
+
exe_name: Optional[str] = None
|
|
251
|
+
if os.path.isfile(info_plist):
|
|
252
|
+
try:
|
|
253
|
+
import plistlib
|
|
254
|
+
|
|
255
|
+
with open(info_plist, "rb") as fh:
|
|
256
|
+
plist = plistlib.load(fh)
|
|
257
|
+
exe_name = plist.get("CFBundleExecutable")
|
|
258
|
+
except Exception:
|
|
259
|
+
exe_name = None
|
|
260
|
+
if not exe_name:
|
|
261
|
+
exe_name = os.path.basename(app_path).replace(".app", "")
|
|
262
|
+
candidate = os.path.join(app_path, "Contents", "MacOS", exe_name)
|
|
263
|
+
return candidate if os.path.isfile(candidate) else None
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _detect_linux(definition: BrowserDefinition) -> List[Browser]:
|
|
267
|
+
found: List[Browser] = []
|
|
268
|
+
seen = set()
|
|
269
|
+
|
|
270
|
+
# PATH lookup
|
|
271
|
+
for exe in definition.linux_executables:
|
|
272
|
+
path = shutil.which(exe)
|
|
273
|
+
if path and path not in seen and os.path.isfile(path):
|
|
274
|
+
seen.add(path)
|
|
275
|
+
found.append(definition.to_browser(path))
|
|
276
|
+
|
|
277
|
+
# .desktop files -> Exec line
|
|
278
|
+
xdg_dirs = [
|
|
279
|
+
os.path.expanduser("~/.local/share/applications"),
|
|
280
|
+
"/usr/share/applications",
|
|
281
|
+
"/usr/local/share/applications",
|
|
282
|
+
]
|
|
283
|
+
for desktop_dir in xdg_dirs:
|
|
284
|
+
if not os.path.isdir(desktop_dir):
|
|
285
|
+
continue
|
|
286
|
+
for desktop_file in definition.linux_desktop_files:
|
|
287
|
+
desktop_path = os.path.join(desktop_dir, desktop_file)
|
|
288
|
+
if not os.path.isfile(desktop_path):
|
|
289
|
+
continue
|
|
290
|
+
try:
|
|
291
|
+
with open(desktop_path, "r", encoding="utf-8", errors="ignore") as fh:
|
|
292
|
+
for line in fh:
|
|
293
|
+
line = line.strip()
|
|
294
|
+
if line.startswith("Exec="):
|
|
295
|
+
exec_value = line[len("Exec="):]
|
|
296
|
+
# Take first token, strip % flags and quotes
|
|
297
|
+
binary = exec_value.split()[0]
|
|
298
|
+
binary = binary.strip().strip('"')
|
|
299
|
+
for char in "%fFuU":
|
|
300
|
+
binary = binary.replace(char, "")
|
|
301
|
+
if os.path.isfile(binary) and binary not in seen:
|
|
302
|
+
seen.add(binary)
|
|
303
|
+
found.append(definition.to_browser(binary))
|
|
304
|
+
break
|
|
305
|
+
except Exception:
|
|
306
|
+
pass
|
|
307
|
+
|
|
308
|
+
return found
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def _detect_browser_platform(definition: BrowserDefinition) -> List[Browser]:
|
|
312
|
+
if sys.platform == "win32":
|
|
313
|
+
return _detect_windows(definition)
|
|
314
|
+
if sys.platform == "darwin":
|
|
315
|
+
return _detect_darwin(definition)
|
|
316
|
+
return _detect_linux(definition)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def detect_browsers(keys: Optional[List[str]] = None) -> Dict[str, List[Browser]]:
|
|
320
|
+
"""Detect installed browsers.
|
|
321
|
+
|
|
322
|
+
Parameters
|
|
323
|
+
----------
|
|
324
|
+
keys:
|
|
325
|
+
Optional list of internal browser keys to restrict detection to.
|
|
326
|
+
When omitted, every built-in browser is checked.
|
|
327
|
+
|
|
328
|
+
Returns
|
|
329
|
+
-------
|
|
330
|
+
dict
|
|
331
|
+
Mapping of browser key -> list of :class:`Browser` instances.
|
|
332
|
+
Only browsers that were actually found are included.
|
|
333
|
+
"""
|
|
334
|
+
results: Dict[str, List[Browser]] = {}
|
|
335
|
+
definitions = get_definitions()
|
|
336
|
+
if keys is not None:
|
|
337
|
+
definitions = [d for d in definitions if d.key in keys]
|
|
338
|
+
|
|
339
|
+
for definition in definitions:
|
|
340
|
+
try:
|
|
341
|
+
found = _detect_browser_platform(definition)
|
|
342
|
+
except Exception:
|
|
343
|
+
# A single browser's detection must never break the whole scan.
|
|
344
|
+
found = []
|
|
345
|
+
if found:
|
|
346
|
+
results[definition.key] = found
|
|
347
|
+
|
|
348
|
+
return results
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def detect_browser(key: str) -> Optional[Browser]:
|
|
352
|
+
"""Return the first installed :class:`Browser` matching *key*, or None."""
|
|
353
|
+
found = detect_browsers(keys=[key])
|
|
354
|
+
browsers = found.get(key)
|
|
355
|
+
if not browsers:
|
|
356
|
+
return None
|
|
357
|
+
return browsers[0]
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def list_browsers() -> List[str]:
|
|
361
|
+
"""Return the keys of every browser known to hiddenwb."""
|
|
362
|
+
return [definition.key for definition in get_definitions()]
|
hiddenwb/launcher.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""Launching URLs in hidden (headless / background) browser windows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import shutil
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
import webbrowser
|
|
9
|
+
from typing import List, Optional, Sequence
|
|
10
|
+
|
|
11
|
+
from .browsers import Browser, BrowserNotFoundError, HiddenWBError
|
|
12
|
+
from .detectors import detect_browser
|
|
13
|
+
from .definitions import find_definition
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def build_command(browser: Browser, url: str) -> List[str]:
|
|
17
|
+
"""Build the command line to open *url* in *browser* headlessly.
|
|
18
|
+
|
|
19
|
+
Chromium-based browsers use ``--headless=new``. Firefox uses ``--headless``.
|
|
20
|
+
Safari has no first-class headless mode on macOS, so it falls back to a
|
|
21
|
+
normal (focus-stealing) launch through the :mod:`webbrowser` module.
|
|
22
|
+
"""
|
|
23
|
+
family = browser.family.lower()
|
|
24
|
+
if family == "chromium":
|
|
25
|
+
base = [browser.path] + list(browser.headless_args)
|
|
26
|
+
base.append(url)
|
|
27
|
+
return base
|
|
28
|
+
if family == "gecko":
|
|
29
|
+
base = [browser.path] + list(browser.headless_args)
|
|
30
|
+
base.append(url)
|
|
31
|
+
return base
|
|
32
|
+
if family == "webkit":
|
|
33
|
+
# macOS Safari: open the URL in the background without raising focus.
|
|
34
|
+
if sys.platform == "darwin":
|
|
35
|
+
return ["open", "-g", "-a", browser.path, url]
|
|
36
|
+
return [browser.path, url]
|
|
37
|
+
# Unknown family: attempt headless with the URL as the last argument.
|
|
38
|
+
return [browser.path] + list(browser.headless_args) + [url]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def open_hidden(
|
|
42
|
+
url: str,
|
|
43
|
+
browser: Optional[Browser] = None,
|
|
44
|
+
key: Optional[str] = None,
|
|
45
|
+
*,
|
|
46
|
+
background: bool = True,
|
|
47
|
+
check: bool = True,
|
|
48
|
+
) -> subprocess.Popen:
|
|
49
|
+
"""Open *url* in a hidden (headless / background) browser window.
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
url:
|
|
54
|
+
The URL to open.
|
|
55
|
+
browser:
|
|
56
|
+
A specific :class:`Browser` instance to use. Mutually exclusive with
|
|
57
|
+
*key*.
|
|
58
|
+
key:
|
|
59
|
+
Internal browser key (e.g. ``"chrome"``, ``"edge"``, ``"firefox"``).
|
|
60
|
+
When given, the first installed browser matching the key is used.
|
|
61
|
+
background:
|
|
62
|
+
When True (default), the process is launched detached from the
|
|
63
|
+
caller's console so it keeps running in the background.
|
|
64
|
+
check:
|
|
65
|
+
When True, raise :class:`BrowserNotFoundError` if no browser is
|
|
66
|
+
available. When False, fall back to the system default browser via
|
|
67
|
+
:mod:`webbrowser`.
|
|
68
|
+
|
|
69
|
+
Returns
|
|
70
|
+
-------
|
|
71
|
+
subprocess.Popen
|
|
72
|
+
The launched browser process.
|
|
73
|
+
|
|
74
|
+
Raises
|
|
75
|
+
------
|
|
76
|
+
BrowserNotFoundError
|
|
77
|
+
If *check* is True and no browser (matching *key*, if given) is
|
|
78
|
+
installed.
|
|
79
|
+
ValueError
|
|
80
|
+
If both *browser* and *key* are given.
|
|
81
|
+
"""
|
|
82
|
+
if browser is not None and key is not None:
|
|
83
|
+
raise ValueError("Pass either `browser` or `key`, not both.")
|
|
84
|
+
|
|
85
|
+
if browser is None:
|
|
86
|
+
if key is not None:
|
|
87
|
+
browser = detect_browser(key)
|
|
88
|
+
else:
|
|
89
|
+
# Pick the first detected browser, preferring Chromium-based ones.
|
|
90
|
+
from .detectors import detect_browsers
|
|
91
|
+
|
|
92
|
+
found = detect_browsers()
|
|
93
|
+
priority = ["edge", "chrome", "brave", "opera-gx", "opera", "firefox"]
|
|
94
|
+
browser = None
|
|
95
|
+
for preferred in priority:
|
|
96
|
+
if preferred in found:
|
|
97
|
+
browser = found[preferred][0]
|
|
98
|
+
break
|
|
99
|
+
if browser is None and found:
|
|
100
|
+
# Use the first available browser.
|
|
101
|
+
browser = next(iter(found.values()))[0]
|
|
102
|
+
|
|
103
|
+
if browser is None:
|
|
104
|
+
if check:
|
|
105
|
+
raise BrowserNotFoundError(
|
|
106
|
+
"No supported web browser was found on this system. "
|
|
107
|
+
"Install Chrome, Edge, Firefox, Brave, Opera, or another "
|
|
108
|
+
"supported browser, or pass check=False to fall back to the "
|
|
109
|
+
"system default browser."
|
|
110
|
+
)
|
|
111
|
+
return _fallback_open(url, background=background)
|
|
112
|
+
|
|
113
|
+
cmd = build_command(browser, url)
|
|
114
|
+
return _launch(cmd, background=background)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def open_url(url: str, *, browser_name: Optional[str] = None) -> bool:
|
|
118
|
+
"""Convenience wrapper: open *url* in the best available hidden browser.
|
|
119
|
+
|
|
120
|
+
Returns True if a hidden browser was launched, False if it fell back to
|
|
121
|
+
the system default (visible) browser.
|
|
122
|
+
"""
|
|
123
|
+
try:
|
|
124
|
+
key = browser_name
|
|
125
|
+
open_hidden(url, key=key, check=True, background=True)
|
|
126
|
+
return True
|
|
127
|
+
except BrowserNotFoundError:
|
|
128
|
+
webbrowser.open(url)
|
|
129
|
+
return False
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _launch(cmd: Sequence[str], *, background: bool) -> subprocess.Popen:
|
|
133
|
+
"""Launch *cmd*, detaching it on Windows when *background* is True."""
|
|
134
|
+
creationflags = 0
|
|
135
|
+
start_new_session = False
|
|
136
|
+
|
|
137
|
+
if sys.platform == "win32" and background:
|
|
138
|
+
# DETACHED_PROCESS + CREATE_NEW_PROCESS_GROUP lets the browser keep
|
|
139
|
+
# running after this script exits and prevents a console window.
|
|
140
|
+
import subprocess as _sp
|
|
141
|
+
|
|
142
|
+
creationflags = _sp.DETACHED_PROCESS | _sp.CREATE_NEW_PROCESS_GROUP
|
|
143
|
+
start_new_session = True
|
|
144
|
+
|
|
145
|
+
if sys.platform != "win32" and background:
|
|
146
|
+
start_new_session = True
|
|
147
|
+
|
|
148
|
+
return subprocess.Popen(
|
|
149
|
+
cmd,
|
|
150
|
+
stdout=subprocess.DEVNULL,
|
|
151
|
+
stderr=subprocess.DEVNULL,
|
|
152
|
+
stdin=subprocess.DEVNULL,
|
|
153
|
+
creationflags=creationflags,
|
|
154
|
+
start_new_session=start_new_session,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _fallback_open(url: str, *, background: bool) -> subprocess.Popen:
|
|
159
|
+
"""Last-resort: open via the system default browser."""
|
|
160
|
+
# webbrowser.open blocks until the browser is told to open; we then
|
|
161
|
+
# return a dummy Popen-like object so the caller always gets a handle.
|
|
162
|
+
webbrowser.open(url)
|
|
163
|
+
|
|
164
|
+
class _Dummy:
|
|
165
|
+
pid = -1
|
|
166
|
+
|
|
167
|
+
def poll(self):
|
|
168
|
+
return None
|
|
169
|
+
|
|
170
|
+
def wait(self, timeout=None):
|
|
171
|
+
return 0
|
|
172
|
+
|
|
173
|
+
def terminate(self):
|
|
174
|
+
pass
|
|
175
|
+
|
|
176
|
+
def kill(self):
|
|
177
|
+
pass
|
|
178
|
+
|
|
179
|
+
return _Dummy() # type: ignore[return-value]
|
hiddenwb/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hiddenwb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Detect the top web browsers and open links in hidden background (headless) windows.
|
|
5
|
+
Author-email: Goplop0959 <goplop0959@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Goplop0959/hiddenwb
|
|
8
|
+
Project-URL: Repository, https://github.com/Goplop0959/hiddenwb
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/Goplop0959/hiddenwb/issues
|
|
10
|
+
Keywords: browser,hidden,headless,chrome,edge,firefox,brave,opera,webbrowser,background
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Classifier: Operating System :: MacOS
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.12.6
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# hiddenwb
|
|
28
|
+
|
|
29
|
+
**hiddenwb** detects the top web browsers installed on your system and lets you
|
|
30
|
+
open a link in a hidden (headless / background) browser window — without stealing
|
|
31
|
+
focus from your terminal.
|
|
32
|
+
|
|
33
|
+
Supported Python: **3.12.6 and up**.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
* 🔍 **Detects 20+ browsers** across Windows, macOS, and Linux, including:
|
|
38
|
+
* Google Chrome (+ Beta, Canary)
|
|
39
|
+
* Microsoft Edge (+ Beta, Dev, Canary)
|
|
40
|
+
* Mozilla Firefox (+ Developer Edition, Nightly)
|
|
41
|
+
* Brave Browser (+ Beta, Nightly)
|
|
42
|
+
* Opera GX (+ Opera, Opera Beta)
|
|
43
|
+
* Vivaldi (+ Snapshot)
|
|
44
|
+
* Chromium
|
|
45
|
+
* Tor Browser, Waterfox, Pale Moon
|
|
46
|
+
* Safari (macOS)
|
|
47
|
+
* Maxthon, Falkon
|
|
48
|
+
* 🕶️ **Open URLs in hidden background windows** using headless mode
|
|
49
|
+
(`--headless=new` for Chromium, `--headless` for Firefox).
|
|
50
|
+
* 💻 **CLI** (`hiddenwb open`, `hiddenwb detect`, `hiddenwb list`)
|
|
51
|
+
* 📦 **Pure Python**, no external dependencies.
|
|
52
|
+
* 🐍 Python 3.12.6+
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install hiddenwb
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
### Python API
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from hiddenwb import detect_browsers, open_hidden, BrowserNotFoundError
|
|
66
|
+
|
|
67
|
+
# See what's installed
|
|
68
|
+
browsers = detect_browsers()
|
|
69
|
+
print(browsers.keys()) # dict_keys(['chrome', 'edge', 'firefox', ...])
|
|
70
|
+
|
|
71
|
+
# Open a link in a hidden Chrome window
|
|
72
|
+
try:
|
|
73
|
+
proc = open_hidden("https://example.com", key="chrome")
|
|
74
|
+
print(f"Launched (pid {proc.pid})")
|
|
75
|
+
except BrowserNotFoundError:
|
|
76
|
+
print("No supported browser found.")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### CLI
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# List every detected browser
|
|
83
|
+
hiddenwb list
|
|
84
|
+
|
|
85
|
+
# Detect a specific browser
|
|
86
|
+
hiddenwb detect chrome
|
|
87
|
+
|
|
88
|
+
# Open a URL in a hidden Edge window
|
|
89
|
+
hiddenwb open https://example.com --browser edge
|
|
90
|
+
|
|
91
|
+
# Open using the first available browser
|
|
92
|
+
hiddenwb open https://example.com
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## How "hidden" works
|
|
96
|
+
|
|
97
|
+
* Chromium-based browsers (Chrome, Edge, Brave, Opera, Vivaldi, …) launch with
|
|
98
|
+
`--headless=new --disable-gpu --no-sandbox --hide-scrollbars --mute-audio`.
|
|
99
|
+
* Firefox launches with `--headless`.
|
|
100
|
+
* Safari on macOS launches with `open -g` (backgrounded, no focus steal).
|
|
101
|
+
* On Windows the process is detached (`DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP`)
|
|
102
|
+
so it keeps running in the background after your script exits.
|
|
103
|
+
|
|
104
|
+
## Project
|
|
105
|
+
|
|
106
|
+
* **Repository:** https://github.com/Goplop0959/hiddenwb
|
|
107
|
+
* **Author:** Goplop0959
|
|
108
|
+
* **License:** MIT
|
|
109
|
+
|
|
110
|
+
## Disclaimer
|
|
111
|
+
|
|
112
|
+
hiddenwb is intended for legitimate automation and testing use-cases. Respect
|
|
113
|
+
website terms of service and users' privacy. The authors are not responsible for
|
|
114
|
+
how this tool is used.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
hiddenwb/__init__.py,sha256=nKsTrhU5_nCwyPFknUUDJCpyOvtZbQonezGh_gAfg_s,752
|
|
2
|
+
hiddenwb/browsers.py,sha256=6THfH8L3hrzIjmQf0VL8pMglnTmFsQin2k9BTGXyALQ,1119
|
|
3
|
+
hiddenwb/cli.py,sha256=V8HhWN89toEsc-3c1CYqvO-tU7DrC4E7LtY6xQHiyuo,4164
|
|
4
|
+
hiddenwb/core.py,sha256=MnVvs_Ha24fi6Y1B3gIJ8ZLCEm71JHw56rXvf9xwoAs,476
|
|
5
|
+
hiddenwb/definitions.py,sha256=TPzCoHi2fqFO9_MyQwD6aVn9-C0RlnvZlCYI6cREyFw,13890
|
|
6
|
+
hiddenwb/detectors.py,sha256=VgwIeELHzkOj2PVHqoLC2MWUecjbQAlz7HLFlpVFcQQ,13889
|
|
7
|
+
hiddenwb/launcher.py,sha256=NgrYg9ZvHuj4H05FC1KQXkDRsLBZ_yQCttHD8Ct0db8,5864
|
|
8
|
+
hiddenwb/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
hiddenwb-0.1.0.dist-info/licenses/LICENSE,sha256=heaBOQWFC7zwR8knLLqF_8CLlFOE98YzRGLxbwvSZso,1067
|
|
10
|
+
hiddenwb-0.1.0.dist-info/METADATA,sha256=pYUSw9kOe6GEdIU_0bKSWPvcJGhEzXqnHMP27sT5nAA,3733
|
|
11
|
+
hiddenwb-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
12
|
+
hiddenwb-0.1.0.dist-info/entry_points.txt,sha256=SI__w9LY7yu_NfQwqmWA74d0f0UBmrWEAo06DZ1ihf0,47
|
|
13
|
+
hiddenwb-0.1.0.dist-info/top_level.txt,sha256=R5TglSY5QNjOpzbzOY9psDM4A1GvBgtyMOSWfkga5GM,9
|
|
14
|
+
hiddenwb-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Goplop0959
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hiddenwb
|