Skip to content

Commit fc1b3d5

Browse files
Contextual frameTree
Signed-off-by: Francis Bouvier <[email protected]>
1 parent 508741c commit fc1b3d5

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

src/cdp/cdp.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ pub fn do(
7171
};
7272
}
7373

74+
pub const State = struct {
75+
frameID: []const u8 = FrameID,
76+
url: []const u8 = URLBase,
77+
securityOrigin: []const u8 = URLBase,
78+
secureContextType: []const u8 = "Secure", // TODO: enum
79+
loaderID: []const u8 = LoaderID,
80+
};
81+
7482
// Utils
7583
// -----
7684

@@ -240,3 +248,4 @@ pub fn getContent(
240248
pub const SessionID = "9559320D92474062597D9875C664CAC0";
241249
pub const URLBase = "chrome://newtab/";
242250
pub const FrameID = "90D14BBD8AED408A0467AC93100BCDBE";
251+
pub const LoaderID = "CFC8BED824DD2FD56CF1EF33C965C79C";

src/cdp/page.zig

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,44 @@ fn enable(
4141
return result(alloc, id, null, null, sessionID);
4242
}
4343

44-
const LoaderID = "CFC8BED824DD2FD56CF1EF33C965C79C";
45-
4644
fn getFrameTree(
4745
alloc: std.mem.Allocator,
4846
id: u64,
4947
scanner: *std.json.Scanner,
50-
_: *Ctx,
48+
ctx: *Ctx,
5149
) ![]const u8 {
5250
const sessionID = try cdp.getSessionID(scanner);
5351
const FrameTree = struct {
5452
frameTree: struct {
5553
frame: struct {
56-
id: []const u8 = cdp.FrameID,
57-
loaderId: []const u8 = LoaderID,
58-
url: []const u8 = cdp.URLBase,
54+
id: []const u8,
55+
loaderId: []const u8,
56+
url: []const u8,
5957
domainAndRegistry: []const u8 = "",
60-
securityOrigin: []const u8 = cdp.URLBase,
61-
mimeType: []const u8 = "mimeType",
58+
securityOrigin: []const u8,
59+
mimeType: []const u8 = "text/html",
6260
adFrameStatus: struct {
6361
adFrameType: []const u8 = "none",
6462
} = .{},
65-
secureContextType: []const u8 = "Secure",
63+
secureContextType: []const u8,
6664
crossOriginIsolatedContextType: []const u8 = "NotIsolated",
6765
gatedAPIFeatures: [][]const u8 = &[0][]const u8{},
68-
} = .{},
69-
} = .{},
66+
},
67+
},
7068
childFrames: ?[]@This() = null,
7169
};
72-
return result(alloc, id, FrameTree, FrameTree{}, sessionID);
70+
const frameTree = FrameTree{
71+
.frameTree = .{
72+
.frame = .{
73+
.id = ctx.state.frameID,
74+
.url = ctx.state.url,
75+
.securityOrigin = ctx.state.securityOrigin,
76+
.secureContextType = ctx.state.secureContextType,
77+
.loaderId = ctx.state.loaderID,
78+
},
79+
},
80+
};
81+
return result(alloc, id, FrameTree, frameTree, sessionID);
7382
}
7483

7584
fn setLifecycleEventsEnabled(

src/cdp/target.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,20 @@ fn createTarget(
178178
_ = try getParams(alloc, Params, scanner);
179179
const sessionID = try cdp.getSessionID(scanner);
180180

181+
// change CDP state
182+
ctx.state.frameID = TargetID;
183+
ctx.state.url = "about:blank";
184+
ctx.state.securityOrigin = "://";
185+
ctx.state.secureContextType = "InsecureScheme";
186+
ctx.state.loaderID = "DD4A76F842AA389647D702B4D805F49A";
187+
181188
// send attachToTarget event
182189
const attached = AttachToTarget{
183190
.sessionId = ContextSessionID,
184191
.targetInfo = .{
185-
.targetId = TargetID,
192+
.targetId = ctx.state.frameID,
186193
.title = "",
187-
.url = "about:blank",
194+
.url = ctx.state.url,
188195
.browserContextId = ContextID,
189196
},
190197
.waitingForDebugger = true,

src/server.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub const Cmd = struct {
2525
buf: []u8, // only for read operations
2626
err: ?Error = null,
2727

28+
// CDP
29+
state: cdp.State = .{},
30+
2831
// JS fields
2932
js_env: *public.Env,
3033
try_catch: public.TryCatch,

0 commit comments

Comments
 (0)