-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Web Inspector Console Logging
Devin Rousso edited this page Dec 6, 2024
·
3 revisions
Console messages can be sent to the Web Inspector Console from a variety of places:
- from JavaScript
consolemethods- always
MessageSource::ConsoleAPI
- always
- in the WebProcess by calling
ScriptExecutionContext::addConsoleMessage- unless an
Inspector::ConsoleMessageis explicitly provided,MessageType::Logis used
- unless an
- in the UIProcess/GPUProcess by sending
Messages::WebPage::AddConsoleMessage- always
MessageType::Log
- always
- in the NetworkProcess by sending
Messages::NetworkProcessConnection::BroadcastConsoleMessage- always
MessageType::Log
- always
Console messages can be configured in a few ways:
-
MessageSourceindicates who/what is dispatching the console message (e.g.JScomes from the JavaScript language itself,ConsoleAPIcomes fromconsolemethods,CSScomes from CSSOM APIs or other CSS activity, etc.)- Although it may be tempting to just use
JSfor console messages created as a result of calling some JavaScript-exposed API, please use a more specificMessageSourceasJSis really meant for messages related to the JavaScript language itself. Feel free to create a newMessageSource(see below) if no existing one fits.
- Although it may be tempting to just use
-
MessageTypeindicates the function of the console message (e.g.Logwill log a message,Clearwill clear the Web Inspector Console, etc.)- You should use
Logunless there is special functionality/UI associated with your console message (e.g. starting performance profiling, clearing the console, etc.). EachMessageTypeessentially corresponds to a similarly namedconsolefunction.
- You should use
-
MessageLevelindicates the importance/severity of the message (e.g.Logis a basic log,Warningis for warnings, etc.) -
const String& messageis the string that is shown in the log (supports formatting/styling) -
unsigned long requestIdentifierassociates this console message with a particular network request in Web Inspector (if non-zero) -
const String& urlis the URL of the associated resource that dispatched this console message -
unsigned lineis the line number in the associated resource that dispatched this console message -
unsigned columnis the column number in the associated resource that dispatched this console message
Adding new sources/types/levels is possible by modifying all of the following:
- Web Inspector Backend (and the rest of WebKit)
-
Source/JavaScriptCore/runtime/ConsoleTypes.h
JSC::MessageSourceJSC::MessageTypeJSC::MessageLevel
-
Source/JavaScriptCore/runtime/ConsoleClient.cpp
static void appendMessagePrefix(StringBuilder&, JSC::MessageSource, JSC::MessageType, JSC::MessageLevel)
-
Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.mm
static NSString *stringForMessageSource(JSC::MessageSource)static NSString *stringForMessageLevel(JSC::MessageLevel)
-
Source/JavaScriptCore/runtime/ConsoleTypes.h
- Web Inspector Protocol
-
Source/JavaScriptCore/inspector/protocol/Console.json
ChannelSource-
ConsoleMessageleveltype
-
Source/JavaScriptCore/inspector/ConsoleMessage.cpp
static Inspector::Protocol::Console::ChannelSource messageSourceValue(JSC::MessageSource)static Inspector::Protocol::Console::ConsoleMessage::Type messageTypeValue(JSC::MessageType)static Inspector::Protocol::Console::ConsoleMessage::Level messageLevelValue(JSC::MessageLevel)
-
Source/JavaScriptCore/inspector/protocol/Console.json
- Web Inspector Frontend
-
Source/WebInspectorUI/UserInterface/Models/ConsoleMessage.js
WI.ConsoleMessage.MessageSourceWI.ConsoleMessage.MessageTypeWI.ConsoleMessage.MessageLevel
-
Source/WebInspectorUI/UserInterface/Models/IssueMessage.js
-
WI.IssueMessage(constructor)
-
-
Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js
- (controls how console messages are rendered)
-
Source/WebInspectorUI/UserInterface/Models/ConsoleMessage.js
Past Examples:
- 222692@main Web Inspector: provide a way to log messages from the network process
- 210079@main Web Inspector: provide a way to capture a screenshot of a node from within the page
- Web Inspector Backend (and the rest of WebKit)
-
Source/WebCore/inspector/agents/page/PageConsoleAgent.cpp
void PageConsoleAgent::getLoggingChannels(ErrorString&, RefPtr<JSON::ArrayOf<Inspector::Protocol::Console::ChannelSource>>&)
-
Source/WebCore/dom/Document.cpp
static MessageSource messageSourceForWTFLogChannel(const WTFLogChannel& channel)
-
Source/WebCore/inspector/agents/page/PageConsoleAgent.cpp
- Web Inspector Protocol
-
Source/JavaScriptCore/inspector/protocol/Console.json
ChannelSource
-
Source/JavaScriptCore/inspector/protocol/Console.json
- Web Inspector Frontend
-
Source/WebInspectorUI/UserInterface/Controllers/ConsoleManager.js
WI.ConsoleManager.prototype.initializeLogChannels
-
Source/WebInspectorUI/UserInterface/Models/LoggingChannel.js
-
WI.LoggingChannel(i.e. theconstructor)
-
-
Source/WebInspectorUI/UserInterface/Views/LogContentView.js
-
WI.LogContentView(i.e.constructor) WI.LogContentView.prototype._scopeFromMessageSourceWI.LogContentView.Scopes
-
-
Source/WebInspectorUI/UserInterface/Views/SettingsTabContentView.js
WI.SettingsTabContentView.prototype._createConsoleSettingsView
-
Source/WebInspectorUI/UserInterface/Controllers/ConsoleManager.js
Past Examples:
- 209160@main Add MSE logging configuration
- 194925@main Web Inspector: Enable WebKit logging configuration and display