diff --git a/harvester/browser.py b/harvester/browser.py index e6e5ab3..0cff9c2 100644 --- a/harvester/browser.py +++ b/harvester/browser.py @@ -3,6 +3,7 @@ import platform import subprocess import tempfile +import shutil from collections.abc import Iterable from enum import Enum from functools import partial @@ -20,7 +21,8 @@ restart_commands = { 'Darwin': 'killall "{app}"', - 'Windows': 'TASKKILL /IM {browser}.exe /F' + 'Windows': 'TASKKILL /IM {browser}.exe /F', + 'Linux': 'pkill -f {browser}' } @@ -64,12 +66,33 @@ def read_windows_registry(browser: str) -> str: return exe_path +def read_linux_binary(_browser: str) -> str: + """ + Attempts to locate a Chromium-based browser on Linux by checking common + executable names on PATH. + """ + candidates = [ + 'google-chrome', + 'google-chrome-stable', + 'chromium', + 'chromium-browser' + ] + for name in candidates: + path = shutil.which(name) + if path: + return path + return None + + registry = { 'Darwin': { 'chrome': partial(read_osx_defults, 'com.google.Chrome', 'Google Chrome'), }, 'Windows': { 'chrome': partial(read_windows_registry, 'chrome'), + }, + 'Linux': { + 'chrome': partial(read_linux_binary, 'chrome'), } } @@ -110,11 +133,11 @@ def launch(domain: Union[str, List[str]], server_address: Tuple[str, int], brows browser_command.append(binary_location) else: raise RuntimeError( - 'Automatic broswer functinality only avalible on MacOS and Windows for now.\n' - 'If you are running one of the above OS\'s then the harvester wasn\'t able to ' - 'find the browser in it\'s default location.\n' - 'Try passing the full path to a browser executeable or the command you\'d use ' - 'to launch it instead.') + 'Could not automatically locate a Chromium-based browser.\n' + 'Supported OS: macOS, Windows, and Linux. The harvester could not find Chrome/Chromium\n' + 'in its default location or on your PATH.\n' + 'Try passing the full path to the browser executable or the command you\'d use to launch it instead.' + ) else: browser_command.append(browser)