You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does Runtime.consoleAPICalled log something that Log.enable doesn't currently catch? All of the logging events should already be captured by the existing Log.entryAdded events (Console is still there just for backwards compatibility)
Log.enable collects the browser-caused messages, e.g., messages about invalid headers such as (Error with Permissions-Policy header: Unrecognized feature: 'abc').
Runtime.consoleAPICalled collects the developer-caused messages from the console API, e.g., console.log("Log!").
The deprecated Console.messageAdded also collects the messages from the console API, however, with less information. For example, Console.messageAdded always reports source=console-api whereas Runtime.consoleAPICalled distinguishes type=log, debug, info, error, warning, dir, ..., also Runtime.consoleAPICalled contains a stackTrace and a timestamp not contained in Console.messageAdded
(according to the documentation it should also collect the browser-caused messages, but it seems like it does not collect them anymore at least if Log.enable is activated).
I agree with the suggestion to replace Console.messageAdded with Runtime.consoleAPICalled.
I would also suggest to separate the two types of messages into two separate arrays console_api and browser_logs instead of using one shared console_log array. While it is possible to separate the two during processing as the entries in the array have different formats, I would assume that most people are only interested in either the browser-caused messages or the developer-caused messages at a time and would not need to filter for one subset each time when they use the logs.
Here is a comparison of the old Console.messageAdded and Runtime.consoleAPICalled message for console.assert(5 % 2 === 0, { 5 }, 'the # is not even');
Yes, the old format is much shorter but also contains some issues:
Not clear that it came from an assert (level=error vs type=assert)
I agree that saving the full Runtime.consoleAPICalled events might get out of hand both for storage and for processing:
Not sure if the stacktrace is helpful. For most analysis it is probably not necessary, but it could enable answering some advance questions.
The timestamp is only a single field, not sure if helpful, but should not hurt to keep.
The text is probably often more helpful than args.
If we do not have storage issues how about saving the full messages in the following format: type, text, executionContextID, timestamp, (context), args, (stackTrace). This would enable even advanced analyses but most simple queries can only use type and text and simple ignore args and stackTrace and the other entries.
For generating text we could either use the old Console.messageAdded events (but we would need to match them to their corresponding Runtime.consoleAPICalled events) or create a useful text entry from the args directly. Probably something like JSON.stringify(args).
The timestamps aren't relative to anything else in the test data so I'm hesitant to waste space with them but I can add them if necessary. Order is maintained so they shouldn't be needed for ordering.
About the timestamps, yes they are probably not useful as only the relative order should be important and that is preserved.
How exactly is the text, data, and stack created from the original message?
What about messages with multiple objects?
What about messages with a deeper callstack?
What about messages without a URL (e.g., eval("console.log('eval')")
I would also keep the executionContextId as this enables to distinguish messages caused by the top-level (inline + external scripts) from messages caused by iframes and similar.
As long as the format and the conversions from the original CDP event are described, any format that enables easy analysis is probably fine. Maybe we should get feedback from some more people?
What kind of analysis could be interesting and would our format enable these?
Stats on the amount and types of messages: works
Count of the most common messages: works (on the stringified output)
Find pages that have specific messages: works (using the stringified output)
The objects are serialized into the data array and each object gets a separate entry. The actual code that creates the text/data entries is here.
Basically, text is created by appending entries that have a value present, separated by spaces. Entries that don't have a value are collected into data entries, reporting the data from the preview and inserting the description into the text version.
The call stack is just grabbing the call site - is there a need for the full stack? I'll have to check, but I assume an eval will get the URL of the main document or where the eval was called from but if there is no URL at all then there will be no stack.
I'll add the executionContextId as well (probably contextID to keep it short).
Trying to walk the line between having everything that would be useful for analysis at-scale without bloating the HAR too badly since it impacts query costs for every query (and storage costs).
Activity
pmeenan commentedon May 30, 2025
Does
Runtime.consoleAPICalledlog something thatLog.enabledoesn't currently catch? All of the logging events should already be captured by the existingLog.entryAddedevents (Consoleis still there just for backwards compatibility)JannisBush commentedon Jun 1, 2025
Log.enablecollects the browser-caused messages, e.g., messages about invalid headers such as (Error with Permissions-Policy header: Unrecognized feature: 'abc').Runtime.consoleAPICalledcollects the developer-caused messages from the console API, e.g.,console.log("Log!").The deprecated
Console.messageAddedalso collects the messages from the console API, however, with less information. For example,Console.messageAddedalways reportssource=console-apiwhereasRuntime.consoleAPICalleddistinguishestype=log, debug, info, error, warning, dir, ..., alsoRuntime.consoleAPICalledcontains a stackTrace and a timestamp not contained inConsole.messageAdded(according to the documentation it should also collect the browser-caused messages, but it seems like it does not collect them anymore at least if
Log.enableis activated).I agree with the suggestion to replace
Console.messageAddedwithRuntime.consoleAPICalled.I would also suggest to separate the two types of messages into two separate arrays
console_apiandbrowser_logsinstead of using one sharedconsole_logarray. While it is possible to separate the two during processing as the entries in the array have different formats, I would assume that most people are only interested in either the browser-caused messages or the developer-caused messages at a time and would not need to filter for one subset each time when they use the logs.pmeenan commentedon Jun 3, 2025
So, if we do this then I probably want to keep both because the format of the consoleAPICalled data will be quite a bit harder to process.
Breaking the browser logs out into a separate
browser_logsmakes total sense and I can do that irregardless.Is there significant value in having the stack trace and timestamp because that will balloon the data pretty significantly? for example:
JannisBush commentedon Jun 3, 2025
Here is a comparison of the old
Console.messageAddedandRuntime.consoleAPICalledmessage forconsole.assert(5 % 2 === 0, { 5 }, 'the # is not even');Yes, the old format is much shorter but also contains some issues:
level=errorvstype=assert)[object Object]is not really helpfulRuntime.consoleAPICalled? view-source:https://test.patrickmeenan.com/console/ looks like line 37 is correct?I agree that saving the full
Runtime.consoleAPICalledevents might get out of hand both for storage and for processing:textis probably often more helpful thanargs.type, text, executionContextID, timestamp, (context), args, (stackTrace). This would enable even advanced analyses but most simple queries can only usetypeandtextand simple ignoreargsandstackTraceand the other entries.textwe could either use the oldConsole.messageAddedevents (but we would need to match them to their correspondingRuntime.consoleAPICalledevents) or create a useful text entry from the args directly. Probably something likeJSON.stringify(args).textfrom the args forConsole.messageAdded: https://source.chromium.org/chromium/chromium/src/+/main:v8/src/inspector/v8-console-message.cc;l=455;drc=aaceb0ff7dcbc44c661bae12fba36279b3dee7c4;bpv=1;bpt=1{ "source": "console-api", "level": "error", "text": "[object Object] the # is not even", "url": "https://test.patrickmeenan.com/console/", "line": 37, "column": 25 }{ "type": "assert", "args": [ { "type": "object", "className": "Object", "description": "Object", "objectId": "3737340583851650503.1.3", "preview": { "type": "object", "description": "Object", "overflow": false, "properties": [ { "name": "num", "type": "number", "value": "5" } ] } }, { "type": "string", "value": "the # is not even" } ], "executionContextId": 1, "timestamp": 1748958767692.235, "stackTrace": { "callFrames": [ { "functionName": "", "scriptId": "7", "url": "https:\/\/test.patrickmeenan.com\/console\/", "lineNumber": 36, "columnNumber": 24 } ] } },pmeenan commentedon Jun 3, 2025
The timestamps aren't relative to anything else in the test data so I'm hesitant to waste space with them but I can add them if necessary. Order is maintained so they shouldn't be needed for ordering.
How about something like this:
JannisBush commentedon Jun 4, 2025
About the timestamps, yes they are probably not useful as only the relative order should be important and that is preserved.
How exactly is the
text,data, andstackcreated from the original message?eval("console.log('eval')")I would also keep the
executionContextIdas this enables to distinguish messages caused by the top-level (inline + external scripts) from messages caused by iframes and similar.As long as the format and the conversions from the original CDP event are described, any format that enables easy analysis is probably fine. Maybe we should get feedback from some more people?
What kind of analysis could be interesting and would our format enable these?
pmeenan commentedon Jun 4, 2025
The objects are serialized into the
dataarray and each object gets a separate entry. The actual code that creates the text/data entries is here.Basically,
textis created by appending entries that have avaluepresent, separated by spaces. Entries that don't have avalueare collected intodataentries, reporting the data from thepreviewand inserting thedescriptioninto the text version.The call stack is just grabbing the call site - is there a need for the full stack? I'll have to check, but I assume an eval will get the URL of the main document or where the eval was called from but if there is no URL at all then there will be no stack.
I'll add the
executionContextIdas well (probablycontextIDto keep it short).Trying to walk the line between having everything that would be useful for analysis at-scale without bloating the HAR too badly since it impacts query costs for every query (and storage costs).