Find the Chrome executable path on Linux or macOS.
()
| 14 | |
| 15 | |
| 16 | def _find_chrome_executable(): |
| 17 | """Find the Chrome executable path on Linux or macOS.""" |
| 18 | system = platform.system() |
| 19 | |
| 20 | if system == 'Darwin': |
| 21 | # macOS standard location |
| 22 | paths = [ |
| 23 | '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' |
| 24 | ] |
| 25 | elif system == 'Linux': |
| 26 | # Common Linux executables (Chromium and Google Chrome) |
| 27 | paths = [ |
| 28 | 'google-chrome', |
| 29 | 'google-chrome-stable', |
| 30 | 'chromium', |
| 31 | 'chromium-browser', |
| 32 | ] |
| 33 | else: |
| 34 | return None |
| 35 | |
| 36 | for path in paths: |
| 37 | try: |
| 38 | # Check if the command/path is callable (using 'which' or |
| 39 | # direct check) |
| 40 | if system == 'Linux': |
| 41 | # Use 'which' for common Linux commands/paths |
| 42 | result = subprocess.run( |
| 43 | ['which', path], |
| 44 | capture_output=True, |
| 45 | text=True, |
| 46 | check=False |
| 47 | ) |
| 48 | if result.returncode == 0: |
| 49 | return result.stdout.strip() |
| 50 | |
| 51 | # For macOS, or if 'which' failed/is unavailable, check direct path |
| 52 | if os.path.exists(path): |
| 53 | return path |
| 54 | |
| 55 | except FileNotFoundError: |
| 56 | continue |
| 57 | |
| 58 | return None |
| 59 | |
| 60 | |
| 61 | def read_command_line(): |
no test coverage detected