Skip to content

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 console methods
    • always MessageSource::ConsoleAPI
  • in the WebProcess by calling ScriptExecutionContext::addConsoleMessage
    • unless an Inspector::ConsoleMessage is explicitly provided, MessageType::Log is used
  • in the UIProcess/GPUProcess by sending Messages::WebPage::AddConsoleMessage
    • always MessageType::Log
  • in the NetworkProcess by sending Messages::NetworkProcessConnection::BroadcastConsoleMessage
    • always MessageType::Log

Console messages can be configured in a few ways:

  • MessageSource indicates who/what is dispatching the console message (e.g. JS comes from the JavaScript language itself, ConsoleAPI comes from console methods, CSS comes from CSSOM APIs or other CSS activity, etc.)
    • Although it may be tempting to just use JS for console messages created as a result of calling some JavaScript-exposed API, please use a more specific MessageSource as JS is really meant for messages related to the JavaScript language itself. Feel free to create a new MessageSource (see below) if no existing one fits.
  • MessageType indicates the function of the console message (e.g. Log will log a message, Clear will clear the Web Inspector Console, etc.)
    • You should use Log unless there is special functionality/UI associated with your console message (e.g. starting performance profiling, clearing the console, etc.). Each MessageType essentially corresponds to a similarly named console function.
  • MessageLevel indicates the importance/severity of the message (e.g. Log is a basic log, Warning is for warnings, etc.)
  • const String& message is the string that is shown in the log (supports formatting/styling)
  • unsigned long requestIdentifier associates this console message with a particular network request in Web Inspector (if non-zero)
  • const String& url is the URL of the associated resource that dispatched this console message
  • unsigned line is the line number in the associated resource that dispatched this console message
  • unsigned column is 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:

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

Automatic Logging from WTFLogChannel

Past Examples:

  • 209160@main Add MSE logging configuration
  • 194925@main Web Inspector: Enable WebKit logging configuration and display

Clone this wiki locally