You need to sign in to do that
Don't have an account?
How to debug Aura Lightning components in browser?
I am looking for a way to make debugging of Aura Lightning components easier. For Apex we already have something called 'Apex Replay Debugger' which allows to see changes in values of variables and stepping through functions line by line.
Is there something similar for Aura components? Which can help see changes in values of <aura:attributes> and stepping through controller and helper methods.
To view changes in attribute values, I am currently console.log( )ing manually to broswer's console. But most of the time this method is unadequate or tiresome.
If anyone is aware of any tool, utility etc. which can act as a proper debugger for Aura Lightning component, then please do share. It will help a lot...
Is there something similar for Aura components? Which can help see changes in values of <aura:attributes> and stepping through controller and helper methods.
To view changes in attribute values, I am currently console.log( )ing manually to broswer's console. But most of the time this method is unadequate or tiresome.
If anyone is aware of any tool, utility etc. which can act as a proper debugger for Aura Lightning component, then please do share. It will help a lot...
General Tools and settings:
use Chrome + built-in Dev Tools + Lightning Component Inspector
be sure debug mode is enabled in your org (Setup: Lightning Components)
be sure caching is disabled in your org (Setup: Session Settings -> uncheck "Enable secure and persistent browser caching to improve performance"
Techniques for most common use cases (be sure that Dev Tools in Chrome are open while testing):
check certain JavaScript code is called at all:
use console.log(), console.debug(), console.warn(), console.error() (different color visualizations) -> can output a variable value as well
check for invalid values only:
rather always log to the console you can do console.assert(myVar != 0) to only show an error when assertion fails
evaluate variables / context on a certain JavaScript code:
use debugger; (this will create a breakpoint in code execution) -> now use the console from Dev Tools while breakpoint is active.
You can write JavaScript to test value of variables, do function calls and check return types, overwrite JavaScript values, and so on. This is super powerful also developing your code
output the value of a more complex Object:
while code execution is paused on a breakpoint (see above) use copy(JSON.stringify(myObjectToEvaluate)); in the Dev Tool console - this will copy the value as JSON to your clipboard and you can process/inspect text based value
measure code execution time between two dedicated "anchors": use console.time("identifier");
[code to execute]
console.timeEnd("identifier");
check why code can not be saved or application is not loading at all: use the Salesforce Lightning CLI to lint your JavaScript code (very useful to check against faulty structure like missing braces)
investigate runtime exceptions origin:
sometimes runtime exceptions show up you don't know exactly where they come from. Use "Pause on Exception"-Button under the "Sources"-Tab in Dev Tools - inside the panel "Call Stack" check if you can identify classes from your code.
As code execution is paused you have the same behavior as a manual breakpoint: on every entry, you are in the right JavaScript context so you can evaluate all values at that certain code execution time. Add some additional breakpoints (by clicking the line number in the Dev Tools) and you will always pause the code on a certain area (like to check what values are before the exception raises or pause on code you can't write a debugger-statement by yourself)
mock data returned from you Apex controller: use the Lightning Components Inspector "Action" Tab and overwrite the result coming back from the server the next time
For sure there are many more useful tools and scenarios, so it is definitely worse checking what Chrome Dev Tools (https://developers.google.com/web/tools/chrome-devtools?utm_source=dcc&utm_medium=redirect&utm_campaign=2018Q2) can do for you. Also what scenarios Lightning Component Inspector (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/inspector_intro.htm?search_text=inspector) is used for.
I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.
Thanks.
All Answers
General Tools and settings:
use Chrome + built-in Dev Tools + Lightning Component Inspector
be sure debug mode is enabled in your org (Setup: Lightning Components)
be sure caching is disabled in your org (Setup: Session Settings -> uncheck "Enable secure and persistent browser caching to improve performance"
Techniques for most common use cases (be sure that Dev Tools in Chrome are open while testing):
check certain JavaScript code is called at all:
use console.log(), console.debug(), console.warn(), console.error() (different color visualizations) -> can output a variable value as well
check for invalid values only:
rather always log to the console you can do console.assert(myVar != 0) to only show an error when assertion fails
evaluate variables / context on a certain JavaScript code:
use debugger; (this will create a breakpoint in code execution) -> now use the console from Dev Tools while breakpoint is active.
You can write JavaScript to test value of variables, do function calls and check return types, overwrite JavaScript values, and so on. This is super powerful also developing your code
output the value of a more complex Object:
while code execution is paused on a breakpoint (see above) use copy(JSON.stringify(myObjectToEvaluate)); in the Dev Tool console - this will copy the value as JSON to your clipboard and you can process/inspect text based value
measure code execution time between two dedicated "anchors": use console.time("identifier");
[code to execute]
console.timeEnd("identifier");
check why code can not be saved or application is not loading at all: use the Salesforce Lightning CLI to lint your JavaScript code (very useful to check against faulty structure like missing braces)
investigate runtime exceptions origin:
sometimes runtime exceptions show up you don't know exactly where they come from. Use "Pause on Exception"-Button under the "Sources"-Tab in Dev Tools - inside the panel "Call Stack" check if you can identify classes from your code.
As code execution is paused you have the same behavior as a manual breakpoint: on every entry, you are in the right JavaScript context so you can evaluate all values at that certain code execution time. Add some additional breakpoints (by clicking the line number in the Dev Tools) and you will always pause the code on a certain area (like to check what values are before the exception raises or pause on code you can't write a debugger-statement by yourself)
mock data returned from you Apex controller: use the Lightning Components Inspector "Action" Tab and overwrite the result coming back from the server the next time
For sure there are many more useful tools and scenarios, so it is definitely worse checking what Chrome Dev Tools (https://developers.google.com/web/tools/chrome-devtools?utm_source=dcc&utm_medium=redirect&utm_campaign=2018Q2) can do for you. Also what scenarios Lightning Component Inspector (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/inspector_intro.htm?search_text=inspector) is used for.
I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.
Thanks.
I have applied most of your suggested methods, and can say that they actually helped me a lot, and made debugging easier and faster.
Below I have summarized your suggestions for a quick look:
Feel free to add more of such suggestions in future. This can certainly help newbie developers like me, who are not much familiar with JS debugging techniques.
Hey everyone.
With the new update on Lightning Web Security, you also need to close this feature from session settings.
Setup: Session Settings -> uncheck "Use Lightning Web Security for Lightning web components and Aura components"