Discover new debugging workflows with this comprehensive reference of Chrome DevTools debugging features.
See Get Started With Debugging JavaScript In Chrome DevTools to learn the basics of debugging.
Set a breakpoint so that you can pause your code in the middle of its execution. To learn how to set breakpoints, see Pause Your Code With Breakpoints.
While the execution is paused, the debugger evaluates all variables, constants, and objects within the current function up to a breakpoint. The debugger shows the current values inline next to the corresponding declarations.
You can use the Console to query the evaluated variables, constants, and objects.
While the execution is paused, hover over a class or function name to preview its properties.
Once your code is paused, step through it, one expression at a time, investigating control flow and property values along the way.
When paused on a line of code containing a function that's not relevant to the problem you're debugging, click Step overstep_over to execute the function without stepping into it.
For example, suppose you're debugging the following code:
functionupdateHeader(){ varday=newDate().getDay(); varname=getName();// A updateName(name);// D}functiongetName(){ varname=app.first+' '+app.last;// B returnname;// C}
You're paused on A
. Once you've pressed step_over, DevTools executes all the code in the function that you're stepping over, which is B
and C
. DevTools then pauses on D
.
When paused on a function call that is related to the problem you're debugging, click Step into to investigate that function.
For example, suppose you're debugging the following code:
functionupdateHeader(){ varday=newDate().getDay(); varname=getName();// A updateName(name);}functiongetName(){ varname=app.first+' '+app.last;// B returnname;}
You're paused on A
. By pressing Step into, DevTools executes this line of code, then pauses on B
.
When paused inside of a function that is not related to the problem you're debugging, click step_out to execute the rest of the function's code.
For example, suppose you're debugging the following code:
functionupdateHeader(){ varday=newDate().getDay(); varname=getName(); updateName(name);// C}functiongetName(){ varname=app.first+' '+app.last;// A returnname;// B}
You're paused on A
. By clicking step_out, DevTools executes the rest of the code in getName()
, which is just B
in this example, and then pauses on C
.
When debugging a long function, there may be a lot of code that is not related to the problem you're debugging.
You could step through all the lines, but that can be tedious. You could set a line-of-code breakpoint on the line you're interested in and then press resume, but there's a faster way.
Right-click the line of code that you're interested in, and select Continue to here. DevTools runs all of the code up to that point, and then pauses on that line.
To continue your script's execution after a pause, click resume. DevTools executes the script up until the next breakpoint, if any.
To ignore all breakpoints and force your script to resume execution, click and hold Resume Script Executionresume and then select Force script executionplay_arrow.
When working with web workers or service workers, click a context listed in the Threads pane to switch to that context. The blue arrow icon represents which context is selected.
For example, suppose that you're paused on a breakpoint in both your main script and your service worker script. You want to view the local and global properties for the service worker context, but the Sources panel is showing the main script context. By clicking on the service worker entry in the Threads pane, you'd be able to switch to that context.
You can debug minified code by stepping through comma-separated expressions. For example, consider the following code:
functionfoo(){}functionbar(){foo();foo();return42;}bar();
When minified, it contains a comma-separated foo(),foo(),42
expression:
functionfoo(){}functionbar(){returnfoo(),foo(),42}bar();
The Debugger steps through such expressions just the same.
Therefore, the stepping behavior is identical:
While paused on a line of code, use the Scope pane to view and edit the values of properties and variables in the local, closure, and global scopes.
While paused on a line of code, use the Call Stack pane to view the call stack that got you to this point.
Select an entry to jump to the line of code where that function was called. The blue arrow icon represents which function DevTools is highlighting.
To observe the behavior of a function and re-run it without having to restart the entire debugging flow, you can restart the execution of a single function when this function is paused. In other words, you can restart the function's frame in the call stack.
To restart a frame:
In the Call Stack pane, right-click a function and select Restart frame from the drop-down menu.
To understand how Restart frame works, consider the following:
functionfoo(value){console.log(value);bar(value);}functionbar(value){value++;console.log(value);debugger;}foo(0);
The foo()
function takes 0
as an argument, logs it, and calls the bar()
function. The bar()
function, in turn, increments the argument.
Try restarting the frames of both functions as follows:
Copy the example code to a new snippet and run it. The execution stops at the debugger
line-of-code breakpoint.
Notice that the debugger shows you the current value next to function declaration: value = 1
.
Restart the bar()
frame.
Step through the value increment statement by pressing F9
. Notice that the current value increases:
value = 2
.
Optionally, in the Scope pane, double-click the value to edit it and set the desired value.
Try restarting the bar()
frame and stepping through the increment statement several more times. The value continues to increase.
Restart the foo()
frame in the Call Stack. Notice that the value is
0
again.
Resume script execution (F8
) to complete this tutorial.
By default, the Call Stack pane shows only the frames that are relevant to your code and omits any scripts added to settingsSettings > Ignore List.
To view the full call stack including third-party frames, enable Show ignore-listed frames under the Call Stack section.
Try it in this demo:
src
> app
> app.component.ts
file.increment()
function.If supported by the framework you are using, DevTools can trace async operations by linking both parts of the async code together.
In this case, the Call Stack shows the entire call history including async call frames.
Key Point DevTools implements this "Async Stack Tagging" feature based on the console.createTask()
API method. It's up to frameworks to implement the API. For example, Angular supports this feature.
Right-click anywhere in the Call Stack pane and select Copy stack trace to copy the current call stack to the clipboard.
Here is an example of the output:
getNumber1(get-started.js:35)inputsAreEmpty(get-started.js:22)onClick(get-started.js:15)
Use the Page pane to navigate the file tree.
When developing web applications using frameworks (for example, React or Angular), it can be difficult to navigate sources due to the minified files generated by the build tools (for example, webpack or Vite).
To help you navigate sources, the Sources > Page pane can group the files into two categories:
To enable grouping, click more_vert > Group files by Authored/Deployed option, under the menu at the top of the file tree.
To help you focus only on the code you create, the Sources > Page pane grays out all scripts or directories added to settingsSettings > Ignore List by default.
To hide such scripts altogether, select Sources > Page > more_vert > Hide ignore-listed sources.
Ignore a script to skip it while debugging. When ignored, a script is obscured in the Call Stack pane, and you never step into the script's functions when you step through your code.
For example, suppose you're stepping through this code:
functionanimate(){ prepare(); lib.doFancyStuff();// A render();}
A
is a third-party library that you trust. If you're confident that the problem you're debugging is not related to the third-party library, then it makes sense to ignore the script.
To ignore an individual script or an entire directory:
If you didn't hide ignore-listed sources, you can select such a source in the file tree and, on the warning warning banner, click Remove from ignored list or Configure.
Otherwise, you can remove hidden and ignored directories and scripts from the list in settingsSettings > Ignore List.
To ignore a script from the Editor pane:
You can remove a script from the list of ignored from settingsSettings > Ignore List.
To ignore a script from the Call Stack pane:
You can remove a script from the list of ignored from settingsSettings > Ignore List.
See settingsSettings > Ignore List.
If you find yourself running the same debug code in the Console over and over, consider Snippets. Snippets are executable scripts that you author, store, and run within DevTools.
See Run Snippets of Code From Any Page to learn more.
Use the Watch pane to watch the values of custom expressions. You can watch any valid JavaScript expression.
When you open a script in the Page pane, DevTools shows you its contents in the Editor pane. In the Editor pane, you can browse and edit your code.
Additionally, you can override the contents locally or create a workspace and save the changes you make in DevTools directly to your local sources.
By default, the Sources panel pretty-prints minified files. When pretty-printed, the Editor may show a single long code line in multiple lines, with -
to indicate that it's the line continuation.
To see the minified filed as it was loaded, click data_object in the bottom left corner of the Editor.
To fold a code block, hover over the line number in the left column and click arrow_drop_downCollapse.
To unfold the code block, click {...}
next to it.
To configure this behavior, see settingsSettings > Preferences > Sources.
When fixing a bug, you often want to test out some changes to your JavaScript. You don't need to make the changes in an external browser and then reload the page. You can edit your script in DevTools.
To edit a script:
Press Command+S (Mac) or Ctrl+S (Windows, Linux) to save. DevTools patches the entire JavaScript file into Chrome's JavaScript engine.
While the execution is paused, you can edit the current function and apply changes live with the following limitations:
To live-edit a function:
Watch the video to learn this workflow.
In this example, the addend1
and addend2
variables initially have an incorrect string
type. So, instead of adding numbers, the strings are concatenated. To fix it, the parseInt()
functions are added during live editing.
To search for text in a script:
To replace the text you found:
See Disable JavaScript With Chrome DevTools.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2017-01-04 UTC.