Console API reference

The Console tool is helpful when you complete multiple tasks in the DevTools. APIs are available to include in your scripts. Convenience methods are only available for use in the Console tool, such as the debug() and monitorEvents() methods. For more information on getting started with the Console, navigate to Get started with logging messages to the Console. For more information on the convenience methods in the Console, navigate to Console Utilities API Reference.


assert

This method writes an error to the Console when expression evaluates to false.

JavaScript syntax

console.assert(expression, object)

Log level: Error

JavaScript example

Input

const x = 5;
const y = 3;
const reason = 'x is expected to be less than y';
console.assert(x < y, {x, y, reason});

Output


clear

This method clears the Console.

If Preserve Log is turned on, the clear method is turned off.

JavaScript syntax

console.clear()

JavaScript example

Input

console.clear();  

Output

See also


count

This method writes the number of times that the count method has been invoked at the same line and with the same label. Use the countReset method to reset the count.

JavaScript syntax

console.count([label])

Log level: Info

JavaScript example

Input

console.count();
console.count('coffee');
console.count();
console.count();

Output


countReset

This method resets a count.

JavaScript syntax

console.countReset([label])

JavaScript example

Input

console.countReset();
console.countReset('coffee');

Output


debug

This method is identical to the log method, except different log level.

JavaScript syntax

console.debug(object [, object, ...])

Log level: Verbose

JavaScript example

Input

console.debug('debug');  

Output


dir

This method prints a JSON representation of the specified object.

JavaScript syntax

console.dir(object)

Log level: Info

JavaScript example

Input

console.dir(document.head);

Output


dirxml

This method prints an XML representation of the descendants of node.

JavaScript syntax

console.dirxml(node)

Log level: Info

JavaScript example

Input

console.dirxml(document);

Output


error

This method prints the object to the Console, formats it as an error, and includes a stack trace.

JavaScript syntax

console.error(object [, object, ...])

Log level: Error

JavaScript example

Input

console.error("I'm sorry, Dave.  I'm afraid I can't do that.");

Output


group

This method visually groups messages together until the groupEnd method is used. Use the groupCollapsed method to collapse the group when it initially logs to the Console.

JavaScript syntax

console.group(label)

JavaScript example

Input

const label = 'Adolescent Irradiated Espionage Tortoises';
console.group(label);
console.info('Leo');
console.info('Mike');
console.info('Don');
console.info('Raph');
console.groupEnd(label);

Output


groupCollapsed

This method is identical to the log method, except the group is initially collapsed when it logs to the Console.

JavaScript syntax

console.groupCollapsed(label)

groupEnd

This method stops visually grouping messages. Navigate to the group method.

JavaScript syntax

console.groupEnd(label)

info

This method is identical to the log method.

JavaScript syntax

console.info(object [, object, ...])

Log level: Info

JavaScript example

Input

console.info('info');

Output


log

This method prints a message to the Console.

JavaScript syntax

console.log(object [, object, ...])

Log level: Info

JavaScript example

Input

console.log('log');

Output


table

This method logs an array of objects as a table.

JavaScript syntax

console.table(array)

Log level: Info

JavaScript example

Input

console.table([
{
first: 'René',
last: 'Magritte',
},
{
first: 'Chaim',
last: 'Soutine',
birthday: '18930113',
},
{
first: 'Henri',
last: 'Matisse',
}
]);

Output


time

This method starts a new timer. Use the timeEnd method to stop the timer and print the elapsed time to the Console.

JavaScript syntax

console.time([label])

JavaScript example

Input

console.time();
for (var i = 0; i < 100000; i++) {
let square = i ** 2;
}
console.timeEnd();

Output


timeEnd

This method stops a timer. For more information, navigate to the time method.

JavaScript syntax

console.timeEnd([label])

Log level: Info


trace

This method prints a stack trace to the Console.

JavaScript syntax

console.trace()

Log level: Info

JavaScript example

Input

const first = () => { second(); };
const second = () => { third(); };
const third = () => { fourth(); };
const fourth = () => { console.trace(); };
first();

Output


warn

This method prints a warning to the Console.

JavaScript syntax

console.warn(object [, object, ...])

Log level: Warning

JavaScript example

Input

console.warn('warn');

Output


Getting in touch with the Microsoft Edge DevTools team

Use the following options to discuss the new features and changes in the post, or anything else related to DevTools.

  • Send your feedback using the Send Feedback icon or select Alt+Shift+I (Windows, Linux) or Option+Shift+I (macOS) in DevTools.
  • Tweet at @EdgeDevTools.
  • Submit a suggestion to The Web We Want.
  • To file bugs about this article, use the following Feedback section.

The Send Feedback icon in the Microsoft Edge DevTools

Note

Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons Attribution 4.0 International License.
The original page is found here and is authored by Kayce Basques (Technical Writer, Chrome DevTools & Lighthouse).

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.