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
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
conditionbooldatadynamic[]
Returns
Remarks
-Microsoft Edge's documentation for console.assert()
-Node.js documentation for console.assert()
-Google Chrome's documentation for console.dir()
Clear()
The console.clear() static method clears the console if possible.
[Value("clear")]
public GlobalObject.Undefined Clear()
Returns
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()
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
labelstring
Returns
Remarks
-Microsoft Edge's documentation for console.count()
-Node.js documentation for console.count()
-Google Chrome's documentation for console.count()
CountReset(string)
The console.countReset() static method resets counter used with Consolecount.
[Value("countReset")]
public GlobalObject.Undefined CountReset(string label = null)
Parameters
labelstring
Returns
Remarks
-Microsoft Edge's documentation for console.countReset()
-Node.js documentation for console.countReset()
-Google Chrome's documentation for console.countReset()
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
datadynamic[]
Returns
Remarks
-Microsoft Edge's documentation for console.debug()
-Node.js documentation for console.debug()
-Google Chrome's documentation for console.debug()
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
itemdynamicoptionsObject
Returns
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.
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()
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
datadynamic[]
Returns
Remarks
-Microsoft Edge's documentation for console.dirxml()
-Node.js documentation for console.dirxml()
-Google Chrome's documentation for console.dirxml()
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
datadynamic[]
Returns
Remarks
-Microsoft Edge's documentation for console.error()
-Node.js documentation for console.error()
-Google Chrome's documentation for console.error()
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
datadynamic[]
Returns
Remarks
-ConsolegroupEnd
-ConsolegroupCollapsed
-Microsoft Edge's documentation for console.group()
-Node.js documentation for console.group()
-Google Chrome's documentation for console.group()
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
datadynamic[]
Returns
Remarks
Call ConsolegroupEnd to back out to the parent group.
See Using groups in the console in the Console documentation for details and examples.
-Consolegroup
-ConsolegroupEnd
-Microsoft Edge's documentation for console.groupCollapsed()
-Node.js documentation for console.groupCollapsed()
-Google Chrome's documentation for console.groupCollapsed()
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
Remarks
-Consolegroup
-ConsolegroupCollapsed
-Microsoft Edge's documentation for console.groupEnd()
-Node.js documentation for console.groupEnd()
-Google Chrome's documentation for console.groupEnd()
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
datadynamic[]
Returns
Remarks
-Microsoft Edge's documentation for console.info()
-Node.js documentation for console.info()
-Google Chrome's documentation for console.info()
Log(params dynamic[])
The console.log() static method outputs a message to the console.
[Value("log")]
public GlobalObject.Undefined Log(params dynamic[] data)
Parameters
datadynamic[]
Returns
Remarks
-Microsoft Edge's documentation for console.log()
-Node.js documentation for console.log()
-Google Chrome's documentation for console.log()
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
Returns
Remarks
-Microsoft Edge's documentation for console.table()
-Node.js documentation for console.table()
-Google Chrome's documentation for console.table()
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
labelstring
Returns
Remarks
See Timers in the Console documentation for details and examples.
-See ConsoletimeLog and ConsoletimeEnd for examples
-Microsoft Edge's documentation for console.time()
-Node.js documentation for console.time()
-Google Chrome's documentation for console.time()
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
labelstring
Returns
Remarks
See Timers in the documentation for details and examples.
-See ConsoletimeLog for additional examples
-Consoletime
-Microsoft Edge's documentation for console.timeEnd()
-Node.js documentation for console.timeEnd()
-Google Chrome's documentation for console.timeEnd()
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
labelstringdatadynamic[]
Returns
Remarks
-Consoletime
-See ConsoletimeEnd for additional examples
-Node.js documentation for console.timeLog()
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
datadynamic[]
Returns
Remarks
NOTE
In some browsers,
console.trace()may also output the sequence of calls and asynchronous events leading to the currentconsole.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's documentation for console.trace()
-Node.js documentation for console.trace()
-Google Chrome's documentation for console.trace()
Warn(params dynamic[])
The console.warn() static method outputs a warning message to the console at the "warning" 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
datadynamic[]