cdp: report console.log/console.warn with their own consoleAPICalled types

console.log and console.warn were both dispatched as .info, so
Runtime.consoleAPICalled (and Console.messageAdded) reported type
"info" for all three of log/info/warn — clients filtering console
output by severity saw them collapsed into one bucket.

Add log/warning members to ConsoleMessageType (the protocol's wire
values — "warning", not "warn") and map console.log -> log,
console.warn -> warning. info/error/debug/trace already matched.

Closes #2730
This commit is contained in:
Navid EMAD
2026-06-12 19:22:24 +02:00
parent 1fae856330
commit b136b3a84d
3 changed files with 29 additions and 3 deletions

View File

@@ -265,9 +265,10 @@ pub const DialogResponse = struct {
};
pub const ConsoleMessageType = enum {
log,
debug,
info,
warn,
warning,
@"error",
fatal,
trace,

View File

@@ -71,12 +71,12 @@ pub fn info(_: *const Console, values: []js.Value, exec: *js.Execution) void {
pub fn log(_: *const Console, values: []js.Value, exec: *js.Execution) void {
logger.info(.js, "console.log", .{ValueWriter{ .values = values }});
dispatchConsoleMessage(values, .info, exec);
dispatchConsoleMessage(values, .log, exec);
}
pub fn warn(_: *const Console, values: []js.Value, exec: *js.Execution) void {
logger.warn(.js, "console.warn", .{ValueWriter{ .values = values }});
dispatchConsoleMessage(values, .info, exec);
dispatchConsoleMessage(values, .warning, exec);
}
pub fn clear(_: *const Console) void {}

View File

@@ -163,3 +163,28 @@ pub fn consoleMessage(arena: Allocator, bc: *CDP.BrowserContext, event: *const N
.args = args.items,
}, .{ .session_id = session_id });
}
const testing = @import("../testing.zig");
test "cdp.runtime: consoleAPICalled type matches the console method" {
// Wire types per the CDP protocol: console.log -> "log",
// console.warn -> "warning" (not "warn"), console.info -> "info",
// console.error -> "error", console.debug -> "debug".
var ctx = try testing.context();
defer ctx.deinit();
var bc = try ctx.loadBrowserContext(.{ .id = "BID-CONS", .url = "hi.html", .target_id = "FID-0000000CON".* });
try ctx.processMessage(.{ .id = 60, .method = "Runtime.enable" });
const frame = bc.session.currentFrame() orelse unreachable;
var ls: js.Local.Scope = undefined;
frame.js.localScope(&ls);
defer ls.deinit();
_ = try ls.local.exec("console.log('l'); console.warn('w'); console.info('i'); console.error('e'); console.debug('d');", null);
try ctx.expectSentEvent("Runtime.consoleAPICalled", .{ .type = "log" }, .{});
try ctx.expectSentEvent("Runtime.consoleAPICalled", .{ .type = "warning" }, .{});
try ctx.expectSentEvent("Runtime.consoleAPICalled", .{ .type = "info" }, .{});
try ctx.expectSentEvent("Runtime.consoleAPICalled", .{ .type = "error" }, .{});
try ctx.expectSentEvent("Runtime.consoleAPICalled", .{ .type = "debug" }, .{});
}