In 2014, it was not possible for JS code to access variables inside a closure from outside the closure. Since then, Chrome's internals have changed to use [[Scopes]]
instead of Closure
.
Is it now (2018) possible for Chrome DevTools to read [[Scopes]]
programmatically? If so, is there an existing DevTools extension that does so?
Use case: inspecting variables inside a UMD module loaded using RequireJS. I know I can do this at a breakpoint or debugger
statement using the Scopes
panel, but would like to be able to do so even when I am not at a breakpoint.
Edit As of 2017, it was not possible to access [[FunctionLocation]]
, but I don't know about [[Scopes]]
.
Attempts
I have investigated the following without success (module factory function name main
):
- This comment mentions
console.dir()
, but there is no programmatic access to the output ofconsole.dir()
. I can useconsole.dir({main})
and then expand the results manually, but not programmatically. From the DevTools console, I can use
inspect({function})
per this. That gets me closer, but not to[[Scopes]]
:> var x = inspect({main}) > x.main.name ← "main" > x.main[Symbol('Scopes')] ← undefined > x.main['[[Scopes]]'] ← undefined
The chrome.devtools.inspectedWindow API provides an
eval
method that can useinspect
. However, I can't get from theinspect
results to[[Scopes]]
, as noted above.
Notes
- Posting a new question rather than bumping the 2014 one as suggested by this Meta answer
- Different from this question because I am trying to access module internals rather than the public module interface