@@ -879,6 +879,22 @@ def _default_allow_remote(self):
879
879
else :
880
880
return not addr .is_loopback
881
881
882
+ use_redirect_file = Bool (True , config = True ,
883
+ help = """Disable launching browser by redirect file
884
+ For versions of notebook > 5.7.2, a security feature measure was added that
885
+ prevented the authentication token used to launch the browser from being visible.
886
+ This feature makes it difficult for other users on a multi-user system from
887
+ running code in your Jupyter session as you.
888
+ However, some environments (like Windows Subsystem for Linux (WSL) and Chromebooks),
889
+ launching a browser using a redirect file can lead the browser failing to load.
890
+ This is because of the difference in file structures/paths between the runtime and
891
+ the browser.
892
+
893
+ Disabling this setting to False will disable this behavior, allowing the browser
894
+ to launch by using a URL and visible token (as before).
895
+ """
896
+ )
897
+
882
898
local_hostnames = List (Unicode (), ['localhost' ], config = True ,
883
899
help = """Hostnames to allow as local when allow_remote_access is False.
884
900
@@ -1761,6 +1777,12 @@ def launch_browser(self):
1761
1777
if not browser :
1762
1778
return
1763
1779
1780
+ if not self .use_redirect_file :
1781
+ uri = self .default_url [len (self .base_url ):]
1782
+
1783
+ if self .token :
1784
+ uri = url_concat (uri , {'token' : self .token })
1785
+
1764
1786
if self .file_to_run :
1765
1787
if not os .path .exists (self .file_to_run ):
1766
1788
self .log .critical (_ ("%s does not exist" ) % self .file_to_run )
@@ -1776,9 +1798,12 @@ def launch_browser(self):
1776
1798
else :
1777
1799
open_file = self .browser_open_file
1778
1800
1779
- b = lambda : browser .open (
1780
- urljoin ('file:' , pathname2url (open_file )),
1781
- new = self .webbrowser_open_new )
1801
+ if self .use_redirect_file :
1802
+ assembled_url = urljoin ('file:' , pathname2url (open_file ))
1803
+ else :
1804
+ assembled_url = url_path_join (self .connection_url , uri )
1805
+
1806
+ b = lambda : browser .open (assembled_url , new = self .webbrowser_open_new )
1782
1807
threading .Thread (target = b ).start ()
1783
1808
1784
1809
def start_app (self ):
0 commit comments