Skip to content

Commit 2f3a581

Browse files
Add TODOs and comments
Signed-off-by: Francis Bouvier <[email protected]>
1 parent 8bdd2a1 commit 2f3a581

File tree

8 files changed

+82
-32
lines changed

8 files changed

+82
-32
lines changed

src/cdp/browser.zig

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn browser(
3030
};
3131
}
3232

33+
// TODO: hard coded data
3334
const ProtocolVersion = "1.3";
3435
const Product = "Chrome/124.0.6367.29";
3536
const Revision = "@9e6ded5ac1ff5e38d930ae52bd9aec09bd1a68e4";
@@ -42,42 +43,43 @@ fn getVersion(
4243
scanner: *std.json.Scanner,
4344
_: *Ctx,
4445
) ![]const u8 {
46+
47+
// input
4548
const msg = try getMsg(alloc, void, scanner);
4649

50+
// ouput
4751
const Res = struct {
48-
protocolVersion: []const u8,
49-
product: []const u8,
50-
revision: []const u8,
51-
userAgent: []const u8,
52-
jsVersion: []const u8,
53-
};
54-
55-
const res = Res{
56-
.protocolVersion = ProtocolVersion,
57-
.product = Product,
58-
.revision = Revision,
59-
.userAgent = UserAgent,
60-
.jsVersion = JsVersion,
52+
protocolVersion: []const u8 = ProtocolVersion,
53+
product: []const u8 = Product,
54+
revision: []const u8 = Revision,
55+
userAgent: []const u8 = UserAgent,
56+
jsVersion: []const u8 = JsVersion,
6157
};
62-
return result(alloc, id orelse msg.id.?, Res, res, null);
58+
return result(alloc, id orelse msg.id.?, Res, .{}, null);
6359
}
6460

61+
// TODO: noop method
6562
fn setDownloadBehavior(
6663
alloc: std.mem.Allocator,
6764
id: ?u16,
6865
scanner: *std.json.Scanner,
6966
_: *Ctx,
7067
) ![]const u8 {
68+
69+
// input
7170
const Params = struct {
7271
behavior: []const u8,
7372
browserContextId: ?[]const u8 = null,
7473
downloadPath: ?[]const u8 = null,
7574
eventsEnabled: ?bool = null,
7675
};
7776
const msg = try getMsg(alloc, Params, scanner);
77+
78+
// output
7879
return result(alloc, id orelse msg.id.?, null, null, null);
7980
}
8081

82+
// TODO: hard coded ID
8183
const DevToolsWindowID = 1923710101;
8284

8385
fn getWindowForTarget(
@@ -108,13 +110,17 @@ fn getWindowForTarget(
108110
return result(alloc, id orelse msg.id.?, Resp, Resp{}, msg.sessionID.?);
109111
}
110112

113+
// TODO: noop method
111114
fn setWindowBounds(
112115
alloc: std.mem.Allocator,
113116
id: ?u16,
114117
scanner: *std.json.Scanner,
115118
_: *Ctx,
116119
) ![]const u8 {
117-
// NOTE: noop
120+
121+
// input
118122
const msg = try cdp.getMsg(alloc, void, scanner);
123+
124+
// output
119125
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
120126
}

src/cdp/cdp.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ pub fn getMsg(
286286
// Common
287287
// ------
288288

289+
// TODO: hard coded IDs
289290
pub const BrowserSessionID = "9559320D92474062597D9875C664CAC0";
290291
pub const ContextSessionID = "4FDC2CB760A23A220497A05C95417CF4";
291292
pub const URLBase = "chrome://newtab/";

src/cdp/emulation.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const MediaFeature = struct {
3636
value: []const u8,
3737
};
3838

39+
// TODO: noop method
3940
fn setEmulatedMedia(
4041
alloc: std.mem.Allocator,
4142
id: ?u16,
@@ -51,10 +52,10 @@ fn setEmulatedMedia(
5152
const msg = try getMsg(alloc, Params, scanner);
5253

5354
// output
54-
// TODO: dummy
5555
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
5656
}
5757

58+
// TODO: noop method
5859
fn setFocusEmulationEnabled(
5960
alloc: std.mem.Allocator,
6061
id: ?u16,
@@ -69,10 +70,10 @@ fn setFocusEmulationEnabled(
6970
const msg = try getMsg(alloc, Params, scanner);
7071

7172
// output
72-
// TODO: dummy
7373
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
7474
}
7575

76+
// TODO: noop method
7677
fn setDeviceMetricsOverride(
7778
alloc: std.mem.Allocator,
7879
id: ?u16,
@@ -87,6 +88,7 @@ fn setDeviceMetricsOverride(
8788
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
8889
}
8990

91+
// TODO: noop method
9092
fn setTouchEmulationEnabled(
9193
alloc: std.mem.Allocator,
9294
id: ?u16,

src/cdp/fetch.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn fetch(
2525
};
2626
}
2727

28+
// TODO: noop method
2829
fn disable(
2930
alloc: std.mem.Allocator,
3031
id: ?u16,

src/cdp/network.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn enable(
3838
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
3939
}
4040

41+
// TODO: noop method
4142
fn setCacheDisabled(
4243
alloc: std.mem.Allocator,
4344
id: ?u16,

src/cdp/page.zig

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const LifecycleEvent = struct {
117117
timestamp: f32 = undefined,
118118
};
119119

120+
// TODO: hard coded method
120121
fn addScriptToEvaluateOnNewDocument(
121122
alloc: std.mem.Allocator,
122123
id: ?u16,
@@ -140,6 +141,7 @@ fn addScriptToEvaluateOnNewDocument(
140141
return result(alloc, id orelse msg.id.?, Res, Res{}, msg.sessionID);
141142
}
142143

144+
// TODO: hard coded method
143145
fn createIsolatedWorld(
144146
alloc: std.mem.Allocator,
145147
id: ?u16,
@@ -202,6 +204,7 @@ fn navigate(
202204

203205
// change state
204206
ctx.state.url = params.url;
207+
// TODO: hard coded ID
205208
ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2";
206209

207210
var life_event = LifecycleEvent{
@@ -211,6 +214,7 @@ fn navigate(
211214
var ts_event: cdp.TimestampEvent = undefined;
212215

213216
// frameStartedLoading event
217+
// TODO: event partially hard coded
214218
const FrameStartedLoading = struct {
215219
frameId: []const u8,
216220
};
@@ -250,20 +254,41 @@ fn navigate(
250254
std.log.debug("res {s}", .{res});
251255
try server.sendSync(ctx, res);
252256

253-
// Send clear runtime contexts event (noop)
257+
// TODO: at this point do we need async the following actions to be async?
258+
259+
// Send Runtime.executionContextsCleared event
260+
// TODO: noop event, we have no env context at this point, is it necesarry?
254261
try sendEvent(alloc, ctx, "Runtime.executionContextsCleared", void, {}, msg.sessionID);
255262

256263
// Launch navigate
257264
var p = try ctx.browser.currentSession().createPage();
258265
ctx.state.executionContextId += 1;
259266
const auxData = try std.fmt.allocPrint(
260267
alloc,
268+
// TODO: we assume this is the default web page, is it right?
261269
"{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}",
262270
.{ctx.state.frameID},
263271
);
264272
defer alloc.free(auxData);
265273
_ = try p.navigate(params.url, auxData);
266274

275+
// Events
276+
277+
// lifecycle init event
278+
// TODO: partially hard coded
279+
if (ctx.state.page_life_cycle_events) {
280+
life_event.name = "init";
281+
life_event.timestamp = 343721.796037;
282+
try sendEvent(
283+
alloc,
284+
ctx,
285+
"Page.lifecycleEvent",
286+
LifecycleEvent,
287+
life_event,
288+
msg.sessionID,
289+
);
290+
}
291+
267292
// frameNavigated event
268293
const FrameNavigated = struct {
269294
frame: Frame,
@@ -286,20 +311,9 @@ fn navigate(
286311
frame_navigated,
287312
msg.sessionID,
288313
);
289-
if (ctx.state.page_life_cycle_events) {
290-
life_event.name = "load";
291-
life_event.timestamp = 343721.824655;
292-
try sendEvent(
293-
alloc,
294-
ctx,
295-
"Page.lifecycleEvent",
296-
LifecycleEvent,
297-
life_event,
298-
msg.sessionID,
299-
);
300-
}
301314

302315
// domContentEventFired event
316+
// TODO: partially hard coded
303317
ts_event = .{ .timestamp = 343721.803338 };
304318
try sendEvent(
305319
alloc,
@@ -309,6 +323,9 @@ fn navigate(
309323
ts_event,
310324
msg.sessionID,
311325
);
326+
327+
// lifecycle DOMContentLoaded event
328+
// TODO: partially hard coded
312329
if (ctx.state.page_life_cycle_events) {
313330
life_event.name = "DOMContentLoaded";
314331
life_event.timestamp = 343721.803338;
@@ -323,6 +340,7 @@ fn navigate(
323340
}
324341

325342
// loadEventFired event
343+
// TODO: partially hard coded
326344
ts_event = .{ .timestamp = 343721.824655 };
327345
try sendEvent(
328346
alloc,
@@ -332,6 +350,9 @@ fn navigate(
332350
ts_event,
333351
msg.sessionID,
334352
);
353+
354+
// lifecycle DOMContentLoaded event
355+
// TODO: partially hard coded
335356
if (ctx.state.page_life_cycle_events) {
336357
life_event.name = "load";
337358
life_event.timestamp = 343721.824655;

src/cdp/runtime.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ pub fn executionContextCreated(
140140
try cdp.sendEvent(alloc, ctx, "Runtime.executionContextCreated", Params, params, sessionID);
141141
}
142142

143+
// TODO: noop method
144+
// should we be passing this also to the JS Inspector?
143145
fn runIfWaitingForDebugger(
144146
alloc: std.mem.Allocator,
145147
id: ?u16,

src/cdp/target.zig

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,23 @@ pub fn target(
3939
};
4040
}
4141

42+
// TODO: hard coded IDs
4243
const PageTargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC";
4344
const BrowserTargetID = "2d2bdef9-1c95-416f-8c0e-83f3ab73a30c";
4445
const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9";
4546

47+
// TODO: noop method
4648
fn setDiscoverTargets(
4749
alloc: std.mem.Allocator,
4850
id: ?u16,
4951
scanner: *std.json.Scanner,
5052
_: *Ctx,
5153
) ![]const u8 {
54+
55+
// input
5256
const msg = try getMsg(alloc, void, scanner);
5357

58+
// output
5459
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
5560
}
5661

@@ -73,6 +78,7 @@ const TargetFilter = struct {
7378
exclude: ?bool = null,
7479
};
7580

81+
// TODO: noop method
7682
fn setAutoAttach(
7783
alloc: std.mem.Allocator,
7884
id: ?u16,
@@ -90,6 +96,7 @@ fn setAutoAttach(
9096
const msg = try getMsg(alloc, Params, scanner);
9197
std.log.debug("params {any}", .{msg.params});
9298

99+
// attachedToTarget event
93100
if (msg.sessionID == null) {
94101
const attached = AttachToTarget{
95102
.sessionId = cdp.BrowserSessionID,
@@ -103,6 +110,7 @@ fn setAutoAttach(
103110
try cdp.sendEvent(alloc, ctx, "Target.attachedToTarget", AttachToTarget, attached, null);
104111
}
105112

113+
// output
106114
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
107115
}
108116

@@ -142,12 +150,15 @@ fn getTargetInfo(
142150
// Browser context are not handled and not in the roadmap for now
143151
// The following methods are "fake"
144152

153+
// TODO: noop method
145154
fn getBrowserContexts(
146155
alloc: std.mem.Allocator,
147156
id: ?u16,
148157
scanner: *std.json.Scanner,
149158
ctx: *Ctx,
150159
) ![]const u8 {
160+
161+
// input
151162
const msg = try getMsg(alloc, void, scanner);
152163

153164
// ouptut
@@ -167,6 +178,7 @@ fn getBrowserContexts(
167178

168179
const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89";
169180

181+
// TODO: noop method
170182
fn createBrowserContext(
171183
alloc: std.mem.Allocator,
172184
id: ?u16,
@@ -205,10 +217,13 @@ fn disposeBrowserContext(
205217
};
206218
const msg = try getMsg(alloc, Params, scanner);
207219

220+
// output
208221
return result(alloc, id orelse msg.id.?, null, {}, null);
209222
}
210223

224+
// TODO: hard coded IDs
211225
const TargetID = "57356548460A8F29706A2ADF14316298";
226+
const LoaderID = "DD4A76F842AA389647D702B4D805F49A";
212227

213228
fn createTarget(
214229
alloc: std.mem.Allocator,
@@ -235,7 +250,7 @@ fn createTarget(
235250
ctx.state.url = "about:blank";
236251
ctx.state.securityOrigin = "://";
237252
ctx.state.secureContextType = "InsecureScheme";
238-
ctx.state.loaderID = "DD4A76F842AA389647D702B4D805F49A";
253+
ctx.state.loaderID = LoaderID;
239254

240255
// send attachToTarget event
241256
const attached = AttachToTarget{
@@ -277,7 +292,7 @@ fn closeTarget(
277292
const res = try result(alloc, id orelse msg.id.?, Resp, Resp{}, null);
278293
try server.sendSync(ctx, res);
279294

280-
// events
295+
// Inspector.detached event
281296
const InspectorDetached = struct {
282297
reason: []const u8 = "Render process gone.",
283298
};
@@ -290,6 +305,7 @@ fn closeTarget(
290305
msg.sessionID orelse cdp.ContextSessionID,
291306
);
292307

308+
// detachedFromTarget event
293309
const TargetDetached = struct {
294310
sessionId: []const u8,
295311
targetId: []const u8,

0 commit comments

Comments
 (0)