# Executing Java script code in JupyterLab gives error

**URL:** <https://discourse.jupyter.org/t/executing-java-script-code-in-jupyterlab-gives-error/14894>\
**Category:** JupyterLab\
**Tags:** jupyterlab, how-to, help-wanted\
**Created:** [July 11, 2022, 11:56am UTC](https://discourse.jupyter.org/t/executing-java-script-code-in-jupyterlab-gives-error/14894 "2022-07-11T11:56:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adhyapakh](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/adhyapakh/32/4907_2.png) [@adhyapakh](https://discourse.jupyter.org/u/adhyapakh)\
**Post date:** [July 11, 2022, 11:56am UTC](https://discourse.jupyter.org/t/executing-java-script-code-in-jupyterlab-gives-error/14894/1 "2022-07-11T11:56:22Z")

</div>

I am trying to print a Javascript code to return the notebook URL.

I have the following written in a Jupyter Notebook cell:

```auto
%%javascript
var kernel = IPython.notebook.kernel
var host = window.location.href
kernel.execute("notebook_url='"+host+"'")

```

and when I query for `notebook_url` it gives output as `'http://localhost:8889/notebooks/LTIBootCamp.ipynb'`

[![enter image description here](https://i.stack.imgur.com/decyk.png)](https://i.stack.imgur.com/decyk.png)

But when I try the same from Jupyter Lab it gives the following error

```auto
from IPython.display import display, Javascript

display(Javascript(
    'var kernel = IPython.notebook.kernel'
'var host = window.location.href'
'kernel.execute("notebook_url='"+host+"'")'
))

```

output error:

```auto
Javascript Error: unexpected token: identifier

```

Any suggestions how can can I do the same in JupyterLab?

---

<div class="post-metadata">

**Author:** ![bollwyvl](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bollwyvl/32/904_2.png) [@bollwyvl](https://discourse.jupyter.org/u/bollwyvl)\
**Post date:** [July 11, 2022, 3:27pm UTC](https://discourse.jupyter.org/t/executing-java-script-code-in-jupyterlab-gives-error/14894/2 "2022-07-11T15:27:00Z")

</div>

Right: the `IPython`- and `Jupyter`-APIs are not available in clients other than notebook \<6, e.g. JupyterLab, VSCode, Colab. It is also uncertain whether these will be introduced as shims in notebook 7.

JupyterLab, in specific, offers an `--expose-app-in-browser` option, but that API (`jupyterapp`) is different, and limited in its own ways.

[ipylab](https://github.com/jtpio/ipylab) provides some options for bridging some of these gaps, but is then more tightly bound to _that_ client.
