Reputation: 131
Two Questions about debugging in chrome console :
function say(){ console.log("hello"); console.log("test"); }
I want to set breakpoints,etc..
And how can I do a tab in a console for indention?
Thank you.
Upvotes: 13
Views: 9653
Reputation: 23858
Now you can write functions and debug them in Chrome console directly.
**Chrome Dev Tools -> Sources -> Snippets
You can write any code there, set breakpoints and hit Ctrl + Enter to run it.
Upvotes: 8
Reputation: 108
You can try this trick, navigate to the following
Chrome Dev Tools -> Sources -> Snippet -> New snippet
Give it a name to the snippet, And add the script in the editor (right side panel) then save it with CTRL + S.
Now that your snippet is added, you can right click on the newly added snippet and click on -> Run
Add the breakpoint and call the method, once debugging is done you can remove the snippet, Incase, if you have trouble creating Snippet check this link
Upvotes: 0
Reputation: 143
Snippet can also be used for this purpose. Though snippets are shared across pages and run from the context of current open page but can be used for this purpose as well.
https://developers.google.com/web/tools/chrome-devtools/snippets
Upvotes: 0
Reputation: 2998
Just to complement the given answer by Kevin, here is the deal:
the command debugger;
will trigger the PAUSE into debugger sources window.
You may change your function to
function say(){
debugger;
console.log("hello");
console.log("test");
}
and next time you execute the function say()
it will pause at the beginning.
You may also type debugger;say();
in the console because it will pause before calling the function say() but you have to press F11 to Setp Into The Next Function
Upvotes: 3
Reputation: 2893
debugger;say()
in your console, and then press F11 twice, you will be navigated to a VMxxxx tab, you can add breakpoints there and it will be kept.
i.e. next time you run say()
in the console, the breakpoint will be triggered.
Shift+Enter
to open a new line and ident with spaces, or copy a "tab" from somewhere else (a text editor) and paste it in chrome.Upvotes: 16