equinor/webviz-config

`webviz build` cannot be used in environments where webbrowser.get fails

oysteinequinor opened this issue · 0 comments

Describe the bug
webviz build fails to provide the login token if webbrowser.get fails.

How to reproduce
Run webviz build in WSL without installing a browser inside of WSL.

Expected behavior
I expect an alternative way of accessing the application, such as a link with the token. I can then click or copy/paste the link from the terminal manually.

Suggested workaround/fix

diff --git a/webviz_config/utils/_localhost_open_browser.py b/webviz_config/utils/_localhost_open_browser.py
index 153641d..8d2e85d 100644
--- a/webviz_config/utils/_localhost_open_browser.py
+++ b/webviz_config/utils/_localhost_open_browser.py
@@ -17,8 +17,17 @@ class LocalhostOpenBrowser:
         self._port = port
         self._token = token

+        # Only open new browser tab if not a reload process
         if not is_reload_process():
-            # Only open new browser tab if not a reload process
+
+            # Print url if browser detection fails (might happen in headless installs)
+            try:
+                webbrowser.get()
+            except webbrowser.Error:
+                print("Automatic browser detection failed. Open link manually.")
+                print(self._url(with_token=True))
+                return
+
             threading.Thread(target=self._timer).start()

     def _timer(self) -> None:

Additional context
I am using this workaround to make webviz work for me.