How in Javascript to send a `comm_info` to the Kernel?

79 views
Skip to first unread message

Jan Pfeifer

unread,
Sep 2, 2023, 1:54:43 AM9/2/23
to Project Jupyter
hi all, 

I’m trying to build something similar to ipywidgets but to the GoNB kernel (a Go kernel), and I’m trying to figure out how to communicate from Javascript in the notebook to the kernel.

Any pointers ?

The Kernel Message protocol suggests that one can use custom messages (using "Comm" channels, using the Shell socket on the kernel, and presumably the IOPub in the Frontend)  for that. I also saw these messages passing by when playing ipywidgets (in Python) and looking at the debug output of JupyterLab.

But how from Javascript (from an HTML widget) I tell Jupyter notebook to send these messages to the kernel ? 

Any pointers to documentation, or example source code I can get started ?

many thanks!

ps.: This is a repost from an old question in Jupyter Forum, for which I didn't get a reply (maybe wrong topic?)

Jan Pfeifer

unread,
Sep 2, 2023, 4:29:33 AM9/2/23
to Project Jupyter
Just to clarify, my mental model of what goes on is:

(1) Kernel <---- ZMQ ----> (2) JupyterServer(?) <--->  WebSockets(??) <---> (3) Jupyter WebApp/FrontEnd (in Browser) <---> (4) User Javascript/Wasm code (Inside the output of a cell)

I'm looking for a way to get (1, the kernel) and (4, the user javascript/wasm) to communicate.

From poking around the debug messages, it seems there is a websocket port in (2, JupyterServe) in `/api/kernels/<session_id>/channels` ? Is this something my user code (4) can open a socket and communicate through, using the custom messages protocol ? 

I found this documentation on WebSocket protocol, but it seems to be aimed at communication between (2) and (3). I'm not sure I'm able in (4) to connect to this websocket, and if it is, what is its address (maybe the one I pointed above?)

cheers

ps.: I found many other questions in stack overflow, Jupyter Forum, and even in this list, but I'm missing some of the details, and most seem to be using/require some installed jupyter extension, which I wanted to avoid having to do -- much better if this works without needing to install other things, not mention having to manager another separate codebase for the extension :)
Reply all
Reply to author
Forward
0 new messages