From e073e3388d90477f6d84c4f471d8515da16cde86 Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Tue, 16 Apr 2024 00:50:17 +0200 Subject: [PATCH] Add Runtime domain Signed-off-by: Francis Bouvier --- src/cdp/cdp.zig | 4 ++++ src/cdp/runtime.zig | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/cdp/runtime.zig diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index 9e34bbee..1c07d9d3 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -2,10 +2,12 @@ const std = @import("std"); const server = @import("../server.zig"); const Ctx = server.Cmd; + const browser = @import("browser.zig").browser; const target = @import("target.zig").target; const page = @import("page.zig").page; const log = @import("log.zig").log; +const runtime = @import("runtime.zig").runtime; pub const Error = error{ UnknonwDomain, @@ -28,6 +30,7 @@ const Domains = enum { Target, Page, Log, + Runtime, }; // The caller is responsible for calling `free` on the returned slice. @@ -58,6 +61,7 @@ pub fn do( .Target => target(alloc, id, iter.next().?, &scanner, ctx), .Page => page(alloc, id, iter.next().?, &scanner, ctx), .Log => log(alloc, id, iter.next().?, &scanner, ctx), + .Runtime => runtime(alloc, id, iter.next().?, &scanner, ctx), }; } diff --git a/src/cdp/runtime.zig b/src/cdp/runtime.zig new file mode 100644 index 00000000..c21fbdf5 --- /dev/null +++ b/src/cdp/runtime.zig @@ -0,0 +1,34 @@ +const std = @import("std"); + +const server = @import("../server.zig"); +const Ctx = server.Cmd; +const result = @import("cdp.zig").result; +const getParams = @import("cdp.zig").getParams; +const stringify = @import("cdp.zig").stringify; + +const RuntimeMethods = enum { + enable, +}; + +pub fn runtime( + alloc: std.mem.Allocator, + id: u64, + action: []const u8, + scanner: *std.json.Scanner, + ctx: *Ctx, +) ![]const u8 { + const method = std.meta.stringToEnum(RuntimeMethods, action) orelse + return error.UnknownMethod; + return switch (method) { + .enable => enable(alloc, id, scanner, ctx), + }; +} + +fn enable( + alloc: std.mem.Allocator, + id: u64, + _: *std.json.Scanner, + _: *Ctx, +) ![]const u8 { + return result(alloc, id, null, null); +}