diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py index d5a43f286..f1f8ce42a 100644 --- a/mitmproxy/tools/cmdline.py +++ b/mitmproxy/tools/cmdline.py @@ -867,6 +867,11 @@ def mitmweb(): ) group = parser.add_argument_group("Mitmweb") + group.add_argument( + "--no-browser", + action="store_false", dest="open_browser", + help="Don't start a browser" + ) group.add_argument( "--wport", action="store", type=int, dest="wport", default=8081, diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index 478690eb2..d276944d9 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -132,6 +132,7 @@ def mitmweb(args=None): # pragma: no cover try: web_options = web.master.Options(**cmdline.get_common_options(args)) web_options.intercept = args.intercept + web_options.open_browser = args.open_browser web_options.wdebug = args.wdebug web_options.wiface = args.wiface web_options.wport = args.wport diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py index 5457fb40a..ac028fd1e 100644 --- a/mitmproxy/tools/web/master.py +++ b/mitmproxy/tools/web/master.py @@ -20,12 +20,14 @@ class Options(options.Options): self, *, # all args are keyword-only. intercept: Optional[str] = None, + open_browser: bool = True, wdebug: bool = False, wport: int = 8081, wiface: str = "127.0.0.1", **kwargs ) -> None: self.intercept = intercept + self.open_browser = open_browser self.wdebug = wdebug self.wport = wport self.wiface = wiface @@ -122,11 +124,13 @@ class WebMaster(master.Master): try: url = "http://{}:{}/".format(self.options.wiface, self.options.wport) print("Server listening at {}".format(url), file=sys.stderr) - if not open_browser(url): - print("No webbrowser found. Please open a browser and point it to {}".format(url)) + if self.options.open_browser: + success = open_browser(url) + if not success: + print("No webbrowser found. Please open a browser and point it to {}".format(url)) iol.start() - except (KeyboardInterrupt): + except KeyboardInterrupt: self.shutdown()