diff --git a/src/cdp/CDP.zig b/src/cdp/CDP.zig index 94b99edf..8124430f 100644 --- a/src/cdp/CDP.zig +++ b/src/cdp/CDP.zig @@ -236,6 +236,7 @@ fn dispatchCommand(command: *Command, method: []const u8) !void { asUint(u56, "Runtime") => return @import("domains/runtime.zig").processMessage(command), asUint(u56, "Network") => return @import("domains/network.zig").processMessage(command), asUint(u56, "Storage") => return @import("domains/storage.zig").processMessage(command), + asUint(u56, "Console") => return @import("domains/console.zig").processMessage(command), else => {}, }, 8 => switch (@as(u64, @bitCast(domain[0..8].*))) { @@ -632,6 +633,9 @@ pub const BrowserContext = struct { self.notification.unregister(.frame_network_almost_idle, self); } + pub fn consoleEnable(_: *BrowserContext) !void {} + pub fn consoleDisable(_: *BrowserContext) void {} + pub fn onFrameRemove(ctx: *anyopaque, _: Notification.FrameRemove) !void { const self: *BrowserContext = @ptrCast(@alignCast(ctx)); @import("domains/page.zig").frameRemove(self); diff --git a/src/cdp/domains/console.zig b/src/cdp/domains/console.zig new file mode 100644 index 00000000..18aaba70 --- /dev/null +++ b/src/cdp/domains/console.zig @@ -0,0 +1,45 @@ +// Copyright (C) 2023-2026 Lightpanda (Selecy SAS) +// +// Francis Bouvier +// Pierre Tachoire +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +const std = @import("std"); + +const CDP = @import("../CDP.zig"); + +pub fn processMessage(cmd: *CDP.Command) !void { + const action = std.meta.stringToEnum(enum { + enable, + disable, + }, cmd.input.action) orelse return error.UnknownMethod; + + switch (action) { + .enable => return enable(cmd), + .disable => return disable(cmd), + } +} + +fn enable(cmd: *CDP.Command) !void { + const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded; + try bc.consoleEnable(); + return cmd.sendResult(null, .{}); +} + +fn disable(cmd: *CDP.Command) !void { + const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded; + bc.consoleDisable(); + return cmd.sendResult(null, .{}); +}