diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index 1c1f25b5..07c9d403 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -32,6 +32,7 @@ const fetch = @import("fetch.zig").fetch; const performance = @import("performance.zig").performance; const IncomingMessage = @import("msg.zig").IncomingMessage; const Input = @import("msg.zig").Input; +const inspector = @import("inspector.zig").inspector; const log_cdp = std.log.scoped(.cdp); @@ -60,6 +61,7 @@ const Domains = enum { Log, Runtime, Network, + Inspector, Emulation, Fetch, Performance, @@ -100,6 +102,7 @@ pub fn dispatch( .Log => log(alloc, msg, action, ctx), .Runtime => runtime(alloc, msg, action, ctx), .Network => network(alloc, msg, action, ctx), + .Inspector => inspector(alloc, msg, action, ctx), .Emulation => emulation(alloc, msg, action, ctx), .Fetch => fetch(alloc, msg, action, ctx), .Performance => performance(alloc, msg, action, ctx), diff --git a/src/cdp/inspector.zig b/src/cdp/inspector.zig new file mode 100644 index 00000000..9d67fa74 --- /dev/null +++ b/src/cdp/inspector.zig @@ -0,0 +1,59 @@ +// Copyright (C) 2023-2024 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 server = @import("../server.zig"); +const Ctx = server.Ctx; +const cdp = @import("cdp.zig"); +const result = cdp.result; +const IncomingMessage = @import("msg.zig").IncomingMessage; +const Input = @import("msg.zig").Input; + +const log = std.log.scoped(.cdp); + +const Methods = enum { + enable, +}; + +pub fn inspector( + alloc: std.mem.Allocator, + msg: *IncomingMessage, + action: []const u8, + ctx: *Ctx, +) ![]const u8 { + const method = std.meta.stringToEnum(Methods, action) orelse + return error.UnknownMethod; + + return switch (method) { + .enable => enable(alloc, msg, ctx), + }; +} + +fn enable( + alloc: std.mem.Allocator, + msg: *IncomingMessage, + _: *Ctx, +) ![]const u8 { + // input + const input = try Input(void).get(alloc, msg); + defer input.deinit(); + log.debug("Req > id {d}, method {s}", .{ input.id, "inspector.enable" }); + + return result(alloc, input.id, null, null, input.sessionId); +}