Setting to disable redirect file browser launch

When it was originally added, the PR for launching a browser via a redirect file (jupyter#4260) created some issues for some environments-namely WSL, Chromebook, and Android (jupyter#4346 (comment), jupyter/help#496). The reason for the break in these environments is due to the file structure/path differences between the runtime and the browser. 

This commit adds a setting to the `jupyter_notebook_config.py` that allows users to disable the use of redirect file for launching a browser in favor of the original, yet visible, URL + token approach. This setting: `c.NotebookApp.use_redirect_file` will be set to True by default.
pull/4999/head
Marcus D Sherman 7 years ago committed by GitHub
parent 55e93b9ffe
commit fa12f4b2f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -223,6 +223,7 @@ class NotebookWebApplication(web.Application):
base_url=base_url,
default_url=default_url,
template_path=template_path,
use_redirect_file=jupyter_app.use_redirect_file,
static_path=jupyter_app.static_file_path,
static_custom_path=jupyter_app.static_custom_path,
static_handler_class = FileFindHandler,
@ -539,6 +540,20 @@ flags['allow-root']=(
_("Allow the notebook to be run from root user.")
)
flags['use_redirect_file']=(
{'NotebookApp' : {'use_redirect_file' : True}},
"""Disable launching browser by redirect file
For some environments (like Windows Subsystem for Linux (WSL) and Chromebooks),
launching a browser using a redirect file (introduced in notebook versions
> 5.7.2) can lead the browser failing to load. This is because of the
difference in file structures/paths between the runtime and the browser.
Disabling this setting will by setting to False will disable this behavior,
allowing the browser to launch by using a URL and visible token (as before).
"""
)
# Add notebook manager flags
flags.update(boolean_flag('script', 'FileContentsManager.save_script',
'DEPRECATED, IGNORED',
@ -645,6 +660,19 @@ class NotebookApp(JupyterApp):
help=_("Whether to allow the user to run the notebook as root.")
)
use_redirect_file = Bool(True, config=True,
help="""Disable launching browser by redirect file
For some environments (like Windows Subsystem for Linux (WSL) and Chromebooks),
launching a browser using a redirect file (introduced in notebook versions
> 5.7.2) can lead the browser failing to load. This is because of the
difference in file structures/paths between the runtime and the browser.
Disabling this setting will by setting to False will disable this behavior,
allowing the browser to launch by using a URL and visible token (as before).
"""
)
default_url = Unicode('/tree', config=True,
help=_("The default URL to redirect to from `/`")
)
@ -1805,7 +1833,13 @@ class NotebookApp(JupyterApp):
if not browser:
return
if self.file_to_run:
if not self.use_redirect_file:
uri = self.default_url[len(self.base_url):]
if self.token:
uri = url_concat(uri, {'token': self.token})
elif self.file_to_run:
if not os.path.exists(self.file_to_run):
self.log.critical(_("%s does not exist") % self.file_to_run)
self.exit(1)
@ -1820,10 +1854,17 @@ class NotebookApp(JupyterApp):
else:
open_file = self.browser_open_file
b = lambda: browser.open(
urljoin('file:', pathname2url(open_file)),
new=self.webbrowser_open_new)
threading.Thread(target=b).start()
if not self.use_redirect_file:
if browser:
b = lambda: browser.open(url_path_join(self.connection_url, uri),
new=self.webbrowser_open_new)
threading.Thread(target=b).start()
else:
b = lambda: browser.open(
urljoin('file:', pathname2url(open_file)),
new=self.webbrowser_open_new)
threading.Thread(target=b).start()
def start(self):
""" Start the Notebook server app, after initialization

Loading…
Cancel
Save