Aryaman25 commited on
Commit
e98283d
Β·
1 Parent(s): 15e8adb

Fix Home button no-op via native window.load_url() instead of location.href

Browse files

Reproduced directly: a page loaded over http(s) cannot script-navigate
itself to a file:// URL β€” the browser silently blocks it (no exception,
no navigation), which is exactly what made the toolbar's Home button do
nothing on a real site. Route it through a new Api.go_home() method
(same pywebview.api pattern already used by Calibrate/Validate/Start
Session) that calls window.load_url(LANDING_URL) natively, bypassing
the page-script navigation restriction entirely.

Files changed (1) hide show
  1. browser_session.py +19 -4
browser_session.py CHANGED
@@ -862,9 +862,6 @@ __THEME_CSS__
862
  document.getElementById('__iux_back').addEventListener('click', function(){ history.back(); });
863
  document.getElementById('__iux_fwd').addEventListener('click', function(){ history.forward(); });
864
  document.getElementById('__iux_reload').addEventListener('click', function(){ location.reload(); });
865
- document.getElementById('__iux_home').addEventListener('click', function(){
866
- location.href = __INSIGHTUX_LANDING_URL__;
867
- });
868
 
869
  // -- sidebar actions (Python decides validity β€” camera/session conflicts,
870
  // wrong page β€” and reports back through the status text) --
@@ -873,6 +870,11 @@ __THEME_CSS__
873
  window.pywebview.api[method]();
874
  }
875
  }
 
 
 
 
 
876
  document.getElementById('__iux_calibrate').addEventListener('click', function(){ callApi('start_calibration'); });
877
  document.getElementById('__iux_validate').addEventListener('click', function(){ callApi('run_validation'); });
878
  document.getElementById('__iux_session').addEventListener('click', function(){ callApi('toggle_session'); });
@@ -941,7 +943,6 @@ __THEME_CSS__
941
  }, true); // capture phase β€” fires before page scripts can intercept/stop the event
942
  })();
943
  """
944
- CHROME_JS = CHROME_JS.replace("__INSIGHTUX_LANDING_URL__", json.dumps(LANDING_URL))
945
  CHROME_JS = CHROME_JS.replace("__ICONS_JS__", theme.ICONS_JS)
946
  CHROME_JS = CHROME_JS.replace("__THEME_JS__", theme.THEME_TOGGLE_JS)
947
  CHROME_JS = CHROME_JS.replace("__THEME_CSS__", theme.THEME_CSS)
@@ -1838,6 +1839,20 @@ class Api:
1838
  print("[browser_session] quit_app() called from JS -- terminating process")
1839
  os._exit(0)
1840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1841
  # -- calibration / validation ------------------------------------------
1842
  # calibrate.py and validate.py are unmodified, standalone OpenCV/pyautogui
1843
  # scripts (their own fullscreen window, their own event loop) β€” they were
 
862
  document.getElementById('__iux_back').addEventListener('click', function(){ history.back(); });
863
  document.getElementById('__iux_fwd').addEventListener('click', function(){ history.forward(); });
864
  document.getElementById('__iux_reload').addEventListener('click', function(){ location.reload(); });
 
 
 
865
 
866
  // -- sidebar actions (Python decides validity β€” camera/session conflicts,
867
  // wrong page β€” and reports back through the status text) --
 
870
  window.pywebview.api[method]();
871
  }
872
  }
873
+ // A page loaded over http(s) can't script-navigate itself to a file://
874
+ // URL β€” the browser silently blocks it, no exception, no navigation β€”
875
+ // so this has to go through the native window.load_url() call in
876
+ // Api.go_home() instead of a plain location.href assignment.
877
+ document.getElementById('__iux_home').addEventListener('click', function(){ callApi('go_home'); });
878
  document.getElementById('__iux_calibrate').addEventListener('click', function(){ callApi('start_calibration'); });
879
  document.getElementById('__iux_validate').addEventListener('click', function(){ callApi('run_validation'); });
880
  document.getElementById('__iux_session').addEventListener('click', function(){ callApi('toggle_session'); });
 
943
  }, true); // capture phase β€” fires before page scripts can intercept/stop the event
944
  })();
945
  """
 
946
  CHROME_JS = CHROME_JS.replace("__ICONS_JS__", theme.ICONS_JS)
947
  CHROME_JS = CHROME_JS.replace("__THEME_JS__", theme.THEME_TOGGLE_JS)
948
  CHROME_JS = CHROME_JS.replace("__THEME_CSS__", theme.THEME_CSS)
 
1839
  print("[browser_session] quit_app() called from JS -- terminating process")
1840
  os._exit(0)
1841
 
1842
+ def go_home(self):
1843
+ # A page loaded over http(s) can't script-navigate itself to a
1844
+ # file:// URL β€” Chromium/WebView2 silently blocks it (no exception,
1845
+ # no navigation), which is what made the toolbar's Home button a
1846
+ # no-op via location.href. window.load_url() is a native host call,
1847
+ # not page script, so it isn't subject to that restriction β€” same
1848
+ # mechanism the report page's own navigation already relies on.
1849
+ print("[browser_session] go_home() called from JS")
1850
+ try:
1851
+ self.window.load_url(LANDING_URL)
1852
+ except Exception as e:
1853
+ print(f"[browser_session] go_home failed: {e}")
1854
+ return True
1855
+
1856
  # -- calibration / validation ------------------------------------------
1857
  # calibrate.py and validate.py are unmodified, standalone OpenCV/pyautogui
1858
  # scripts (their own fullscreen window, their own event loop) β€” they were