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

后端 未结 2 1770
夕颜
夕颜 2021-02-04 23:56

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

2条回答
  •  北海茫月
    2021-02-05 00:32

    You need to create the object in the Console itself, as the reference to the object needs to be maintained by Chrome. Just put the following into the console instead:

    {why:'dont', you:'work?'}
    

    If you check out this revision where the feature was added, it says:

    Adding ability to access objects from printed ObjectPropertySections (console, scopes pane and etc.).

    The problem, based on my understanding, is that console.log is outputting a string representation of the object, and just using object formatters to display it nicely. The object doesn't exist anymore. When you create an object through the console itself, Chrome is storing the object itself in memory. If you have paused on a breakpoint and have locally scoped variables, these can also be stored globally because they are also in memory.

    One thing you could do in your code, if you haven't got circular references is:

    console.log(JSON.stringify({why:'dont', you:'work?'}));
    > {"why":"dont","you":"work?"}
    

    In the Console, copy the output and paste it into a JSON.parse call:

    JSON.parse('{"why":"dont","you":"work?"}');
    > Object {why: "dont", you: "work?"}
    

    The variable exists now in memory so you can store it.

提交回复
热议问题