Skip to content
This repository

Ability to open the notebook in a browser when it starts #891

Merged
merged 1 commit into from over 2 years ago

2 participants

Thomas Kluyver Fernando Perez
Thomas Kluyver
Collaborator

When the notebook starts up, it opens a browser with its homepage.

Currently, this simply makes the call to launch the browser immediately before entering the server loop. On my system, the server is running by the time the browser requests the homepage. If this isn't sufficient, we'll just need to use a threading.Timer to delay it for a fraction of a second.

There's a config option, and a flag --no-browser to control this behaviour.

Fernando Perez fperez merged commit e9f8f8c into from
Fernando Perez fperez closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 17, 2011
Thomas Kluyver Add ability to open the notebook in a browser when it starts. e9f8f8c
This page is out of date. Refresh to see the latest.
15  IPython/frontend/html/notebook/notebookapp.py
@@ -22,6 +22,7 @@
22 22
 import signal
23 23
 import socket
24 24
 import sys
  25
+import webbrowser
25 26
 
26 27
 import zmq
27 28
 
@@ -51,7 +52,7 @@
51 52
     aliases as ipkernel_aliases,
52 53
     IPKernelApp
53 54
 )
54  
-from IPython.utils.traitlets import Dict, Unicode, Int, List, Enum
  55
+from IPython.utils.traitlets import Dict, Unicode, Int, List, Enum, Bool
55 56
 
56 57
 #-----------------------------------------------------------------------------
57 58
 # Module globals
@@ -111,11 +112,15 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager, log):
111 112
 #-----------------------------------------------------------------------------
112 113
 
113 114
 flags = dict(ipkernel_flags)
  115
+flags['no-browser']=(
  116
+    {'IPythonNotebookApp' : {'open_browser' : False}},
  117
+    "Don't open the notebook in a browser after startup."
  118
+)
114 119
 
115 120
 # the flags that are specific to the frontend
116 121
 # these must be scrubbed before being passed to the kernel,
117 122
 # or it will raise an error on unrecognized flags
118  
-notebook_flags = []
  123
+notebook_flags = ['no-browser']
119 124
 
120 125
 aliases = dict(ipkernel_aliases)
121 126
 
@@ -195,6 +200,9 @@ def _ip_changed(self, name, old, new):
195 200
     password = Unicode(u'', config=True,
196 201
                       help="""Password to use for web authentication"""
197 202
     )
  203
+    
  204
+    open_browser = Bool(True, config=True,
  205
+                        help="Whether to open in a browser after starting.")
198 206
 
199 207
     def get_ws_url(self):
200 208
         """Return the WebSocket URL for this server."""
@@ -291,6 +299,9 @@ def start(self):
291 299
         self.log.info("The IPython Notebook is running at: %s://%s:%i" % (proto,
292 300
                                                                           ip,
293 301
                                                                           self.port))
  302
+        if self.open_browser:
  303
+            ip = self.ip or '127.0.0.1'
  304
+            webbrowser.open("%s://%s:%i" % (proto, ip, self.port), new=2)
294 305
         ioloop.IOLoop.instance().start()
295 306
 
296 307
 #-----------------------------------------------------------------------------
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.