30

This may be a very basic questions, but I don't seem to find the answer for it! Basically I want my console.log statements to show all the good stuff instead of the LockerService Proxy object. Is there a way to do that without setting the API version to lower than 40.0? Even then I'm not sure if that'll do it.

For now I'm using JSON stringify.

1
  • could you provide more details on which objects are wrapped in proxies? I think this could be handled with a customDevtoolFormatter but I'd need more info (I'm not very familiar with the LockerService)
    – NSjonas
    Apr 23, 2019 at 7:54

4 Answers 4

29

This will get it out of proxy and back into nice, readable format.

console.log(JSON.parse(JSON.stringify(myObject)));

Used it so much I made a snippet of it (vscode, sublime, maybe others)

"xlog": {
    "prefix": "xlog",
    "body": [
        "console.log(JSON.parse(JSON.stringify(${1:var}));"
    ],
    "description": "logs json stuff through proxy"
2
  • This is one of the most useful tricks I've seen in recent memory. Feb 11, 2019 at 19:44
  • Yes... one wonders why this is not a function in inspector... I think Google wants us to use the debugger...
    – Joeri
    May 14, 2021 at 10:31
16

Here is how I generally work in chrome when i see a proxy object,

Use the chrome "store as global variable" on the proxy object as shown in the below screenshot

enter image description here

Then I just use the Javascript object.keys() and add a bit of Javascript in the console like below to print keys

for (let key of Object.keys(temp1)) {
        console.log(key + temp1);
}

That gets me what I need and then most of the times , I just have to rely on JSON.stringify() to see the output .

enter image description here

1
  • Thanks Mohith. That's pretty much my current approach except I am doing all of this right inside of the controller. But a sizeable benefit of your approach is that I don't have to jump back and forth to code. I like it.
    – Mossi
    Feb 8, 2018 at 7:20
2

I did everything above but nothing worked so I tried to look at the setup. Found this solution:

From Setup go to Session Settings and look for Lightning Web Security and under that is the Use Lightning Web Security for Lightning web components checkbox. Disable the checkbox and the console logs should be showing the structured JSON instead of proxy.

enter image description here

1
  • This is something new we recently got in the latest release. Nov 2, 2022 at 8:49
1

For those with Lightning Web Security switched on and who want to see the real values contained in console logged proxy objects you must first switch on the Enable custom formatters feature in Chrome DevTools. This is documented here.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .