Add TODOs and comments

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-01 17:48:54 +02:00
parent 8bdd2a14e8
commit 2f3a581859
8 changed files with 82 additions and 32 deletions

View File

@@ -30,6 +30,7 @@ pub fn browser(
}; };
} }
// TODO: hard coded data
const ProtocolVersion = "1.3"; const ProtocolVersion = "1.3";
const Product = "Chrome/124.0.6367.29"; const Product = "Chrome/124.0.6367.29";
const Revision = "@9e6ded5ac1ff5e38d930ae52bd9aec09bd1a68e4"; const Revision = "@9e6ded5ac1ff5e38d930ae52bd9aec09bd1a68e4";
@@ -42,32 +43,30 @@ fn getVersion(
scanner: *std.json.Scanner, scanner: *std.json.Scanner,
_: *Ctx, _: *Ctx,
) ![]const u8 { ) ![]const u8 {
// input
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, void, scanner);
// ouput
const Res = struct { const Res = struct {
protocolVersion: []const u8, protocolVersion: []const u8 = ProtocolVersion,
product: []const u8, product: []const u8 = Product,
revision: []const u8, revision: []const u8 = Revision,
userAgent: []const u8, userAgent: []const u8 = UserAgent,
jsVersion: []const u8, jsVersion: []const u8 = JsVersion,
}; };
return result(alloc, id orelse msg.id.?, Res, .{}, null);
const res = Res{
.protocolVersion = ProtocolVersion,
.product = Product,
.revision = Revision,
.userAgent = UserAgent,
.jsVersion = JsVersion,
};
return result(alloc, id orelse msg.id.?, Res, res, null);
} }
// 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 {
// input
const Params = struct { const Params = struct {
behavior: []const u8, behavior: []const u8,
browserContextId: ?[]const u8 = null, browserContextId: ?[]const u8 = null,
@@ -75,9 +74,12 @@ fn setDownloadBehavior(
eventsEnabled: ?bool = null, eventsEnabled: ?bool = null,
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, Params, scanner);
// output
return result(alloc, id orelse msg.id.?, null, null, null); return result(alloc, id orelse msg.id.?, null, null, null);
} }
// TODO: hard coded ID
const DevToolsWindowID = 1923710101; const DevToolsWindowID = 1923710101;
fn getWindowForTarget( fn getWindowForTarget(
@@ -108,13 +110,17 @@ fn getWindowForTarget(
return result(alloc, id orelse msg.id.?, Resp, Resp{}, msg.sessionID.?); return result(alloc, id orelse msg.id.?, Resp, Resp{}, msg.sessionID.?);
} }
// 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 {
// NOTE: noop
// input
const msg = try cdp.getMsg(alloc, void, scanner); const msg = try cdp.getMsg(alloc, void, scanner);
// output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
} }

View File

@@ -286,6 +286,7 @@ pub fn getMsg(
// Common // Common
// ------ // ------
// TODO: hard coded IDs
pub const BrowserSessionID = "9559320D92474062597D9875C664CAC0"; pub const BrowserSessionID = "9559320D92474062597D9875C664CAC0";
pub const ContextSessionID = "4FDC2CB760A23A220497A05C95417CF4"; pub const ContextSessionID = "4FDC2CB760A23A220497A05C95417CF4";
pub const URLBase = "chrome://newtab/"; pub const URLBase = "chrome://newtab/";

View File

@@ -36,6 +36,7 @@ const MediaFeature = struct {
value: []const u8, value: []const u8,
}; };
// TODO: noop method
fn setEmulatedMedia( fn setEmulatedMedia(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,
@@ -51,10 +52,10 @@ fn setEmulatedMedia(
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, Params, scanner);
// output // output
// TODO: dummy
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
} }
// TODO: noop method
fn setFocusEmulationEnabled( fn setFocusEmulationEnabled(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,
@@ -69,10 +70,10 @@ fn setFocusEmulationEnabled(
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, Params, scanner);
// output // output
// TODO: dummy
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
} }
// TODO: noop method
fn setDeviceMetricsOverride( fn setDeviceMetricsOverride(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,
@@ -87,6 +88,7 @@ fn setDeviceMetricsOverride(
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
} }
// TODO: noop method
fn setTouchEmulationEnabled( fn setTouchEmulationEnabled(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,

View File

@@ -25,6 +25,7 @@ pub fn fetch(
}; };
} }
// TODO: noop method
fn disable( fn disable(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,

View File

@@ -38,6 +38,7 @@ fn enable(
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
} }
// TODO: noop method
fn setCacheDisabled( fn setCacheDisabled(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,

View File

@@ -117,6 +117,7 @@ const LifecycleEvent = struct {
timestamp: f32 = undefined, timestamp: f32 = undefined,
}; };
// TODO: hard coded method
fn addScriptToEvaluateOnNewDocument( fn addScriptToEvaluateOnNewDocument(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,
@@ -140,6 +141,7 @@ fn addScriptToEvaluateOnNewDocument(
return result(alloc, id orelse msg.id.?, Res, Res{}, msg.sessionID); return result(alloc, id orelse msg.id.?, Res, Res{}, msg.sessionID);
} }
// TODO: hard coded method
fn createIsolatedWorld( fn createIsolatedWorld(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,
@@ -202,6 +204,7 @@ fn navigate(
// change state // change state
ctx.state.url = params.url; ctx.state.url = params.url;
// TODO: hard coded ID
ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2"; ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2";
var life_event = LifecycleEvent{ var life_event = LifecycleEvent{
@@ -211,6 +214,7 @@ fn navigate(
var ts_event: cdp.TimestampEvent = undefined; var ts_event: cdp.TimestampEvent = undefined;
// frameStartedLoading event // frameStartedLoading event
// TODO: event partially hard coded
const FrameStartedLoading = struct { const FrameStartedLoading = struct {
frameId: []const u8, frameId: []const u8,
}; };
@@ -250,7 +254,10 @@ fn navigate(
std.log.debug("res {s}", .{res}); std.log.debug("res {s}", .{res});
try server.sendSync(ctx, res); try server.sendSync(ctx, res);
// Send clear runtime contexts event (noop) // TODO: at this point do we need async the following actions to be async?
// Send Runtime.executionContextsCleared event
// TODO: noop event, we have no env context at this point, is it necesarry?
try sendEvent(alloc, ctx, "Runtime.executionContextsCleared", void, {}, msg.sessionID); try sendEvent(alloc, ctx, "Runtime.executionContextsCleared", void, {}, msg.sessionID);
// Launch navigate // Launch navigate
@@ -258,12 +265,30 @@ fn navigate(
ctx.state.executionContextId += 1; ctx.state.executionContextId += 1;
const auxData = try std.fmt.allocPrint( const auxData = try std.fmt.allocPrint(
alloc, alloc,
// TODO: we assume this is the default web page, is it right?
"{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}",
.{ctx.state.frameID}, .{ctx.state.frameID},
); );
defer alloc.free(auxData); defer alloc.free(auxData);
_ = try p.navigate(params.url, auxData); _ = try p.navigate(params.url, auxData);
// Events
// lifecycle init event
// TODO: partially hard coded
if (ctx.state.page_life_cycle_events) {
life_event.name = "init";
life_event.timestamp = 343721.796037;
try sendEvent(
alloc,
ctx,
"Page.lifecycleEvent",
LifecycleEvent,
life_event,
msg.sessionID,
);
}
// frameNavigated event // frameNavigated event
const FrameNavigated = struct { const FrameNavigated = struct {
frame: Frame, frame: Frame,
@@ -286,20 +311,9 @@ fn navigate(
frame_navigated, frame_navigated,
msg.sessionID, msg.sessionID,
); );
if (ctx.state.page_life_cycle_events) {
life_event.name = "load";
life_event.timestamp = 343721.824655;
try sendEvent(
alloc,
ctx,
"Page.lifecycleEvent",
LifecycleEvent,
life_event,
msg.sessionID,
);
}
// domContentEventFired event // domContentEventFired event
// TODO: partially hard coded
ts_event = .{ .timestamp = 343721.803338 }; ts_event = .{ .timestamp = 343721.803338 };
try sendEvent( try sendEvent(
alloc, alloc,
@@ -309,6 +323,9 @@ fn navigate(
ts_event, ts_event,
msg.sessionID, msg.sessionID,
); );
// lifecycle DOMContentLoaded event
// TODO: partially hard coded
if (ctx.state.page_life_cycle_events) { if (ctx.state.page_life_cycle_events) {
life_event.name = "DOMContentLoaded"; life_event.name = "DOMContentLoaded";
life_event.timestamp = 343721.803338; life_event.timestamp = 343721.803338;
@@ -323,6 +340,7 @@ fn navigate(
} }
// loadEventFired event // loadEventFired event
// TODO: partially hard coded
ts_event = .{ .timestamp = 343721.824655 }; ts_event = .{ .timestamp = 343721.824655 };
try sendEvent( try sendEvent(
alloc, alloc,
@@ -332,6 +350,9 @@ fn navigate(
ts_event, ts_event,
msg.sessionID, msg.sessionID,
); );
// lifecycle DOMContentLoaded event
// TODO: partially hard coded
if (ctx.state.page_life_cycle_events) { if (ctx.state.page_life_cycle_events) {
life_event.name = "load"; life_event.name = "load";
life_event.timestamp = 343721.824655; life_event.timestamp = 343721.824655;

View File

@@ -140,6 +140,8 @@ pub fn executionContextCreated(
try cdp.sendEvent(alloc, ctx, "Runtime.executionContextCreated", Params, params, sessionID); try cdp.sendEvent(alloc, ctx, "Runtime.executionContextCreated", Params, params, sessionID);
} }
// TODO: noop method
// 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,

View File

@@ -39,18 +39,23 @@ pub fn target(
}; };
} }
// TODO: hard coded IDs
const PageTargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC"; const PageTargetID = "CFCD6EC01573CF29BB638E9DC0F52DDC";
const BrowserTargetID = "2d2bdef9-1c95-416f-8c0e-83f3ab73a30c"; const BrowserTargetID = "2d2bdef9-1c95-416f-8c0e-83f3ab73a30c";
const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9"; const BrowserContextID = "65618675CB7D3585A95049E9DFE95EA9";
// 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
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, void, scanner);
// output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
} }
@@ -73,6 +78,7 @@ const TargetFilter = struct {
exclude: ?bool = null, exclude: ?bool = null,
}; };
// TODO: noop method
fn setAutoAttach( fn setAutoAttach(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,
@@ -90,6 +96,7 @@ fn setAutoAttach(
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, Params, scanner);
std.log.debug("params {any}", .{msg.params}); std.log.debug("params {any}", .{msg.params});
// attachedToTarget event
if (msg.sessionID == null) { if (msg.sessionID == null) {
const attached = AttachToTarget{ const attached = AttachToTarget{
.sessionId = cdp.BrowserSessionID, .sessionId = cdp.BrowserSessionID,
@@ -103,6 +110,7 @@ fn setAutoAttach(
try cdp.sendEvent(alloc, ctx, "Target.attachedToTarget", AttachToTarget, attached, null); try cdp.sendEvent(alloc, ctx, "Target.attachedToTarget", AttachToTarget, attached, null);
} }
// output
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
} }
@@ -142,12 +150,15 @@ fn getTargetInfo(
// Browser context are not handled and not in the roadmap for now // Browser context are not handled and not in the roadmap for now
// The following methods are "fake" // The following methods are "fake"
// 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
const msg = try getMsg(alloc, void, scanner); const msg = try getMsg(alloc, void, scanner);
// ouptut // ouptut
@@ -167,6 +178,7 @@ fn getBrowserContexts(
const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89"; const ContextID = "22648B09EDCCDD11109E2D4FEFBE4F89";
// TODO: noop method
fn createBrowserContext( fn createBrowserContext(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
id: ?u16, id: ?u16,
@@ -205,10 +217,13 @@ fn disposeBrowserContext(
}; };
const msg = try getMsg(alloc, Params, scanner); const msg = try getMsg(alloc, Params, scanner);
// output
return result(alloc, id orelse msg.id.?, null, {}, null); return result(alloc, id orelse msg.id.?, null, {}, null);
} }
// TODO: hard coded IDs
const TargetID = "57356548460A8F29706A2ADF14316298"; const TargetID = "57356548460A8F29706A2ADF14316298";
const LoaderID = "DD4A76F842AA389647D702B4D805F49A";
fn createTarget( fn createTarget(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
@@ -235,7 +250,7 @@ fn createTarget(
ctx.state.url = "about:blank"; ctx.state.url = "about:blank";
ctx.state.securityOrigin = "://"; ctx.state.securityOrigin = "://";
ctx.state.secureContextType = "InsecureScheme"; ctx.state.secureContextType = "InsecureScheme";
ctx.state.loaderID = "DD4A76F842AA389647D702B4D805F49A"; ctx.state.loaderID = LoaderID;
// send attachToTarget event // send attachToTarget event
const attached = AttachToTarget{ const attached = AttachToTarget{
@@ -277,7 +292,7 @@ fn closeTarget(
const res = try result(alloc, id orelse msg.id.?, Resp, Resp{}, null); const res = try result(alloc, id orelse msg.id.?, Resp, Resp{}, null);
try server.sendSync(ctx, res); try server.sendSync(ctx, res);
// events // Inspector.detached event
const InspectorDetached = struct { const InspectorDetached = struct {
reason: []const u8 = "Render process gone.", reason: []const u8 = "Render process gone.",
}; };
@@ -290,6 +305,7 @@ fn closeTarget(
msg.sessionID orelse cdp.ContextSessionID, msg.sessionID orelse cdp.ContextSessionID,
); );
// detachedFromTarget event
const TargetDetached = struct { const TargetDetached = struct {
sessionId: []const u8, sessionId: []const u8,
targetId: []const u8, targetId: []const u8,