@@ -645,6 +645,24 @@ def _default_log_format(self):
645
645
help = _ ("Whether to allow the user to run the notebook as root." )
646
646
)
647
647
648
+ use_redirect_file = Bool (True , config = True ,
649
+ help = """Disable launching browser by redirect file
650
+
651
+ For versions of notebook > 5.7.2, a security feature measure was added that
652
+ prevented the authentication token used to launch the browser from being visible.
653
+ This feature makes it difficult for other users on a multi-user system from
654
+ running code in your Jupyter session as you.
655
+
656
+ However, some environments (like Windows Subsystem for Linux (WSL) and Chromebooks),
657
+ launching a browser using a redirect file can lead the browser failing to load.
658
+ This is because of the difference in file structures/paths between the runtime and
659
+ the browser.
660
+
661
+ Disabling this setting to False will disable this behavior, allowing the browser
662
+ to launch by using a URL and visible token (as before).
663
+ """
664
+ )
665
+
648
666
default_url = Unicode ('/tree' , config = True ,
649
667
help = _ ("The default URL to redirect to from `/`" )
650
668
)
@@ -1805,6 +1823,12 @@ def launch_browser(self):
1805
1823
if not browser :
1806
1824
return
1807
1825
1826
+ if not self .use_redirect_file :
1827
+ uri = self .default_url [len (self .base_url ):]
1828
+
1829
+ if self .token :
1830
+ uri = url_concat (uri , {'token' : self .token })
1831
+
1808
1832
if self .file_to_run :
1809
1833
if not os .path .exists (self .file_to_run ):
1810
1834
self .log .critical (_ ("%s does not exist" ) % self .file_to_run )
@@ -1820,9 +1844,12 @@ def launch_browser(self):
1820
1844
else :
1821
1845
open_file = self .browser_open_file
1822
1846
1823
- b = lambda : browser .open (
1824
- urljoin ('file:' , pathname2url (open_file )),
1825
- new = self .webbrowser_open_new )
1847
+ if self .use_redirect_file :
1848
+ assembled_url = urljoin ('file:' , pathname2url (open_file ))
1849
+ else :
1850
+ assembled_url = url_path_join (self .connection_url , uri )
1851
+
1852
+ b = lambda : browser .open (assembled_url , new = self .webbrowser_open_new )
1826
1853
threading .Thread (target = b ).start ()
1827
1854
1828
1855
def start (self ):
0 commit comments