Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions harvester/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}'
}


Expand Down Expand Up @@ -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'),
}
}

Expand Down Expand Up @@ -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)

Expand Down