Add Page domain

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-04-16 00:41:26 +02:00
parent 980571073d
commit b1242207a9
2 changed files with 37 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ const server = @import("../server.zig");
const Ctx = server.Cmd; const Ctx = server.Cmd;
const browser = @import("browser.zig").browser; const browser = @import("browser.zig").browser;
const target = @import("target.zig").target; const target = @import("target.zig").target;
const page = @import("page.zig").page;
pub const Error = error{ pub const Error = error{
UnknonwDomain, UnknonwDomain,
@@ -24,6 +25,7 @@ pub fn isCdpError(err: anyerror) ?Error {
const Domains = enum { const Domains = enum {
Browser, Browser,
Target, Target,
Page,
}; };
// The caller is responsible for calling `free` on the returned slice. // The caller is responsible for calling `free` on the returned slice.
@@ -52,6 +54,7 @@ pub fn do(
return switch (domain) { return switch (domain) {
.Browser => browser(alloc, id, iter.next().?, &scanner, ctx), .Browser => browser(alloc, id, iter.next().?, &scanner, ctx),
.Target => target(alloc, id, iter.next().?, &scanner, ctx), .Target => target(alloc, id, iter.next().?, &scanner, ctx),
.Page => page(alloc, id, iter.next().?, &scanner, ctx),
}; };
} }

34
src/cdp/page.zig Normal file
View File

@@ -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 PageMethods = enum {
enable,
};
pub fn page(
alloc: std.mem.Allocator,
id: u64,
action: []const u8,
scanner: *std.json.Scanner,
ctx: *Ctx,
) ![]const u8 {
const method = std.meta.stringToEnum(PageMethods, 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);
}