# Anyway to get all cells' names on a notebook?

**URL:** <https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830>\
**Category:** Help\
**Created:** [March 26, 2021, 2:07pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830 "2021-03-26T14:07:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Real-John-Cheung](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/real-john-cheung/32/4489_2.png) [@Real-John-Cheung](https://talk.observablehq.com/u/Real-John-Cheung)\
**Post date:** [March 26, 2021, 2:07pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/1 "2021-03-26T14:07:49Z")

</div>

I am confused about how Observable works…, especially how a cell’s name is linked to the script file (I guess by the data-node-id, but the fact that there is autofill for cell names seems to indicate that all cells’ names are store somewhere as a list or something)

Is there a way to access this ‘list’ in a cell?

---

<div class="post-metadata">

**Author:** ![asg017](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/asg017/32/2159_2.png) [@asg017](https://talk.observablehq.com/u/asg017)\
**Post date:** [March 26, 2021, 3:30pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/2 "2021-03-26T15:30:15Z")

</div>

From _within_ an Observable notebook (ie the code that you write), I don’t think there’s a way to access a “list” of cells that are in scope.

But the [runtime](https://github.com/observablehq/runtime) itself does store that, since the runtime handles cell evaluation and the [computation tree](https://observablehq.com/@observablehq/how-observable-runs). If you had direct access to the [“module”](https://github.com/observablehq/runtime#modules) of a notebook, you could do something like:

```javascript
const main = runtime.module();

main.variable().define("a", 1);
main.variable().define("b", 2);
main.variable().define("c", ["a", "b"], (a, b) => a + b);

console.log(Array.from(main._scope.keys())) // ["a", "b", "c"]

```

[Here’s this in action](https://observablehq.com/d/cf29c7cac2c64e58).

But, you don’t have access to a notebook’s runtime from within the notebook itself. The autocomplete works in [observablehq.com](http://observablehq.com) because the notebook _editor_ has access to the runtime (I assume), but your code that you write does not. If you embed the notebook elsewhere, then you have more control, but not in the typical notebook at [observablehq.com](http://observablehq.com).

Overall I recommend [How Observable Runs](https://observablehq.com/@observablehq/how-observable-runs) to learn more about how the runtime/notebook cells work!

---

<div class="post-metadata">

**Author:** ![Real-John-Cheung](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/real-john-cheung/32/4489_2.png) [@Real-John-Cheung](https://talk.observablehq.com/u/Real-John-Cheung)\
**Post date:** [March 26, 2021, 3:45pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/3 "2021-03-26T15:45:19Z")

</div>

Thanks a lot!  
I have spent quite some time trying to get access to the ‘list’ 😂 seems that I have to change my approach

---

<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:** [March 26, 2021, 3:59pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/4 "2021-03-26T15:59:49Z")

</div>

There is no _officially-supported_ way, but you can get access to the notebook module from within the notebook with a kind of hack; see @mootari’s notebook for a demo:

> **[Runtime](https://observablehq.com/d/e1c39d41e8e944b0?ui=classic)**
>
> Based on an idea by Bryan Gin-ge Chen (which he explores in his notebook Dirty tricks). Disclaimer: The documentation found in this notebook must not be taken as fact. It's meant to be a "best effort" to dissect Observable's runtime. Presumably, our...

---

<div class="post-metadata">

**Author:** ![Real-John-Cheung](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/real-john-cheung/32/4489_2.png) [@Real-John-Cheung](https://talk.observablehq.com/u/Real-John-Cheung)\
**Post date:** [March 26, 2021, 4:13pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/5 "2021-03-26T16:13:35Z")

</div>

Thanks a lot! I am going to check it out now 🙂

---

<div class="post-metadata">

**Author:** ![dhowe](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/dhowe/32/4149_2.png) [@dhowe](https://talk.observablehq.com/u/dhowe)\
**Post date:** [March 28, 2021, 6:24am UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/6 "2021-03-28T06:24:29Z")

</div>

Does anyone know the thinking behind not providing module/runtime access from within a notebook (security issues perhaps) ? Seeing as access is _already_ available, via hacks like [@mootari](https://observablehq.com/d/e1c39d41e8e944b0?ui=classic) 's, it would be really nice if there was a clean way to do this…

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [April 15, 2021, 5:04pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/7 "2021-04-15T17:04:40Z")

</div>

@dhowe That would require providing official support, and would hinder changes to the internals. Same reason there’s no official API.

> Seeing as access is _already_ available

Take that statement with truckloads of salt. “Available” is definitely not the right choice of words here, given the nature of the hack, and its various gotchas.

---

<div class="post-metadata">

**Author:** ![dhowe](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/dhowe/32/4149_2.png) [@dhowe](https://talk.observablehq.com/u/dhowe)\
**Post date:** [May 19, 2021, 6:21pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/8 "2021-05-19T18:21:58Z")

</div>

This was (less than clearly) in relation to the question about security – that is, if the reason was security, then…

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [May 19, 2021, 6:42pm UTC](https://talk.observablehq.com/t/anyway-to-get-all-cells-names-on-a-notebook/4830/9 "2021-05-19T18:42:57Z")

</div>

I don’t think that security is a concern, since the notebook iframe is sandboxed and (with some minor exceptions like reporting content height, extracting the title and generating cell downloads) cannot affect the parent frame.

If people were to mess with the Runtime instance it could cause all sorts of stability issues which would be hard to trace, but would still be reported as bugs to the team. Therefore granting direct access to the Runtime would not really be an option.

Exposing this information will require careful planning of the appropriate API, and analysis of the potential side effects for different environments, like embeds. If you want to voice your demand for such a feature, I suggest you open a feature request on [Issues · observablehq/feedback · GitHub](https://github.com/observablehq/feedback/issues).
