Javascript Extension to enable arbitrary control of JupyterLab

58 views
Skip to first unread message

Florian Wetschoreck

unread,
Nov 30, 2018, 4:16:09 AM11/30/18
to Project Jupyter
Hi,

there are good reasons why currently it is not allowed to execute arbitrary Javascript in JupyterLab.
Also, there is a fix with the javascript extension package which exposes the window, document and element objects.

However, we need access to more (internal) objects if we want to add cells or execute cells etc

Therefore, I want to extend the current Javascript extension package to expose even more context for users who know what they are doing.
The goal is to have another more powerful javascript extension which exposes all relevant objects to fully manipulate JupyterLab without having to go through the process of writing a custom extension.

Do you have any advice on this endeavor? For example: which objects to expose?
How to install the extension without interfering with the existing javascript MimeRenderer. Or maybe: how to overwrite the existing Javascript MimeRenderer. Is it possible to have both side by side? eg to import Javascript and/or JavascriptFullAccess from IPython.display

Any help is highly appreciated.

Florian

Grant Nestor

unread,
Nov 30, 2018, 12:17:50 PM11/30/18
to Project Jupyter
Hi Florian,

This certainly was one nice thing about classic notebook: the global `jupyter` variable. 

If you run JupyterLab in dev-mode, you get a global `window.lab` variable that gives you a handle on the application. This is a good starting point. To add a new cell, you can call `window.lab.commands.execute('notebook:insert-cell-below')`. You can call that in the browser console or in a cell:

```py
%%js
window.lab.commands.execute('notebook:insert-cell-below')
```

If you want to run a cell: `window.lab.commands.execute('notebook:run-cell-and-select-next')`

You can find these commands by searching the command palette and then searching the jupyterlab source code for the command title.

Another relevant project is jyve which gives you several custom Jupyter JS-based kernels that expose JupyterLab internals outside of dev-mode: https://github.com/deathbeds/jyve

We are weary to expose this outside of dev-mode by default because of the consequences that running arbitrary code could have on the user's lab environment and system. We could consider adding a setting to the javascript-extension allowing users to override this behavior so that it's not default but possible.

Feel free to open an issue on the jupyterlab repo.

Grant

Brian Granger

unread,
Dec 3, 2018, 3:21:02 PM12/3/18
to jup...@googlegroups.com
I agree with Grant that the preferred way of doing this would be to use the JupyterLab command system.  You could write a mime renderer that takes JSON data and runs corresponding command. Then you don't have to send it JavaScript code over the wire.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/e456cda7-901a-4d3d-a764-9078ff9fd68a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgra...@calpoly.edu and elli...@gmail.com

Florian Wetschoreck

unread,
Dec 7, 2018, 10:10:53 AM12/7/18
to Project Jupyter
Hi Grant,

thank you for your elaborate answer! jyve looks exactly like what I was thinking about.

Best regards,
Florian

Florian Wetschoreck

unread,
Dec 7, 2018, 10:12:40 AM12/7/18
to Project Jupyter
Thank you for your comment, too, Brian! I might get back to this, when I am thinking about how to exactly implement this.

Best regards,
Florian
Reply all
Reply to author
Forward
0 new messages