cdp: ensure there is an ID on each request

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-15 17:28:18 +02:00
parent 7750956c7b
commit 84c49fbe34
10 changed files with 100 additions and 94 deletions

View File

@@ -57,13 +57,13 @@ const JsVersion = "12.4.254.8";
fn getVersion( fn getVersion(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
// input // input
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
// ouput // ouput
const Res = struct { const Res = struct {
@@ -73,13 +73,13 @@ fn getVersion(
userAgent: []const u8 = UserAgent, userAgent: []const u8 = UserAgent,
jsVersion: []const u8 = JsVersion, jsVersion: []const u8 = JsVersion,
}; };
return result(alloc, id orelse msg.id.?, Res, .{}, null); return result(alloc, msg.id, Res, .{}, null);
} }
// TODO: noop method // TODO: noop method
fn setDownloadBehavior( fn setDownloadBehavior(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -91,10 +91,10 @@ fn setDownloadBehavior(
downloadPath: ?[]const u8 = null, downloadPath: ?[]const u8 = null,
eventsEnabled: ?bool = null, eventsEnabled: ?bool = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// output // output
return result(alloc, id orelse msg.id.?, null, null, null); return result(alloc, msg.id, null, null, null);
} }
// TODO: hard coded ID // TODO: hard coded ID
@@ -102,7 +102,7 @@ const DevToolsWindowID = 1923710101;
fn getWindowForTarget( fn getWindowForTarget(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -111,7 +111,7 @@ fn getWindowForTarget(
const Params = struct { const Params = struct {
targetId: ?[]const u8 = null, targetId: ?[]const u8 = null,
}; };
const msg = try cdp.getMsg(alloc, ?Params, scanner); const msg = try cdp.getMsg(alloc, _id, ?Params, scanner);
std.debug.assert(msg.sessionID != null); std.debug.assert(msg.sessionID != null);
// output // output
@@ -125,20 +125,20 @@ fn getWindowForTarget(
windowState: []const u8 = "normal", windowState: []const u8 = "normal",
} = .{}, } = .{},
}; };
return result(alloc, id orelse msg.id.?, Resp, Resp{}, msg.sessionID.?); return result(alloc, msg.id, Resp, Resp{}, msg.sessionID.?);
} }
// TODO: noop method // TODO: noop method
fn setWindowBounds( fn setWindowBounds(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
// input // input
const msg = try cdp.getMsg(alloc, void, scanner); const msg = try cdp.getMsg(alloc, _id, void, scanner);
// output // output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }

View File

@@ -35,6 +35,7 @@ pub const Error = error{
UnknonwDomain, UnknonwDomain,
UnknownMethod, UnknownMethod,
NoResponse, NoResponse,
RequestWithoutID,
}; };
pub fn isCdpError(err: anyerror) ?Error { pub fn isCdpError(err: anyerror) ?Error {
@@ -276,10 +277,11 @@ fn getSessionId(scanner: *std.json.Scanner, key: []const u8) !?[]const u8 {
pub fn getMsg( pub fn getMsg(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
_id: ?u16,
comptime params_T: type, comptime params_T: type,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
) !struct { id: ?u16, params: ?params_T, sessionID: ?[]const u8 } { ) !struct { id: u16, params: ?params_T, sessionID: ?[]const u8 } {
var id: ?u16 = null; var id_msg: ?u16 = null;
var params: ?params_T = null; var params: ?params_T = null;
var sessionID: ?[]const u8 = null; var sessionID: ?[]const u8 = null;
@@ -291,9 +293,9 @@ pub fn getMsg(
if (t != .string) { if (t != .string) {
return error.WrongTokenType; return error.WrongTokenType;
} }
if (id == null) { if (_id == null and id_msg == null) {
id = try getId(scanner, t.string); id_msg = try getId(scanner, t.string);
if (id != null) continue; if (id_msg != null) continue;
} }
if (params == null) { if (params == null) {
params = try getParams(alloc, params_T, scanner, t.string); params = try getParams(alloc, params_T, scanner, t.string);
@@ -311,7 +313,11 @@ pub fn getMsg(
); );
t = try scanner.next(); t = try scanner.next();
if (t != .end_of_document) return error.CDPMsgEnd; if (t != .end_of_document) return error.CDPMsgEnd;
return .{ .id = id, .params = params, .sessionID = sessionID };
// check id
if (_id == null and id_msg == null) return error.RequestWithoutID;
return .{ .id = _id orelse id_msg.?, .params = params, .sessionID = sessionID };
} }
// Common // Common

View File

@@ -57,7 +57,7 @@ const MediaFeature = struct {
// TODO: noop method // TODO: noop method
fn setEmulatedMedia( fn setEmulatedMedia(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -67,16 +67,16 @@ fn setEmulatedMedia(
media: ?[]const u8 = null, media: ?[]const u8 = null,
features: ?[]MediaFeature = null, features: ?[]MediaFeature = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// output // output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
// TODO: noop method // TODO: noop method
fn setFocusEmulationEnabled( fn setFocusEmulationEnabled(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -85,35 +85,35 @@ fn setFocusEmulationEnabled(
const Params = struct { const Params = struct {
enabled: bool, enabled: bool,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// output // output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
// TODO: noop method // TODO: noop method
fn setDeviceMetricsOverride( fn setDeviceMetricsOverride(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
// input // input
const msg = try cdp.getMsg(alloc, void, scanner); const msg = try cdp.getMsg(alloc, _id, void, scanner);
// output // output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
// TODO: noop method // TODO: noop method
fn setTouchEmulationEnabled( fn setTouchEmulationEnabled(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try cdp.getMsg(alloc, void, scanner); const msg = try cdp.getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }

View File

@@ -46,11 +46,11 @@ pub fn fetch(
// TODO: noop method // TODO: noop method
fn disable( fn disable(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }

View File

@@ -46,11 +46,11 @@ pub fn log(
fn enable( fn enable(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }

View File

@@ -47,23 +47,23 @@ pub fn network(
fn enable( fn enable(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
// TODO: noop method // TODO: noop method
fn setCacheDisabled( fn setCacheDisabled(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }

View File

@@ -58,12 +58,12 @@ pub fn page(
fn enable( fn enable(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
const Frame = struct { const Frame = struct {
@@ -83,11 +83,11 @@ const Frame = struct {
fn getFrameTree( fn getFrameTree(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try cdp.getMsg(alloc, void, scanner); const msg = try cdp.getMsg(alloc, _id, void, scanner);
const FrameTree = struct { const FrameTree = struct {
frameTree: struct { frameTree: struct {
@@ -106,12 +106,12 @@ fn getFrameTree(
}, },
}, },
}; };
return result(alloc, id orelse msg.id.?, FrameTree, frameTree, msg.sessionID); return result(alloc, msg.id, FrameTree, frameTree, msg.sessionID);
} }
fn setLifecycleEventsEnabled( fn setLifecycleEventsEnabled(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -120,12 +120,12 @@ fn setLifecycleEventsEnabled(
const Params = struct { const Params = struct {
enabled: bool, enabled: bool,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
ctx.state.page_life_cycle_events = true; ctx.state.page_life_cycle_events = true;
// output // output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
const LifecycleEvent = struct { const LifecycleEvent = struct {
@@ -138,7 +138,7 @@ const LifecycleEvent = struct {
// TODO: hard coded method // TODO: hard coded method
fn addScriptToEvaluateOnNewDocument( fn addScriptToEvaluateOnNewDocument(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -150,19 +150,19 @@ fn addScriptToEvaluateOnNewDocument(
includeCommandLineAPI: bool = false, includeCommandLineAPI: bool = false,
runImmediately: bool = false, runImmediately: bool = false,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// output // output
const Res = struct { const Res = struct {
identifier: []const u8 = "1", identifier: []const u8 = "1",
}; };
return result(alloc, id orelse msg.id.?, Res, Res{}, msg.sessionID); return result(alloc, msg.id, Res, Res{}, msg.sessionID);
} }
// TODO: hard coded method // TODO: hard coded method
fn createIsolatedWorld( fn createIsolatedWorld(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -173,7 +173,7 @@ fn createIsolatedWorld(
worldName: []const u8, worldName: []const u8,
grantUniveralAccess: bool, grantUniveralAccess: bool,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
std.debug.assert(msg.sessionID != null); std.debug.assert(msg.sessionID != null);
const params = msg.params.?; const params = msg.params.?;
@@ -199,12 +199,12 @@ fn createIsolatedWorld(
executionContextId: u8 = 0, executionContextId: u8 = 0,
}; };
return result(alloc, id orelse msg.id.?, Resp, .{}, msg.sessionID); return result(alloc, msg.id, Resp, .{}, msg.sessionID);
} }
fn navigate( fn navigate(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -217,7 +217,7 @@ fn navigate(
frameId: ?[]const u8 = null, frameId: ?[]const u8 = null,
referrerPolicy: ?[]const u8 = null, // TODO: enum referrerPolicy: ?[]const u8 = null, // TODO: enum
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
std.debug.assert(msg.sessionID != null); std.debug.assert(msg.sessionID != null);
const params = msg.params.?; const params = msg.params.?;
@@ -269,7 +269,7 @@ fn navigate(
.frameId = ctx.state.frameID, .frameId = ctx.state.frameID,
.loaderId = ctx.state.loaderID, .loaderId = ctx.state.loaderID,
}; };
const res = try result(alloc, id orelse msg.id.?, Resp, resp, msg.sessionID); const res = try result(alloc, msg.id, Resp, resp, msg.sessionID);
defer alloc.free(res); defer alloc.free(res);
std.log.debug("res {s}", .{res}); std.log.debug("res {s}", .{res});
try server.sendSync(ctx, res); try server.sendSync(ctx, res);

View File

@@ -45,11 +45,11 @@ pub fn performance(
fn enable( fn enable(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }

View File

@@ -79,10 +79,10 @@ fn sendInspector(
userGesture: ?bool = null, userGesture: ?bool = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
const params = msg.params.?; const params = msg.params.?;
script = params.expression; script = params.expression;
id = _id orelse msg.id.?; id = msg.id;
} else if (method == .callFunctionOn) { } else if (method == .callFunctionOn) {
const Params = struct { const Params = struct {
functionDeclaration: []const u8, functionDeclaration: []const u8,
@@ -97,10 +97,10 @@ fn sendInspector(
userGesture: ?bool = null, userGesture: ?bool = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
const params = msg.params.?; const params = msg.params.?;
script = params.functionDeclaration; script = params.functionDeclaration;
id = _id orelse msg.id.?; id = msg.id;
} }
if (script) |src| { if (script) |src| {
@@ -162,11 +162,11 @@ pub fn executionContextCreated(
// should we be passing this also to the JS Inspector? // should we be passing this also to the JS Inspector?
fn runIfWaitingForDebugger( fn runIfWaitingForDebugger(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }

View File

@@ -65,16 +65,16 @@ const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9";
// TODO: noop method // TODO: noop method
fn setDiscoverTargets( fn setDiscoverTargets(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
// input // input
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
// output // output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
const AttachToTarget = struct { const AttachToTarget = struct {
@@ -99,7 +99,7 @@ const TargetFilter = struct {
// TODO: noop method // TODO: noop method
fn setAutoAttach( fn setAutoAttach(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -111,7 +111,7 @@ fn setAutoAttach(
flatten: bool = true, flatten: bool = true,
filter: ?[]TargetFilter = null, filter: ?[]TargetFilter = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
std.log.debug("params {any}", .{msg.params}); std.log.debug("params {any}", .{msg.params});
// attachedToTarget event // attachedToTarget event
@@ -129,12 +129,12 @@ fn setAutoAttach(
} }
// output // output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, msg.id, null, null, msg.sessionID);
} }
fn getTargetInfo( fn getTargetInfo(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -143,7 +143,7 @@ fn getTargetInfo(
const Params = struct { const Params = struct {
targetId: ?[]const u8 = null, targetId: ?[]const u8 = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// output // output
const TargetInfo = struct { const TargetInfo = struct {
@@ -162,7 +162,7 @@ fn getTargetInfo(
.targetId = BrowserTargetID, .targetId = BrowserTargetID,
.type = "browser", .type = "browser",
}; };
return result(alloc, id orelse msg.id.?, TargetInfo, targetInfo, null); return result(alloc, msg.id, TargetInfo, targetInfo, null);
} }
// Browser context are not handled and not in the roadmap for now // Browser context are not handled and not in the roadmap for now
@@ -171,13 +171,13 @@ fn getTargetInfo(
// TODO: noop method // TODO: noop method
fn getBrowserContexts( fn getBrowserContexts(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
// input // input
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, _id, void, scanner);
// ouptut // ouptut
const Resp = struct { const Resp = struct {
@@ -191,7 +191,7 @@ fn getBrowserContexts(
const contextIDs = [0][]const u8{}; const contextIDs = [0][]const u8{};
resp = .{ .browserContextIds = &contextIDs }; resp = .{ .browserContextIds = &contextIDs };
} }
return result(alloc, id orelse msg.id.?, Resp, resp, null); return result(alloc, msg.id, Resp, resp, null);
} }
const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89"; const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89";
@@ -199,7 +199,7 @@ const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89";
// TODO: noop method // TODO: noop method
fn createBrowserContext( fn createBrowserContext(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -211,7 +211,7 @@ fn createBrowserContext(
proxyBypassList: ?[]const u8 = null, proxyBypassList: ?[]const u8 = null,
originsWithUniversalNetworkAccess: ?[][]const u8 = null, originsWithUniversalNetworkAccess: ?[][]const u8 = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
ctx.state.contextID = ContextID; ctx.state.contextID = ContextID;
@@ -219,12 +219,12 @@ fn createBrowserContext(
const Resp = struct { const Resp = struct {
browserContextId: []const u8 = ContextID, browserContextId: []const u8 = ContextID,
}; };
return result(alloc, id orelse msg.id.?, Resp, Resp{}, msg.sessionID); return result(alloc, msg.id, Resp, Resp{}, msg.sessionID);
} }
fn disposeBrowserContext( fn disposeBrowserContext(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -233,10 +233,10 @@ fn disposeBrowserContext(
const Params = struct { const Params = struct {
browserContextId: []const u8, browserContextId: []const u8,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// output // output
const res = try result(alloc, id orelse msg.id.?, null, .{}, null); const res = try result(alloc, msg.id, null, .{}, null);
defer alloc.free(res); defer alloc.free(res);
try server.sendSync(ctx, res); try server.sendSync(ctx, res);
@@ -249,7 +249,7 @@ const LoaderID = "DD4A76F842AA389647D702B4D805F49A";
fn createTarget( fn createTarget(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -265,7 +265,7 @@ fn createTarget(
background: bool = false, background: bool = false,
forTab: ?bool = null, forTab: ?bool = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// change CDP state // change CDP state
ctx.state.frameID = TargetID; ctx.state.frameID = TargetID;
@@ -291,12 +291,12 @@ fn createTarget(
const Resp = struct { const Resp = struct {
targetId: []const u8 = TargetID, targetId: []const u8 = TargetID,
}; };
return result(alloc, id orelse msg.id.?, Resp, Resp{}, msg.sessionID); return result(alloc, msg.id, Resp, Resp{}, msg.sessionID);
} }
fn closeTarget( fn closeTarget(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, _id: ?u16,
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
ctx: *Ctx, ctx: *Ctx,
) ![]const u8 { ) ![]const u8 {
@@ -305,13 +305,13 @@ fn closeTarget(
const Params = struct { const Params = struct {
targetId: []const u8, targetId: []const u8,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, _id, Params, scanner);
// output // output
const Resp = struct { const Resp = struct {
success: bool = true, success: bool = true,
}; };
const res = try result(alloc, id orelse msg.id.?, Resp, Resp{}, null); const res = try result(alloc, msg.id, Resp, Resp{}, null);
defer alloc.free(res); defer alloc.free(res);
try server.sendSync(ctx, res); try server.sendSync(ctx, res);