log.entryAdded eventThe log.entryAdded event of the log module fires when a new log entry is created in the browser, from either a console API call or an unhandled JavaScript error.
The params field in the event notification is a log entry object. Based on the source of the log, the log entry object has different types: "console" or "javascript". Each type may provide additional fields specific to that source.
All log entry objects include the following fields:
levelA string that indicates the severity of the log entry. It has one of the following values:
"debug": A debug-level message (from console.debug() or console.trace())."info": An informational message (from console.log(), console.info(), and other console methods that don't produce a more specific level)."warn": A warning message (from console.warn())."error": An error message (from console.error() or console.assert()).sourceAn object that identifies the realm where the log entry was created. It contains the following fields:
realmA string that contains the ID of the realm.
context OptionalA string that contains the ID of the context in which the log entry was created.
userContext OptionalA string that contains the ID of the user context in which the script-related event occurred.
stackTrace OptionalAn object with a callFrames array that represents the JavaScript stack at the point the entry was created. Each item in the array is a stack frame with the following fields: columnNumber, functionName, lineNumber, and url.
textA string that contains the log message or null if not available. For console entries, it is the concatenation of all stringified arguments joined by spaces, and for JavaScript errors, it is generally the error message. The exact format is browser-dependent, so don't rely on this value for assertions in tests.
timestampA non-negative integer that represents the time when the log entry was created, as milliseconds elapsed since the epoch (Date.now()).
typeA string that identifies the source of the log entry. It has one of the following values:
"console": Indicates that the log entry was generated from a call to a console API method (for example, console.log(), console.warn()). Log entry objects of this type include additional fields."javascript": Indicates that the log entry was generated from an unhandled JavaScript error."console" log entry fieldsIn addition to the common fields, log entry objects with "type": "console" also include:
argsAn array of objects that represent the arguments passed to the console method. Each object has a type field (such as "string", "number", "boolean", or "array") and optional value, handle, and internalId fields.
methodA string that contains the name of the console method that was called (for example, "log", "error", "assert", "debug", "trace", "warn").
With a WebDriver BiDi connection and a subscription to log.entryAdded active, the browser sends a log.entryAdded event when a script evaluates console.log("hello", [1, true, "foo"]):
{
"type": "event",
"method": "log.entryAdded",
"params": {
"type": "console",
"method": "log",
"source": {
"realm": "7c37f4c0-abcd-1234-ef56-789012345678",
"context": "6B3D5B3A-6571-432B-8E96-E53B5C2ECBB5"
},
"args": [
{
"type": "string",
"value": "hello"
},
{
"type": "array",
"value": [
{ "type": "number", "value": 1 },
{ "type": "boolean", "value": true },
{ "type": "string", "value": "foo" }
]
}
],
"level": "info",
"text": "hello 1,true,foo",
"timestamp": 1712345678901,
"stackTrace": {
"callFrames": [
{
"columnNumber": 8,
"functionName": "",
"lineNumber": 1,
"url": "https://example.com/app.js"
}
]
}
}
}With a WebDriver BiDi connection and a subscription to log.entryAdded active, the browser sends a log.entryAdded event when a script evaluates console.warn("something went wrong"):
{
"type": "event",
"method": "log.entryAdded",
"params": {
"type": "console",
"method": "warn",
"source": {
"realm": "7c37f4c0-abcd-1234-ef56-789012345678",
"context": "6B3D5B3A-6571-432B-8E96-E53B5C2ECBB5"
},
"args": [
{
"type": "string",
"value": "something went wrong"
}
],
"level": "warn",
"text": "something went wrong",
"timestamp": 1712345678950,
"stackTrace": {
"callFrames": [
{
"columnNumber": 8,
"functionName": "",
"lineNumber": 1,
"url": "https://example.com/app.js"
}
]
}
}
}With a WebDriver BiDi connection and a subscription to log.entryAdded active, the browser sends a log.entryAdded event when an unhandled JavaScript error occurs:
{
"type": "event",
"method": "log.entryAdded",
"params": {
"type": "javascript",
"level": "error",
"source": {
"realm": "7c37f4c0-abcd-1234-ef56-789012345678",
"context": "6B3D5B3A-6571-432B-8E96-E53B5C2ECBB5"
},
"text": "ReferenceError: undefinedVariable is not defined",
"timestamp": 1712345679100,
"stackTrace": {
"callFrames": [
{
"columnNumber": 27,
"functionName": "",
"lineNumber": 3,
"url": "https://example.com/app.js"
},
{
"columnNumber": 18,
"functionName": "",
"lineNumber": 3,
"url": "https://example.com/app.js"
}
]
}
}
}session.subscribe commandconsole API