MCPcopy
hub / github.com/mitmproxy/mitmproxy / open_browser

Function open_browser

mitmproxy/tools/web/webaddons.py:116–151  ·  view source on GitHub ↗

Open a URL in a browser window. In contrast to webbrowser.open, we limit the list of suitable browsers. This gracefully degrades to a no-op on headless servers, where webbrowser.open would otherwise open lynx. Returns: True, if a browser has been opened False, i

(url: str)

Source from the content-addressed store, hash-verified

114
115
116def open_browser(url: str) -> bool:
117 """
118 Open a URL in a browser window.
119 In contrast to webbrowser.open, we limit the list of suitable browsers.
120 This gracefully degrades to a no-op on headless servers, where webbrowser.open
121 would otherwise open lynx.
122
123 Returns:
124 True, if a browser has been opened
125 False, if no suitable browser has been found.
126 """
127 browsers = (
128 "windows-default",
129 "macosx",
130 "wslview %s",
131 "gio",
132 "x-www-browser",
133 "gnome-open %s",
134 "xdg-open",
135 "google-chrome",
136 "chrome",
137 "chromium",
138 "chromium-browser",
139 "firefox",
140 "opera",
141 "safari",
142 )
143 for browser in browsers:
144 try:
145 b = webbrowser.get(browser)
146 except webbrowser.Error:
147 pass
148 else:
149 if b.open(url):
150 return True
151 return False

Callers 1

runningMethod · 0.85

Calls 2

getMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…