Node.js – Chrome DevTools error: “Failed to save to temp variable.”

google-chromegoogle-chrome-devtoolsnode.js

I am using Node Monkey to debug my NodeJS app.

It happens frequently that when I click "Store as Global Variable" in my Chrome Console it says "Failed to save to temp variable."

enter image description here

console.log({why:'dont', you:'work?'})

It happens also in this jsfiddle

1) Am I doing something wrong?

2) Why this happens?

Chrome: 50.0.2661.102 (64-bit)
OSX El Capitan 10.11.4

Best Answer

I can see two reasons why Store As Global Variable wouldn't work:

1. Wrong Console Context Selected

This is arguably a Chrome bug, but you can only store an object as a global if the console is set to the same context as the code that logged the object.

In practice this means you might need to select the correct IFrame or web worker.

For example, on jsFiddle:

In the normal jsFiddle editor page context I'm getting an error. But it works if I change the context to the contents of the fiddle itself:

2. Garbage Collection

In order for Chrome to give you a reference to the object the object still has to be in memory. If that isn't the case it can only throw an error.

However, I'm pretty sure that being shown in the console forces V8 to keep a reference to the value.