Console features reference

Kayce Basques
Kayce Basques
Sofia Emelianova
Sofia Emelianova

This page is a reference of features related to the Chrome DevTools Console. It assumes that you'realready familiar with using the Console to view logged messages and run JavaScript. If not, seeGetStarted.

If you're looking for the API reference on functions likeconsole.log() seeConsole APIReference. For the reference on functions likemonitorEvents() seeConsole Utilities APIReference.

Open the Console

You can open the Console as apanel or as atab in the Drawer.

Open the Console panel

PressControl+Shift+J orCommand+Option+J (Mac).

The Console.

To open the Console from theCommand Menu, start typingConsole and then run theShowConsole command that has thePanel badge next to it.

The command for showing the Console panel.

Open the Console in the Drawer

PressEscape or clickCustomize And Control DevToolsCustomize And Controls DevTools. and thenselectShow Console Drawer.

Show Console Drawer.

The Drawer pops up at the bottom of your DevTools window, with theConsole tab open.

The Console tab in the Drawer.

To open the Console tab from theCommand Menu, start typingConsole and then run theShowConsole command that has theDrawer badge next to it.

The command for showing the Console tab in the Drawer.

Open Console Settings

ClickSettings.Console Settings in the top-right corner of theConsole.

Key point: Not to be confused withSettings.DevTools Settings above and next to theThree-dot menu. three-dot menu.

Console Settings.

The links below explain each setting:

Open the Console Sidebar

ClickShow Console SidebarShow Console Sidebar. to showthe Sidebar, which is useful for filtering.

Console Sidebar.

View messages

This section contains features that change how messages are presented in the Console. SeeViewmessages for a hands-on walkthrough.

Disable message grouping

Open Console Settings and disableGroup similar to disable the Console's default messagegrouping behavior. SeeLog XHR and Fetch requests for an example.

View messages from breakpoints

TheConsole marks messages triggered by breakpoints in the following way:

The Console marks messages created by conditional breakpoints and logpoints.

To jump to theinline breakpoint editor in theSources panel, click the anchor link next to the breakpoint message.

View stack traces

TheConsole automatically captures stack traces for errors and warnings. A stack trace is a history of function calls (frames) that led to the error or warning. TheConsole shows them in reverse order: the latest frame is at the top.

To view a stack trace, click theExpand. expand icon next to an error or warning.

Stack traces.

View error causes in stack traces

TheConsole can show you chains oferror causes in the stack trace, if any.

To make debugging easier, you canspecify error causes when catching and rethrowing errors. As theConsole walks up the cause chain, it prints each error stack with aCaused by: prefix, so you can find the original error.

A chain of error causes prefixed with 'Caused by:' in the stack trace.

View async stack traces

If supported by the framework you are using or when directly using browser scheduling primitives, such assetTimeout, DevTools can trace async operations by linking both parts of the async code together.

In this case, the stack trace shows the "full story" of the async operation.

Async stack trace.

Key point: DevTools implements this "Async Stack Tagging" feature based on theconsole.createTask() API method.DevTools encourages frameworks and abstractions to use this API. For example,Angular supports this feature.

Show known third-party frames in stack traces

When source maps include theignoreList field, by default, theConsole hides from stack traces the third-party frames from sources generated by bundlers (for example, webpack) or frameworks (for example, Angular).

To view the full stack trace including third-party frames, clickShow N more frames at the bottom of the stack trace.

Show N more frames.

To always view the full stack trace, disable theSettings.Settings >Ignore List >Automatically add known third-party scripts to ignore list setting.

Automatically add known third-party scripts to ignore list.

Log XHR and Fetch requests

Open Console Settings and enableLog XMLHttpRequests to log allXMLHttpRequest andFetch requests to the Console as they happen.

Logging XMLHttpRequest and Fetch requests.

The top message in the example above shows the Console's default grouping behavior. The example below showshow the same log looks afterdisabling message grouping.

How the logged XMLHttpRequest and Fetch requests look after ungrouping.

Persist messages across page loads

By default the Console clears whenever you load a new page. To persist messages across page loads,Open Console Settings and then enable thePreserve Log checkbox.

Hide network messages

By default the browser logs network messages to theConsole. For example, the top message inthe following example represents a 404.

A 404 message in the Console.

To hide network messages:

  1. Open Console Settings.
  2. Enable theHide Network checkbox.

Show or hide CORS errors

TheConsole can showCORS errors if network requests fail due toCross-Origin Resource Sharing (CORS).

To show or hide CORS errors:

  1. Open Console Settings.
  2. Check or clear theShow CORS errors in the console checkbox.

Show CORS errors in the console.

If the console is set to show CORS errors and you encounter them, you can click the following buttons next to errors:

Network and Issues buttons.

Filter messages

There are many ways to filter out messages in the Console.

Filter out browser messages

Open the Console Sidebar and clickUser Messages to only show messages that came from thepage's JavaScript.

Viewing user messages.

Filter by log level

DevTools assigns most ofconsole.* methods severity levels.

There are four levels:

  • Verbose
  • Info
  • Warning
  • Error

For example,console.log() is in theInfo group, whereasconsole.error() is in theError group. TheConsole API Reference describes the severitylevel of each applicable method.

Every message that the browser logs to the Console has a severitylevel too. You can hide any level of messages that you're not interested in. For example, if you'reonly interested inError messages, you can hide the other 3 groups.

Click theLog Levels drop-down to enable or disableVerbose,Info,Warning orErrormessages.

The Log Levels drop-down.

You can also filter by log level byShow Console Sidebar.opening the Console Sidebar and then clickingErrors,Warnings,Info, orVerbose.

Using the Sidebar to view warnings.

Filter messages by URL

Typeurl: followed by a URL to only view messages that came from that URL. After you typeurl:DevTools shows all relevant URLs.

A URL filter.

Domains also work. For example, ifhttps://example.com/a.js andhttps://example.com/b.js are logging messages,url:https://example.com enables you to focus onthe messages from these 2 scripts.

To hide all messages from a specified URL, type-url: followed by the URL, for example,https://b.wal.co. This is a negative URL filter.

A negative URL filter. DevTools is hiding all messages that match the specified URL.

You can also show messages from a single URL byopening the Console Sidebar, expanding theUser Messages section, and then clicking the URL of the script containing the messages you wantto focus on.

Viewing the messages from a specific script.

Filter out messages from different contexts

Suppose that you've got an ad on your page. The ad is embedded in an<iframe> and is generating alot of messages in your Console. Because this ad is in a differentJavaScript context, one wayto hide its messages is toopen Console Settings and enable theSelected Context Onlycheckbox.

Filter out messages that don't match a regular expression pattern

Type a regular expression such as/[foo]\s[bar]/ in theFilter text box to filter out anymessages that don't match that pattern. Spaces are not supported, use\s instead. DevTools checks if the pattern is found in the message textor the script that caused the message to be logged.

For example, the following filters out all messages that don't match/[gm][ta][mi]/.

Filtering out any messages that don't match /[gm][ta][mi]/.

Search for text in logs

To search for text in log messages:

  1. To open a built-in search bar, pressCommand+F (Mac) orCtrl+F (Windows, Linux).
  2. In the bar, type your query. In this example the query islegacy.Typing a query.Optionally, you can:
    • ClickMatch case.Match Case to make your query case-sensitive.
    • ClickRegEx button.Use Regular Expression to search using a RegEx expression.
  3. PressEnter. To jump to previous or next search result, press the up or down button.

Run JavaScript

This section contains features related to running JavaScript in the Console. SeeRunJavaScript for a hands-on walkthrough.

String copy options

The console outputs strings as valid JavaScript literals by default. Right-click an output and choose between three copy options:

  • Copy as JavaScript literal. Escapes appropriate special characters and wraps the string in either single quotes, double quotes,or backticks depending on the content.
  • Copy string contents. Copies the exact raw string to the clipboard, including new lines and other special characters.
  • Copy as JSON literal. Formats the string to valid JSON.

The copy options.

Re-run previous expressions and clear history

Press theUp Arrow key to cycle through the history of JavaScript expressions that youran earlier in theConsole. PressEnter to run that expression again.

To clear the console history, right-click an empty space in theConsole and selectClear console history from the context menu.

Clear, copy, and save messages

To clear theConsole window, do one of the following:

  • ClickblockClear console in the action bar at the top.
  • PressCtrl+L orCmd+K.
  • Right-click an empty space in theConsole and selectClear console from the context menu.

The right-click context menu.

From the context menu, you can also:

  • Copy console: Copy all current messages to clipboard, but not thehistory of previous commands.
  • Save as...: Save all current messages to a plaintext.log file.

Watch an expression's value in real-time with Live Expressions

If you find yourself typing the same JavaScript expression in the Console repeatedly, you might findit easier to create aLive Expression. WithLive Expressions, you type an expression once andthen pin it to the top of your Console. The value of the expression updates in near real-time. SeeWatch JavaScript Expression Values In Real-Time With Live Expressions.

Disable Eager Evaluation

As you type JavaScript expressions in the Console,Eager Evaluation shows a preview of thatexpression's return value.Open Console Settings and disable theEager Evaluation checkboxto turn off the return value previews.

Trigger user activation with evaluation

User activation is the state of a browsing session that depends on user actions. An "active" state means the user is currently interacting with the page or has interacted since page load.

To trigger user activation with any evaluation,open Console Settings andcheckCheckbox.Treat code evaluation as user action.

Disable autocomplete from history

As you type out an expression, the Console's autocomplete popup shows expressions that you ranearlier. These expressions are prepended with the> character. In the following example, DevTools earlier evaluateddocument.querySelector('a') anddocument.querySelector('img').

The autocomplete popup showing expressions from history.

Open Console Settings anddisable theAutocomplete From History checkbox to stop showing expressions from your history.

Select JavaScript context

By default theJavaScript Context drop-down is set totop, which represents the maindocument'sbrowsing context.

The JavaScript Context drop-down.

Suppose you have an ad on your page embedded in an<iframe>. You want to run JavaScript in orderto tweak the ad's DOM. To do this, you first need to select the ad's browsing context from theJavaScript Context drop-down.

Selecting a different JavaScript context.

Inspect object properties

TheConsole can display an interactive list of properties of a JavaScript object you specify.

To browse the list, type the object name into theConsole and pressEnter.

To inspect the properties of DOM objects, follow the steps inView the properties of DOM objects.

Spot own and inherited properties

TheConsole sorts own object properties first and highlights them in bold font.

Displaying object properties.

Properties inherited from the prototype chain are in regular font. TheConsole displays them on the object itself by evaluating the corresponding native accessors of built-in objects.

Displaying inherited properties.

Evaluate custom accessors

By default, DevTools doesn't evaluate accessors you create.Custom accessor.To evaluate a custom accessor on an object, click(...).Evaluated custom accessor.

Spot enumerable and non-enumerable properties

Enumerable properties are bright in color. Non-enumerable properties are muted.Enumerable and non-enumerable properties.Enumerable properties can be iterated over with thefor … in loop orObject.keys() method.

Spot private properties of class instances

TheConsole designatesprivate properties of class instances with a# prefix.

Private property of a class instance.

TheConsole can also autocomplete private properties even when you evaluate them ouside the class scope.

Private property autocompletion.

Inspect internal JavaScript properties

Borrowing theECMAScript notation, theConsole encloses some properties internal to JavaScript in double square brackets. You can't interact with such properties in your code. However, it might be useful to inspect them.

You might see the following internal properties on different objects:

Inspect functions

In JavaScript, functions are also objects with properties. However, if you type a function name into theConsole, DevTools calls it instead of displaying its properties.

To view function properties internal to JavaScript, use theconsole.dir() command.

Inspecting properties of a function.

Functions have the following properties:

  • [[FunctionLocation]]. A link to the line with the function definition in a source file.
  • [[Scopes]]. Lists values and expressions the function has access to. To inspect function scopes during debugging, seeView and edit local, closure, and global properties.
  • Bound functions have the following properties:
    • [[TargetFunction]]. The target ofbind().
    • [[BoundThis]]. The value ofthis.
    • [[BoundArgs]]. An array of function arguments.Bound function.
  • Generator functions are marked with a[[IsGenerator]]: true property.Generator function.
  • Generators return iterator objects and they have following properties:
    • [[GeneratorLocation]]. A link to a line with the generator definition in a source file.
    • [[GeneratorState]]:suspended,closed, orrunning.
    • [[GeneratorFunction]]. The generator that returned the object.
    • [[GeneratorReceiver]]. An object that receives the value.Iterator object.

Clear the Console

You can use any of the following workflows to clear the Console:

  • ClickClear ConsoleClear..
  • Right-click a message and then selectClear Console.
  • Typeclear() in the Console and then pressEnter.
  • Callconsole.clear() from your webpage's JavaScript.
  • PressControl+L while the Console is in focus.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2019-04-18 UTC.