mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Let Page.navigate do actually navigation
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -262,3 +262,7 @@ pub const SessionID = "9559320D92474062597D9875C664CAC0";
|
|||||||
pub const URLBase = "chrome://newtab/";
|
pub const URLBase = "chrome://newtab/";
|
||||||
pub const FrameID = "90D14BBD8AED408A0467AC93100BCDBE";
|
pub const FrameID = "90D14BBD8AED408A0467AC93100BCDBE";
|
||||||
pub const LoaderID = "CFC8BED824DD2FD56CF1EF33C965C79C";
|
pub const LoaderID = "CFC8BED824DD2FD56CF1EF33C965C79C";
|
||||||
|
|
||||||
|
pub const TimestampEvent = struct {
|
||||||
|
timestamp: f64,
|
||||||
|
};
|
||||||
|
|||||||
116
src/cdp/page.zig
116
src/cdp/page.zig
@@ -6,6 +6,7 @@ const cdp = @import("cdp.zig");
|
|||||||
const result = cdp.result;
|
const result = cdp.result;
|
||||||
const getParams = cdp.getParams;
|
const getParams = cdp.getParams;
|
||||||
const stringify = cdp.stringify;
|
const stringify = cdp.stringify;
|
||||||
|
const sendEvent = cdp.sendEvent;
|
||||||
|
|
||||||
const PageMethods = enum {
|
const PageMethods = enum {
|
||||||
enable,
|
enable,
|
||||||
@@ -45,6 +46,21 @@ fn enable(
|
|||||||
return result(alloc, id, null, null, sessionID);
|
return result(alloc, id, null, null, sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Frame = struct {
|
||||||
|
id: []const u8,
|
||||||
|
loaderId: []const u8,
|
||||||
|
url: []const u8,
|
||||||
|
domainAndRegistry: []const u8 = "",
|
||||||
|
securityOrigin: []const u8,
|
||||||
|
mimeType: []const u8 = "text/html",
|
||||||
|
adFrameStatus: struct {
|
||||||
|
adFrameType: []const u8 = "none",
|
||||||
|
} = .{},
|
||||||
|
secureContextType: []const u8,
|
||||||
|
crossOriginIsolatedContextType: []const u8 = "NotIsolated",
|
||||||
|
gatedAPIFeatures: [][]const u8 = &[0][]const u8{},
|
||||||
|
};
|
||||||
|
|
||||||
fn getFrameTree(
|
fn getFrameTree(
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
id: u64,
|
id: u64,
|
||||||
@@ -54,20 +70,7 @@ fn getFrameTree(
|
|||||||
const sessionID = try cdp.getSessionID(scanner);
|
const sessionID = try cdp.getSessionID(scanner);
|
||||||
const FrameTree = struct {
|
const FrameTree = struct {
|
||||||
frameTree: struct {
|
frameTree: struct {
|
||||||
frame: struct {
|
frame: Frame,
|
||||||
id: []const u8,
|
|
||||||
loaderId: []const u8,
|
|
||||||
url: []const u8,
|
|
||||||
domainAndRegistry: []const u8 = "",
|
|
||||||
securityOrigin: []const u8,
|
|
||||||
mimeType: []const u8 = "text/html",
|
|
||||||
adFrameStatus: struct {
|
|
||||||
adFrameType: []const u8 = "none",
|
|
||||||
} = .{},
|
|
||||||
secureContextType: []const u8,
|
|
||||||
crossOriginIsolatedContextType: []const u8 = "NotIsolated",
|
|
||||||
gatedAPIFeatures: [][]const u8 = &[0][]const u8{},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
childFrames: ?[]@This() = null,
|
childFrames: ?[]@This() = null,
|
||||||
};
|
};
|
||||||
@@ -105,6 +108,13 @@ fn setLifecycleEventsEnabled(
|
|||||||
return result(alloc, id, null, null, sessionID);
|
return result(alloc, id, null, null, sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LifeCycleEvent = struct {
|
||||||
|
frameId: []const u8,
|
||||||
|
loaderId: ?[]const u8,
|
||||||
|
name: []const u8 = undefined,
|
||||||
|
timestamp: f32 = undefined,
|
||||||
|
};
|
||||||
|
|
||||||
fn addScriptToEvaluateOnNewDocument(
|
fn addScriptToEvaluateOnNewDocument(
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
id: u64,
|
id: u64,
|
||||||
@@ -162,14 +172,31 @@ fn navigate(
|
|||||||
frameId: ?[]const u8 = null,
|
frameId: ?[]const u8 = null,
|
||||||
referrerPolicy: ?[]const u8 = null, // TODO: enum
|
referrerPolicy: ?[]const u8 = null, // TODO: enum
|
||||||
};
|
};
|
||||||
const content = try cdp.getContent(alloc, Params, scanner);
|
const input = try cdp.getContent(alloc, Params, scanner);
|
||||||
std.debug.assert(content.sessionID != null);
|
const sessionID = input.sessionID;
|
||||||
|
std.debug.assert(sessionID != null);
|
||||||
|
|
||||||
// change state
|
// change state
|
||||||
ctx.state.url = content.params.url;
|
ctx.state.url = input.params.url;
|
||||||
ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2";
|
ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2";
|
||||||
|
|
||||||
var page = try ctx.browser.currentSession().createPage();
|
var life_event = LifeCycleEvent{
|
||||||
|
.frameId = ctx.state.frameID,
|
||||||
|
.loaderId = ctx.state.loaderID,
|
||||||
|
};
|
||||||
|
var ts_event: cdp.TimestampEvent = undefined;
|
||||||
|
|
||||||
|
// frameStartedLoading event
|
||||||
|
const FrameStartedLoading = struct {
|
||||||
|
frameId: []const u8,
|
||||||
|
};
|
||||||
|
const frame_started_loading = FrameStartedLoading{ .frameId = ctx.state.frameID };
|
||||||
|
try sendEvent(alloc, ctx, "Page.frameStartedLoading", FrameStartedLoading, frame_started_loading, sessionID);
|
||||||
|
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, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
// output
|
// output
|
||||||
const Resp = struct {
|
const Resp = struct {
|
||||||
@@ -181,5 +208,56 @@ fn navigate(
|
|||||||
.frameId = ctx.state.frameID,
|
.frameId = ctx.state.frameID,
|
||||||
.loaderId = ctx.state.loaderID,
|
.loaderId = ctx.state.loaderID,
|
||||||
};
|
};
|
||||||
return result(alloc, id, Resp, resp, content.sessionID);
|
const res = try result(alloc, id, Resp, resp, sessionID);
|
||||||
|
std.log.debug("res {s}", .{res});
|
||||||
|
try server.sendSync(ctx, res);
|
||||||
|
|
||||||
|
// launch navigate
|
||||||
|
var p = try ctx.browser.currentSession().createPage();
|
||||||
|
_ = try p.navigate(input.params.url);
|
||||||
|
|
||||||
|
// frameNavigated event
|
||||||
|
const FrameNavigated = struct {
|
||||||
|
frame: Frame,
|
||||||
|
type: []const u8 = "Navigation",
|
||||||
|
};
|
||||||
|
const frame_navigated = FrameNavigated{
|
||||||
|
.frame = .{
|
||||||
|
.id = ctx.state.frameID,
|
||||||
|
.url = ctx.state.url,
|
||||||
|
.securityOrigin = ctx.state.securityOrigin,
|
||||||
|
.secureContextType = ctx.state.secureContextType,
|
||||||
|
.loaderId = ctx.state.loaderID,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
try sendEvent(alloc, ctx, "Page.frameNavigated", FrameNavigated, frame_navigated, 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, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// domContentEventFired event
|
||||||
|
ts_event = .{ .timestamp = 343721.803338 };
|
||||||
|
try sendEvent(alloc, ctx, "Page.domContentEventFired", cdp.TimestampEvent, ts_event, sessionID);
|
||||||
|
if (ctx.state.page_life_cycle_events) {
|
||||||
|
life_event.name = "DOMContentLoaded";
|
||||||
|
life_event.timestamp = 343721.803338;
|
||||||
|
try sendEvent(alloc, ctx, "Page.lifeCycleEvent", LifeCycleEvent, life_event, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadEventFired event
|
||||||
|
ts_event = .{ .timestamp = 343721.824655 };
|
||||||
|
try sendEvent(alloc, ctx, "Page.loadEventFired", cdp.TimestampEvent, ts_event, 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, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// frameStoppedLoading
|
||||||
|
const FrameStoppedLoading = struct { frameId: []const u8 };
|
||||||
|
try sendEvent(alloc, ctx, "Page.frameStoppedLoading", FrameStoppedLoading, .{ .frameId = ctx.state.frameID }, sessionID);
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,9 +76,12 @@ pub const Cmd = struct {
|
|||||||
}
|
}
|
||||||
@panic(@errorName(err));
|
@panic(@errorName(err));
|
||||||
};
|
};
|
||||||
std.log.debug("res {s}", .{res});
|
|
||||||
|
|
||||||
sendAsync(self, res) catch unreachable;
|
// send result
|
||||||
|
if (!std.mem.eql(u8, res, "")) {
|
||||||
|
std.log.debug("res {s}", .{res});
|
||||||
|
sendAsync(self, res) catch unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
if (pos == null) break;
|
if (pos == null) break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user