# Access current cell metadata

**URL:** https://talk.observablehq.com/t/access-current-cell-metadata/1873
**Category:** Feedback
**Created:** [April 9, 2019, 7:24pm UTC](https://talk.observablehq.com/t/access-current-cell-metadata/1873 "2019-04-09T19:24:01Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)
#### Post date: [April 9, 2019, 10:04pm UTC](https://talk.observablehq.com/t/access-current-cell-metadata/1873/2 "2019-04-09T22:04:17Z")

</div>

There was a previous request along these lines [here](https://talk.observablehq.com/t/how-to-get-a-cell-s-name/1246) but in the end something much simpler (a trick to get the name of a function argument by wrapping it in an object) sufficed.

Here are some thoughts on how you might approach getting that data now. I see ways that you can get something like the `Notebook` global (with data about all the cells in the notebook), but getting a `currentCell` object working seems harder:

As hinted at in the above-linked thread, you can get a lot of the information you want about a notebook by fetching the notebook JSON object from the Observable API (specifically, from `https://api.observablehq.com/document/username/notebook-name`); however, this can’t be done directly from a notebook because the origin of the request needs to be `observablehq.com` and not `.observableusercontent.com`. I think there used to be some notebooks [like this one](https://observablehq.com/@fil/my-notebooks) which got around this using a CORS proxy, but the proxies don’t seem to be working at the moment.

An imperfect way to get something like this notebook JSON data is to use the `fromV1` function I’ve written [here](https://observablehq.com/@bryangingechen/fromv1), which lets you pass a URL to the notebook’s runtime V1 module JS file (which the API lets you access from a notebook). This function can reconstruct a notebook JSON object from the JS file (n.b. this is stuck at the most-recently shared / published version of the notebook), but there are limitations, particularly for notebooks with imports.

Note that the notebook JSON object only contains the id of each cell (currently, a number) and the cell “body” (i.e. the source string you submit for the cell). To get the name and viewof data you want from that, you can pass the cell bodies to the observable [parser library](https://github.com/observablehq/parser); (see e.g. [this notebook of mine](https://observablehq.com/@bryangingechen/from-raw-notebook-source-to-observable-runtime-v1-modules)).

Finally, let’s assume you have accomplished enough of the above so that one of your live cells `cell1` has access to a parsed notebook array `nbdat` whose elements are objects with metadata on each of the cells in that notebook. Then you still have the problem of figuring out from within `cell1` which entry of `nbdat` it corresponds to. This seems tricky to do in general.

OK, I ended up making a rough little demo notebook. The punchline is that cells which output HTML elements can sort of get their own metadata, but you’ll need a “real” notebook JSON object – the one created by `fromV1` won’t be good enough:

> **[A notebook that kinda knows about itself](https://observablehq.com/d/8d72f1a5131e5033)**
>
> An Observable notebook by Bryan Gin-ge Chen.

---

_[View the full topic](https://talk.observablehq.com/t/access-current-cell-metadata/1873)._
