Skip to content

Commit 04fa25e

Browse files
🐛 Fix Safari executable cannot open a URL directly (#14)
1 parent 9d03813 commit 04fa25e

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

browsers/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def _launch(browser: str, path: str, args: Sequence[str], url: str = None) -> su
7272
elif url is not None:
7373
url_arg.append(url)
7474

75-
if sys.platform != "linux":
75+
if browser == "safari":
76+
if args:
77+
logger.warning("Safari does not accept command line arguments. %s will be ignored.", str(args))
78+
command = ["open", "--wait-apps", "--new", "--fresh", "-a", path, *url_arg]
79+
elif sys.platform != "linux":
7680
command = [path, *url_arg, *args]
7781
else:
7882
command = [*shlex.split(path), *url_arg, *args]

browsers/osx.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ def browsers() -> Iterator[Tuple[str, Dict]]: # type: ignore[return]
3838
executable = os.path.join(path, "Contents/MacOS", executable_name)
3939
display_name = plist.get("CFBundleDisplayName") or plist.get("CFBundleName", browser)
4040
version = plist[version_string]
41-
yield browser, dict(path=executable, display_name=display_name, version=version)
41+
yield browser, dict(
42+
path=executable if browser != "safari" else path, display_name=display_name, version=version
43+
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pybrowsers"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
repository = "https://github.com/roniemartinez/browsers"
55
description = "Python library for detecting and launching browsers"
66
authors = ["Ronie Martinez <ronmarti18@gmail.com>"]

tests/test_detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_get_available_browsers(browser: str) -> None:
5555
"safari",
5656
{
5757
"display_name": "Safari",
58-
"path": "/Applications/Safari.app/Contents/MacOS/Safari",
58+
"path": "/Applications/Safari.app",
5959
"version": ANY,
6060
},
6161
marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"),

0 commit comments

Comments
 (0)