mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Add sendEvent utility function
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -129,14 +129,14 @@ pub fn result(
|
|||||||
return stringify(alloc, resp);
|
return stringify(alloc, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// caller owns the slice returned
|
pub fn sendEvent(
|
||||||
pub fn method(
|
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
|
ctx: *Ctx,
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
comptime T: type,
|
comptime T: type,
|
||||||
params: T,
|
params: T,
|
||||||
sessionID: ?[]const u8,
|
sessionID: ?[]const u8,
|
||||||
) ![]const u8 {
|
) !void {
|
||||||
const Resp = struct {
|
const Resp = struct {
|
||||||
method: []const u8,
|
method: []const u8,
|
||||||
params: T,
|
params: T,
|
||||||
@@ -144,7 +144,9 @@ pub fn method(
|
|||||||
};
|
};
|
||||||
const resp = Resp{ .method = name, .params = params, .sessionId = sessionID };
|
const resp = Resp{ .method = name, .params = params, .sessionId = sessionID };
|
||||||
|
|
||||||
return stringify(alloc, resp);
|
const event_msg = try stringify(alloc, resp);
|
||||||
|
std.log.debug("event {s}", .{event_msg});
|
||||||
|
try server.sendSync(ctx, event_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getParams(
|
pub fn getParams(
|
||||||
|
|||||||
@@ -168,6 +168,8 @@ fn navigate(
|
|||||||
ctx.state.url = content.params.url;
|
ctx.state.url = content.params.url;
|
||||||
ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2";
|
ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2";
|
||||||
|
|
||||||
|
var page = try ctx.browser.currentSession().createPage();
|
||||||
|
|
||||||
// output
|
// output
|
||||||
const Resp = struct {
|
const Resp = struct {
|
||||||
frameId: []const u8,
|
frameId: []const u8,
|
||||||
|
|||||||
@@ -31,12 +31,68 @@ fn enable(
|
|||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
id: u64,
|
id: u64,
|
||||||
scanner: *std.json.Scanner,
|
scanner: *std.json.Scanner,
|
||||||
_: *Ctx,
|
ctx: *Ctx,
|
||||||
) ![]const u8 {
|
) ![]const u8 {
|
||||||
|
_ = ctx;
|
||||||
|
|
||||||
|
// input
|
||||||
const sessionID = try cdp.getSessionID(scanner);
|
const sessionID = try cdp.getSessionID(scanner);
|
||||||
|
|
||||||
|
// output
|
||||||
|
// const uniqueID = "1367118932354479079.-1471398151593995849";
|
||||||
|
// const mainCtx = try executionContextCreated(
|
||||||
|
// alloc,
|
||||||
|
// 1,
|
||||||
|
// cdp.URLBase,
|
||||||
|
// "",
|
||||||
|
// uniqueID,
|
||||||
|
// .{},
|
||||||
|
// sessionID,
|
||||||
|
// );
|
||||||
|
// std.log.debug("res {s}", .{mainCtx});
|
||||||
|
// try server.sendAsync(ctx, mainCtx);
|
||||||
|
|
||||||
return result(alloc, id, null, null, sessionID);
|
return result(alloc, id, null, null, sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AuxData = struct {
|
||||||
|
isDefault: bool = true,
|
||||||
|
type: []const u8 = "default",
|
||||||
|
frameId: []const u8 = cdp.FrameID,
|
||||||
|
};
|
||||||
|
|
||||||
|
const ExecutionContextDescription = struct {
|
||||||
|
id: u64,
|
||||||
|
origin: []const u8,
|
||||||
|
name: []const u8,
|
||||||
|
uniqueId: []const u8,
|
||||||
|
auxData: ?AuxData = null,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn executionContextCreated(
|
||||||
|
alloc: std.mem.Allocator,
|
||||||
|
id: u64,
|
||||||
|
origin: []const u8,
|
||||||
|
name: []const u8,
|
||||||
|
uniqueID: []const u8,
|
||||||
|
auxData: ?AuxData,
|
||||||
|
sessionID: ?[]const u8,
|
||||||
|
) ![]const u8 {
|
||||||
|
const Params = struct {
|
||||||
|
context: ExecutionContextDescription,
|
||||||
|
};
|
||||||
|
const params = Params{
|
||||||
|
.context = .{
|
||||||
|
.id = id,
|
||||||
|
.origin = origin,
|
||||||
|
.name = name,
|
||||||
|
.uniqueId = uniqueID,
|
||||||
|
.auxData = auxData,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return try cdp.method(alloc, "Runtime.executionContextCreated", Params, params, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
fn runIfWaitingForDebugger(
|
fn runIfWaitingForDebugger(
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
id: u64,
|
id: u64,
|
||||||
|
|||||||
@@ -81,15 +81,7 @@ fn tagetSetAutoAttach(
|
|||||||
.browserContextId = BrowserContextID,
|
.browserContextId = BrowserContextID,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const event = try cdp.method(
|
try cdp.sendEvent(alloc, ctx, "Target.attachedToTarget", AttachToTarget, attached, null);
|
||||||
alloc,
|
|
||||||
"Target.attachedToTarget",
|
|
||||||
AttachToTarget,
|
|
||||||
attached,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
std.log.debug("event {s}", .{event});
|
|
||||||
try server.sendSync(ctx, event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result(alloc, id, null, null, sessionID);
|
return result(alloc, id, null, null, sessionID);
|
||||||
@@ -196,15 +188,7 @@ fn createTarget(
|
|||||||
},
|
},
|
||||||
.waitingForDebugger = true,
|
.waitingForDebugger = true,
|
||||||
};
|
};
|
||||||
const event = try cdp.method(
|
try cdp.sendEvent(alloc, ctx, "Target.attachedToTarget", AttachToTarget, attached, sessionID);
|
||||||
alloc,
|
|
||||||
"Target.attachedToTarget",
|
|
||||||
AttachToTarget,
|
|
||||||
attached,
|
|
||||||
sessionID,
|
|
||||||
);
|
|
||||||
std.log.debug("event {s}", .{event});
|
|
||||||
try server.sendSync(ctx, event);
|
|
||||||
|
|
||||||
// output
|
// output
|
||||||
const Resp = struct {
|
const Resp = struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user