diff --git a/src/Ui/UiServer.py b/src/Ui/UiServer.py
index 63738c99..08820832 100644
--- a/src/Ui/UiServer.py
+++ b/src/Ui/UiServer.py
@@ -13,6 +13,7 @@ from Config import config
 from Debug import Debug
 import importlib
 
+from util import helper
 
 # Skip websocket handler if not necessary
 class UiWSGIHandler(WebSocketHandler):
@@ -144,22 +145,7 @@ class UiServer:
             self.log.info("Web interface: http://%s:%s/" % (config.ui_ip, config.ui_port))
         self.log.info("--------------------------------------")
 
-        if config.open_browser and config.open_browser != "False":
-            logging.info("Opening browser: %s...", config.open_browser)
-            import webbrowser
-            ui_ip = config.ui_ip if config.ui_ip != "*" else "127.0.0.1"
-            url = f'http://{ui_ip}:{config.ui_port}/{config.homepage}'
-            try:
-                if config.open_browser == "default_browser":
-                    browser = webbrowser.get()
-                else:
-                    browser = webbrowser.get(config.open_browser)
-                gevent.spawn_later(0.3, browser.open, url, new=2)
-            except webbrowser.Error as err:
-                import subprocess
-                subprocess.Popen([config.open_browser, url])
-            except Exception as err:
-                print("Error starting browser: %s" % err)
+        helper.openBrowser(config.open_browser)
 
         self.server = WSGIServer((self.ip, self.port), handler, handler_class=UiWSGIHandler, log=self.log)
         self.server.sockets = {}
diff --git a/src/main.py b/src/main.py
index d348f37a..47701b99 100644
--- a/src/main.py
+++ b/src/main.py
@@ -69,20 +69,8 @@ if config.action == "main":
         lock = helper.openLocked("%s/lock.pid" % config.data_dir, "w")
         lock.write("%s" % os.getpid())
     except BlockingIOError as err:
-        startupError("Can't open lock file, your ZeroNet client is probably already running, exiting... (%s)" % err)
-        if config.open_browser and config.open_browser != "False":
-            print("Opening browser: %s...", config.open_browser)
-            import webbrowser
-            try:
-                if config.open_browser == "default_browser":
-                    browser = webbrowser.get()
-                else:
-                    browser = webbrowser.get(config.open_browser)
-                browser.open("http://%s:%s/%s" % (
-                    config.ui_ip if config.ui_ip != "*" else "127.0.0.1", config.ui_port, config.homepage
-                ), new=2)
-            except Exception as err:
-                startupError("Error starting browser: %s" % err)
+        startupError(f"Can't open lock file, your 0net client is probably already running, exiting... ({err})")
+        helper.openBrowser(config.open_browser)
         sys.exit()
 
 config.initLogging()
diff --git a/src/util/helper.py b/src/util/helper.py
index 61455b08..fa979864 100644
--- a/src/util/helper.py
+++ b/src/util/helper.py
@@ -354,3 +354,14 @@ def encodeResponse(func):  # Encode returned data from utf8 to bytes
                 yield back.encode()
 
     return wrapper
+
+def openBrowser(agent):
+    if agent and agent != "False":
+        print(f"Opening browser: {agent}...")
+        ui_ip = config.ui_ip if config.ui_ip != "*" else "127.0.0.1"
+        url = f'http://{ui_ip}:{config.ui_port}/{config.homepage}'
+        try:
+            import subprocess
+            subprocess.Popen([config.open_browser, url])
+        except Exception as err:
+            print(f"Error starting browser: {err}")