From b136b3a84d3adba9ce4dee900b903881f79ffbe3 Mon Sep 17 00:00:00 2001 From: Navid EMAD Date: Fri, 12 Jun 2026 19:22:24 +0200 Subject: [PATCH] cdp: report console.log/console.warn with their own consoleAPICalled types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/Notification.zig | 3 ++- src/browser/webapi/Console.zig | 4 ++-- src/cdp/domains/runtime.zig | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Notification.zig b/src/Notification.zig index 1dff474fe..c8064f12f 100644 --- a/src/Notification.zig +++ b/src/Notification.zig @@ -265,9 +265,10 @@ pub const DialogResponse = struct { }; pub const ConsoleMessageType = enum { + log, debug, info, - warn, + warning, @"error", fatal, trace, diff --git a/src/browser/webapi/Console.zig b/src/browser/webapi/Console.zig index 3d97325a5..a7f1661e1 100644 --- a/src/browser/webapi/Console.zig +++ b/src/browser/webapi/Console.zig @@ -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 {} diff --git a/src/cdp/domains/runtime.zig b/src/cdp/domains/runtime.zig index 0ca9c6c15..6228ee738 100644 --- a/src/cdp/domains/runtime.zig +++ b/src/cdp/domains/runtime.zig @@ -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" }, .{}); +}