From f0e24a583d475fa971b60cb34ee8c68c89b1334f Mon Sep 17 00:00:00 2001 From: BestDigital22 <14256056+BestDigital22@users.noreply.github.com> Date: Sat, 2 Sep 2023 19:49:46 -0400 Subject: [PATCH] specify a custom web browser to launch instead of launching the default browser, pass a custom file path. also include a csv of command line flags like incognito,start-maximized --- comfy/cli_args.py | 3 +++ comfy/utils.py | 16 ++++++++++++++++ main.py | 11 ++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/comfy/cli_args.py b/comfy/cli_args.py index fda245433..e35da2f7a 100644 --- a/comfy/cli_args.py +++ b/comfy/cli_args.py @@ -94,6 +94,9 @@ parser.add_argument("--windows-standalone-build", action="store_true", help="Win parser.add_argument("--disable-metadata", action="store_true", help="Disable saving prompt metadata in files.") +parser.add_argument("--custom-browser-path", type=str, help="Path to custom browser instead of platform default, ex: c:/chrome.exe") +parser.add_argument("--custom-browser-args-csv", type=str, help="Args to pass to browser, ex: \"incognito,start-maximized\"") + args = parser.parse_args() if args.windows_standalone_build: diff --git a/comfy/utils.py b/comfy/utils.py index 47f4b9709..8cac5b149 100644 --- a/comfy/utils.py +++ b/comfy/utils.py @@ -407,3 +407,19 @@ class ProgressBar: def update(self, value): self.update_absolute(self.current + value) + +def launch_custom_web_browser(args, address, port): + import webbrowser + custom_browser = webbrowser.GenericBrowser(args.custom_browser_path) + + #If the user has supplied custom browser args + if args.custom_browser_args_csv: + + #args.browser_args_csv is a csv, split it into a list, prepend "--" to each arg and append to custom_browser.args + for arg in args.custom_browser_args_csv.split(","): + custom_browser.args.append("--" + arg) + + webbrowser.register('custom_browser', None, custom_browser) + customBrowser = webbrowser.get('custom_browser') + print(f"Launching custom browser at " + args.custom_browser_path) + customBrowser.open(f"http://{address}:{port}") \ No newline at end of file diff --git a/main.py b/main.py index a4038db4b..60355b5f7 100644 --- a/main.py +++ b/main.py @@ -180,7 +180,16 @@ if __name__ == "__main__": import webbrowser if os.name == 'nt' and address == '0.0.0.0': address = '127.0.0.1' - webbrowser.open(f"http://{address}:{port}") + + #If the user has supplied a custom browser path, use that instead of the default browser + if args.custom_browser_path: + if os.path.isfile(args.custom_browser_path): + comfy.utils.launch_custom_web_browser(args, address, port) + else: + print(f"Custom browser path does not exist: {args.custom_browser_path}") + else: + webbrowser.open(f"http://{address}:{port}") + call_on_start = startup_server try: