Table of Contents

Class console

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The console object provides access to the debugging console (e.g., the Web console in Firefox).

[Value("console")]
public class console
Inheritance
console
Inherited Members

Remarks

Implementations of the console API may differ between runtimes. In particular, some console methods may work differently or not work at all in some online editors and IDEs. To see the behavior described in this documentation, try the methods in your browser's developer tools, although even here, there are some differences between browsers.

The console object is available in any global scope. For example:

-Firefox Developer Tools
-Web console — how the Web console in Firefox handles console API calls
-about:debugging — how to see console output when the debugging target is a mobile device
-Google Chrome DevTools
-Microsoft Edge DevTools
-Safari Web Inspector

See also on MDN

Constructors

console()

public console()

Methods

Assert(bool, params dynamic[])

The console.assert() static method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

[Value("assert")]
public GlobalObject.Undefined Assert(bool condition = false, params dynamic[] data)

Parameters

condition bool
data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Clear()

The console.clear() static method clears the console if possible.

[Value("clear")]
public GlobalObject.Undefined Clear()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

A graphical console, like those in web browsers, will remove all previous messages; a console displaying on a terminal, like the one in Node.js, will attempt to clear it using an escape code or system API; otherwise the method will have no effect (and no error).

-Microsoft Edge's documentation for console.clear()
-Node.js documentation for console.clear()
-Google Chrome's documentation for console.clear()

See also on MDN

Count(string)

The console.count() static method logs the number of times that this particular call to count() has been called.

[Value("count")]
public GlobalObject.Undefined Count(string label = null)

Parameters

label string

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

CountReset(string)

The console.countReset() static method resets counter used with Consolecount.

[Value("countReset")]
public GlobalObject.Undefined CountReset(string label = null)

Parameters

label string

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Debug(params dynamic[])

The console.debug() static method outputs a message to the console at the "debug" log level. The message is only displayed to the user if the console is configured to display debug output. In most cases, the log level is configured within the console UI. This log level might correspond to the Debug or Verbose log level.

[Value("debug")]
public GlobalObject.Undefined Debug(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Dir(dynamic, Object?)

The console.dir() static method displays a list of the properties of the specified JavaScript object. In browser consoles, the output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

[Value("dir")]
public GlobalObject.Undefined Dir(dynamic item = null, Object? options = null)

Parameters

item dynamic
options Object

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Unlike other logging methods, console.dir() does not attempt to pretty-print the object. For example, if you pass a DOM element to console.dir(), it will not be displayed like in the element inspector, but will instead show a list of properties.

A screenshot of the Firefox console where console.dir(document.location) is run. We can see the URL of the page, followed by a block of properties. If the property is a function or an object, a disclosure triangle is prepended.

In runtimes like Node.js and Deno, where console output goes to the terminal and is therefore not interactive, the options parameter provides a way to customize the way the object is presented.

-Microsoft Edge's documentation for console.dir()
-Node.js documentation for console.dir()
-Google Chrome's documentation for console.dir()

See also on MDN

Dirxml(params dynamic[])

The console.dirxml() static method displays an interactive tree of the descendant elements of the specified XML/HTML element. If it is not possible to display as an element the JavaScript Object view is shown instead. The output is presented as a hierarchical listing of expandable nodes that let you see the contents of child nodes.

[Value("dirxml")]
public GlobalObject.Undefined Dirxml(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Error(params dynamic[])

The console.error() static method outputs a message to the console at the "error" log level. The message is only displayed to the user if the console is configured to display error output. In most cases, the log level is configured within the console UI. The message may be formatted as an error, with red colors and call stack information.

[Value("error")]
public GlobalObject.Undefined Error(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Group(params dynamic[])

The console.group() static method creates a new inline group in the Web console log, causing any subsequent console messages to be indented by an additional level, until ConsolegroupEnd is called.

[Value("group")]
public GlobalObject.Undefined Group(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

GroupCollapsed(params dynamic[])

The console.groupCollapsed() static method creates a new inline group in the console. Unlike Consolegroup, however, the new group is created collapsed. The user will need to use the disclosure button next to it to expand it, revealing the entries created in the group.

[Value("groupCollapsed")]
public GlobalObject.Undefined GroupCollapsed(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

GroupEnd()

The console.groupEnd() static method exits the current inline group in the console. See Using groups in the console in the Console documentation for details and examples.

[Value("groupEnd")]
public GlobalObject.Undefined GroupEnd()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Info(params dynamic[])

The console.info() static method outputs a message to the console at the "info" log level. The message is only displayed to the user if the console is configured to display info output. In most cases, the log level is configured within the console UI. The message may receive special formatting, such as a small "i" icon next to it.

[Value("info")]
public GlobalObject.Undefined Info(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Log(params dynamic[])

The console.log() static method outputs a message to the console.

[Value("log")]
public GlobalObject.Undefined Log(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Table(dynamic, List<string>)

The console.table() static method displays tabular data as a table.

[Value("table")]
public GlobalObject.Undefined Table(dynamic tabularData = null, List<string> properties = null)

Parameters

tabularData dynamic
properties List<string>

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Time(string)

The console.time() static method starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 10,000 timers running on a given page. When you call ConsoletimeEnd with the same name, the browser will output the time, in milliseconds, that elapsed since the timer was started.

[Value("time")]
public GlobalObject.Undefined Time(string label = null)

Parameters

label string

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

See Timers in the Console documentation for details and examples.

-See ConsoletimeLog and ConsoletimeEnd for examples
-Microsoft Edge&apos;s documentation for console.time()
-Node.js documentation for console.time()
-Google Chrome&apos;s documentation for console.time()

See also on MDN

TimeEnd(string)

The console.timeEnd() static method stops a timer that was previously started by calling Consoletime.

[Value("timeEnd")]
public GlobalObject.Undefined TimeEnd(string label = null)

Parameters

label string

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

TimeLog(string, params dynamic[])

The console.timeLog() static method logs the current value of a timer that was previously started by calling Consoletime.

[Value("timeLog")]
public GlobalObject.Undefined TimeLog(string label = null, params dynamic[] data)

Parameters

label string
data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

-Consoletime
-See ConsoletimeEnd for additional examples
-Node.js documentation for console.timeLog()

See also on MDN

Trace(params dynamic[])

The console.trace() static method outputs a stack trace to the console.

[Value("trace")]
public GlobalObject.Undefined Trace(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

NOTE

In some browsers, console.trace() may also output the sequence of calls and asynchronous events leading to the current console.trace() which are not on the call stack — to help identify the origin of the current event evaluation loop.

See Stack traces in the Console documentation for details and examples.

-Microsoft Edge&apos;s documentation for console.trace()
-Node.js documentation for console.trace()
-Google Chrome&apos;s documentation for console.trace()

See also on MDN

Warn(params dynamic[])

The console.warn() static method outputs a warning message to the console at the &quot;warning&quot; log level. The message is only displayed to the user if the console is configured to display warning output. In most cases, the log level is configured within the console UI. The message may receive special formatting, such as yellow colors and a warning icon.

[Value("warn")]
public GlobalObject.Undefined Warn(params dynamic[] data)

Parameters

data dynamic[]

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks