Skip to content

Commit

Permalink
Add support for Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwacky42 committed Oct 31, 2022
1 parent 27cf2d2 commit b5f7049
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mitmproxy/addons/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,24 @@ def get_chrome_flatpak() -> Optional[str]:
return None


def get_firefox_executable() -> Optional[str]:
for browser in (
"/Applications/Firefox.app/Contents/MacOS/Firefox",
r"C:\Program Files\Mozilla Firefox\firefox.exe",
"firefox",
):
if shutil.which(browser):
return browser

return None

def get_browser_cmd() -> Optional[list[str]]:
if browser := get_chrome_executable():
return [browser]
elif browser := get_chrome_flatpak():
return ["flatpak", "run", "-p", browser]

elif browser := get_firefox():
return [browser]
return None


Expand Down
8 changes: 8 additions & 0 deletions test/mitmproxy/addons/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ async def test_get_browser_cmd_no_flatpak():
which.side_effect = lambda cmd: cmd == "flatpak"
subprocess_run.return_value = mock.Mock(returncode=1)
assert browser.get_browser_cmd() is None


async def test_get_browser_cmd_firefox():
with mock.patch("shutil.which") as which:
which.side_effect = lambda cmd: cmd == "firefox"
assert browser.get_browser_cmd() == ["firefox"]


0 comments on commit b5f7049

Please sign in to comment.