コンソール API

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

メモ: この機能はウェブワーカー内で利用可能です。

コンソール API (Console API) には、開発者がデバッグ作業(メッセージ、コード内の設定点での変数の値、操作の完了にかかった時間などの記録)を実行できるようにする機能が用意されています。

概念と使用方法

コンソール API は、主に独自の API として始められ、さまざまなブラウザーでは、実装上の不整合はあったものの、実装が行われてきました。 Console API 仕様は、一貫した振る舞いを定義するために作成されました。 すべての最新のブラウザーは、最終的にこの振る舞いの実装に落ち着きましたが、一部の実装には独自の機能がまだ追加されています。 これらについては、次をご覧ください。

使用方法は非常に簡単です。console オブジェクトには、基本的なデバッグ作業を実行するために呼び出すことができる多くのメソッドが含まれており、通常はブラウザーのウェブコンソールにさまざまな値をログ出力することに焦点を当てています。

最も一般的に使用されるメソッドは console.log() で、特定の変数に含まれる現在の値を記録するために使用します。

インターフェイス

console

記録、スタックトレース、タイマー、カウンターなどの基本的なデバッグ機能を提供します。

js
let myString = "Hello world";

// "Hello world" をコンソールに出力
console.log(myString);

その他の例については、console のリファレンスページを参照してください。

仕様書

Specification
Console
# console-namespace

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
console
assert() static method
clear() static method
countReset() static method
count() static method
debug() static method
dir() static method
options.colors parameter
ExperimentalNon-standard
options.depth parameter
ExperimentalNon-standard
options.showHidden parameter
ExperimentalNon-standard
dirxml() static method
error() static method
exception() static method (an alias for error())
DeprecatedNon-standard
groupCollapsed() static method
groupEnd() static method
group() static method
info() static method
log() static method
profileEnd() static method
Non-standard
profile() static method
Non-standard
Substitution strings
table() static method
timeEnd() static method
timeLog() static method
timeStamp() static method
Non-standard
time() static method
trace() static method
warn() static method
Available in workers

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
User must explicitly enable this feature.
Has more compatibility info.

関連情報