Skip to content
This repository was archived by the owner on Jul 26, 2024. It is now read-only.

Commit b0e6735

Browse files
committed
browser documentation
1 parent 9fce75f commit b0e6735

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

paling/browsers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ def _build_urls(start_pages: Iterable[Union[str, Dict[str, str]]], options: Opti
4747

4848

4949
def open(start_pages: Iterable[Union[str, Dict[str, str]]], options: OptionsDictT) -> None:
50+
"""
51+
Open a browser and navigate to the specified start pages.
52+
53+
Args:
54+
start_pages (Iterable[Union[str, Dict[str, str]]]): A collection of start pages to navigate to.
55+
Each start page can be either a URL string or a dictionary with 'url' and 'params' keys.
56+
options (OptionsDictT): A dictionary of options for configuring the browser.
57+
58+
Raises:
59+
TypeError: If the 'mode' option is not a string, boolean, or None.
60+
TypeError: If the 'cmdline_args' option is not a list of strings.
61+
EnvironmentError: If the specified browser installation cannot be found.
62+
63+
Returns:
64+
None
65+
"""
5066
# Build full URLs for starting pages (including host and port)
5167
start_urls = _build_urls(start_pages, options)
5268

paling/chrome.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
name: str = 'Google Chrome/Chromium'
99

1010
def run(path: str, options: OptionsDictT, start_urls: List[str]) -> None:
11+
"""
12+
Run the Chrome browser with the specified path, options, and start URLs.
13+
14+
Args:
15+
path (str): The path to the Chrome browser executable.
16+
options (OptionsDictT): A dictionary containing the options for running Chrome.
17+
start_urls (List[str]): A list of URLs to open in Chrome.
18+
19+
Raises:
20+
TypeError: If the 'cmdline_args' option is not of type List[str].
21+
22+
Returns:
23+
None
24+
"""
1125
if not isinstance(options['cmdline_args'], list):
1226
raise TypeError("'cmdline_args' option must be of type List[str]")
1327
if options['app_mode']:
@@ -22,6 +36,12 @@ def run(path: str, options: OptionsDictT, start_urls: List[str]) -> None:
2236

2337

2438
def find_path() -> Optional[str]:
39+
"""
40+
Finds the path of the Chrome executable based on the current operating system.
41+
42+
Returns:
43+
Optional[str]: The path of the Chrome executable if found, otherwise None.
44+
"""
2545
if sys.platform in ['win32', 'win64']:
2646
return _find_chrome_win()
2747
elif sys.platform == 'darwin':
@@ -33,6 +53,12 @@ def find_path() -> Optional[str]:
3353

3454

3555
def _find_chrome_mac() -> Optional[str]:
56+
"""
57+
Find the path of Google Chrome executable on macOS.
58+
59+
Returns:
60+
Optional[str]: The path of Google Chrome executable if found, otherwise None.
61+
"""
3662
default_dir = r'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
3763
if os.path.exists(default_dir):
3864
return default_dir
@@ -45,6 +71,12 @@ def _find_chrome_mac() -> Optional[str]:
4571

4672

4773
def _find_chromium_mac() -> Optional[str]:
74+
"""
75+
Find the Chromium executable path on macOS.
76+
77+
Returns:
78+
Optional[str]: The path to the Chromium executable if found, None otherwise.
79+
"""
4880
default_dir = r'/Applications/Chromium.app/Contents/MacOS/Chromium'
4981
if os.path.exists(default_dir):
5082
return default_dir
@@ -57,6 +89,12 @@ def _find_chromium_mac() -> Optional[str]:
5789

5890

5991
def _find_chrome_linux() -> Optional[str]:
92+
"""
93+
Finds the path of the Chrome executable on a Linux system.
94+
95+
Returns:
96+
Optional[str]: The path of the Chrome executable if found, None otherwise.
97+
"""
6098
import whichcraft as wch
6199
chrome_names = ['chromium-browser',
62100
'chromium',
@@ -71,6 +109,12 @@ def _find_chrome_linux() -> Optional[str]:
71109

72110

73111
def _find_chrome_win() -> Optional[str]:
112+
"""
113+
Find the path of the Chrome executable on Windows.
114+
115+
Returns:
116+
Optional[str]: The path of the Chrome executable if found, None otherwise.
117+
"""
74118
import winreg as reg
75119
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
76120
chrome_path: Optional[str] = None

paling/edge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys, subprocess as sps, os
2+
from typing import Optional
23

34
name = 'Edge'
45

@@ -27,7 +28,7 @@ def run(path: str, options: dict, start_urls: list) -> None:
2728
cmd = 'start microsoft-edge:{}'.format(start_urls[0])
2829
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
2930

30-
def find_path() -> str | None:
31+
def find_path() -> Optional[str]:
3132
if sys.platform in ['win32', 'win64']:
3233
return _find_edge_win()
3334
else:

0 commit comments

Comments
 (0)