mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
@@ -28,7 +28,6 @@ const log = std.log.scoped(.cdp);
|
|||||||
|
|
||||||
pub const URL_BASE = "chrome://newtab/";
|
pub const URL_BASE = "chrome://newtab/";
|
||||||
pub const LOADER_ID = "LOADERID24DD2FD56CF1EF33C965C79C";
|
pub const LOADER_ID = "LOADERID24DD2FD56CF1EF33C965C79C";
|
||||||
pub const FRAME_ID = "FRAMEIDD8AED408A0467AC93100BCDBE";
|
|
||||||
|
|
||||||
pub const TimestampEvent = struct {
|
pub const TimestampEvent = struct {
|
||||||
timestamp: f64,
|
timestamp: f64,
|
||||||
@@ -282,7 +281,6 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
|||||||
|
|
||||||
// State
|
// State
|
||||||
url: []const u8,
|
url: []const u8,
|
||||||
frame_id: []const u8,
|
|
||||||
loader_id: []const u8,
|
loader_id: []const u8,
|
||||||
security_origin: []const u8,
|
security_origin: []const u8,
|
||||||
page_life_cycle_events: bool,
|
page_life_cycle_events: bool,
|
||||||
@@ -301,7 +299,6 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
|||||||
.target_id = null,
|
.target_id = null,
|
||||||
.session_id = null,
|
.session_id = null,
|
||||||
.url = URL_BASE,
|
.url = URL_BASE,
|
||||||
.frame_id = FRAME_ID,
|
|
||||||
.security_origin = URL_BASE,
|
.security_origin = URL_BASE,
|
||||||
.secure_context_type = "Secure", // TODO = enum
|
.secure_context_type = "Secure", // TODO = enum
|
||||||
.loader_id = LOADER_ID,
|
.loader_id = LOADER_ID,
|
||||||
|
|||||||
@@ -57,12 +57,13 @@ const Frame = struct {
|
|||||||
|
|
||||||
fn getFrameTree(cmd: anytype) !void {
|
fn getFrameTree(cmd: anytype) !void {
|
||||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||||
|
const target_id = bc.target_id orelse return error.TargetNotLoaded;
|
||||||
|
|
||||||
return cmd.sendResult(.{
|
return cmd.sendResult(.{
|
||||||
.frameTree = .{
|
.frameTree = .{
|
||||||
.frame = Frame{
|
.frame = Frame{
|
||||||
.url = bc.url,
|
.url = bc.url,
|
||||||
.id = bc.frame_id,
|
.id = target_id,
|
||||||
.loaderId = bc.loader_id,
|
.loaderId = bc.loader_id,
|
||||||
.securityOrigin = bc.security_origin,
|
.securityOrigin = bc.security_origin,
|
||||||
.secureContextType = bc.secure_context_type,
|
.secureContextType = bc.secure_context_type,
|
||||||
@@ -132,7 +133,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||||
|
|
||||||
// didn't create?
|
// didn't create?
|
||||||
_ = bc.target_id orelse return error.TargetIdNotLoaded;
|
const target_id = bc.target_id orelse return error.TargetIdNotLoaded;
|
||||||
|
|
||||||
// didn't attach?
|
// didn't attach?
|
||||||
const session_id = bc.session_id orelse return error.SessionIdNotLoaded;
|
const session_id = bc.session_id orelse return error.SessionIdNotLoaded;
|
||||||
@@ -163,7 +164,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var life_event = LifecycleEvent{
|
var life_event = LifecycleEvent{
|
||||||
.frameId = bc.frame_id,
|
.frameId = target_id,
|
||||||
.loaderId = bc.loader_id,
|
.loaderId = bc.loader_id,
|
||||||
.name = "init",
|
.name = "init",
|
||||||
.timestamp = 343721.796037,
|
.timestamp = 343721.796037,
|
||||||
@@ -172,7 +173,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
// frameStartedLoading event
|
// frameStartedLoading event
|
||||||
// TODO: event partially hard coded
|
// TODO: event partially hard coded
|
||||||
try cmd.sendEvent("Page.frameStartedLoading", .{
|
try cmd.sendEvent("Page.frameStartedLoading", .{
|
||||||
.frameId = bc.frame_id,
|
.frameId = target_id,
|
||||||
}, .{ .session_id = session_id });
|
}, .{ .session_id = session_id });
|
||||||
|
|
||||||
if (bc.page_life_cycle_events) {
|
if (bc.page_life_cycle_events) {
|
||||||
@@ -181,7 +182,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
|
|
||||||
// output
|
// output
|
||||||
try cmd.sendResult(.{
|
try cmd.sendResult(.{
|
||||||
.frameId = bc.frame_id,
|
.frameId = target_id,
|
||||||
.loaderId = bc.loader_id,
|
.loaderId = bc.loader_id,
|
||||||
}, .{});
|
}, .{});
|
||||||
|
|
||||||
@@ -195,7 +196,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
cmd.arena,
|
cmd.arena,
|
||||||
// NOTE: we assume this is the default web page
|
// NOTE: we assume this is the default web page
|
||||||
"{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}",
|
"{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}",
|
||||||
.{bc.frame_id},
|
.{target_id},
|
||||||
);
|
);
|
||||||
|
|
||||||
var page = bc.session.currentPage().?;
|
var page = bc.session.currentPage().?;
|
||||||
@@ -217,7 +218,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
try cmd.sendEvent("Page.frameNavigated", .{
|
try cmd.sendEvent("Page.frameNavigated", .{
|
||||||
.type = "Navigation",
|
.type = "Navigation",
|
||||||
.frame = Frame{
|
.frame = Frame{
|
||||||
.id = bc.frame_id,
|
.id = target_id,
|
||||||
.url = bc.url,
|
.url = bc.url,
|
||||||
.securityOrigin = bc.security_origin,
|
.securityOrigin = bc.security_origin,
|
||||||
.secureContextType = bc.secure_context_type,
|
.secureContextType = bc.secure_context_type,
|
||||||
@@ -259,7 +260,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
|
|
||||||
// frameStoppedLoading
|
// frameStoppedLoading
|
||||||
return cmd.sendEvent("Page.frameStoppedLoading", .{
|
return cmd.sendEvent("Page.frameStoppedLoading", .{
|
||||||
.frameId = bc.frame_id,
|
.frameId = target_id,
|
||||||
}, .{ .session_id = session_id });
|
}, .{ .session_id = session_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,13 +274,13 @@ test "cdp.page: getFrameTree" {
|
|||||||
try ctx.expectSentError(-31998, "BrowserContextNotLoaded", .{ .id = 10 });
|
try ctx.expectSentError(-31998, "BrowserContextNotLoaded", .{ .id = 10 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9" });
|
const bc = try ctx.loadBrowserContext(.{ .id = "BID-9", .target_id = "TID-3" });
|
||||||
{
|
{
|
||||||
try ctx.processMessage(.{ .id = 11, .method = "Page.getFrameTree" });
|
try ctx.processMessage(.{ .id = 11, .method = "Page.getFrameTree" });
|
||||||
try ctx.expectSentResult(.{
|
try ctx.expectSentResult(.{
|
||||||
.frameTree = .{
|
.frameTree = .{
|
||||||
.frame = .{
|
.frame = .{
|
||||||
.id = bc.frame_id,
|
.id = "TID-3",
|
||||||
.loaderId = bc.loader_id,
|
.loaderId = bc.loader_id,
|
||||||
.url = bc.url,
|
.url = bc.url,
|
||||||
.domainAndRegistry = "",
|
.domainAndRegistry = "",
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ pub const ExecutionContextCreated = struct {
|
|||||||
pub const AuxData = struct {
|
pub const AuxData = struct {
|
||||||
isDefault: bool = true,
|
isDefault: bool = true,
|
||||||
type: []const u8 = "default",
|
type: []const u8 = "default",
|
||||||
frameId: []const u8 = cdp.FRAME_ID,
|
frameId: []const u8,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ fn getTargetInfo(cmd: anytype) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return cmd.sendResult(.{
|
return cmd.sendResult(.{
|
||||||
.targetInfo = .{
|
.targetInfo = TargetInfo{
|
||||||
.targetId = target_id,
|
.targetId = target_id,
|
||||||
.type = "page",
|
.type = "page",
|
||||||
.title = "",
|
.title = "",
|
||||||
@@ -243,7 +243,8 @@ fn getTargetInfo(cmd: anytype) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return cmd.sendResult(.{
|
return cmd.sendResult(.{
|
||||||
.targetInfo = .{
|
.targetInfo = TargetInfo{
|
||||||
|
.targetId = "TID-STARTUP-B",
|
||||||
.type = "browser",
|
.type = "browser",
|
||||||
.title = "",
|
.title = "",
|
||||||
.url = "",
|
.url = "",
|
||||||
@@ -342,9 +343,9 @@ fn setAutoAttach(cmd: anytype) !void {
|
|||||||
try cmd.sendEvent("Target.attachedToTarget", AttachToTarget{
|
try cmd.sendEvent("Target.attachedToTarget", AttachToTarget{
|
||||||
.sessionId = "STARTUP",
|
.sessionId = "STARTUP",
|
||||||
.targetInfo = TargetInfo{
|
.targetInfo = TargetInfo{
|
||||||
.type = "browser",
|
.type = "page",
|
||||||
.targetId = "TID-STARTUP",
|
.targetId = "TID-STARTUP-P",
|
||||||
.title = "about:blank",
|
.title = "New Private Tab",
|
||||||
.url = "chrome://newtab/",
|
.url = "chrome://newtab/",
|
||||||
.browserContextId = "BID-STARTUP",
|
.browserContextId = "BID-STARTUP",
|
||||||
},
|
},
|
||||||
@@ -382,7 +383,7 @@ const TargetInfo = struct {
|
|||||||
attached: bool = true,
|
attached: bool = true,
|
||||||
type: []const u8 = "page",
|
type: []const u8 = "page",
|
||||||
canAccessOpener: bool = false,
|
canAccessOpener: bool = false,
|
||||||
browserContextId: []const u8,
|
browserContextId: ?[]const u8 = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const testing = @import("testing.zig");
|
const testing = @import("testing.zig");
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ const TestContext = struct {
|
|||||||
|
|
||||||
const BrowserContextOpts = struct {
|
const BrowserContextOpts = struct {
|
||||||
id: ?[]const u8 = null,
|
id: ?[]const u8 = null,
|
||||||
|
target_id: ?[]const u8 = null,
|
||||||
session_id: ?[]const u8 = null,
|
session_id: ?[]const u8 = null,
|
||||||
};
|
};
|
||||||
pub fn loadBrowserContext(self: *TestContext, opts: BrowserContextOpts) !*main.BrowserContext(TestCDP) {
|
pub fn loadBrowserContext(self: *TestContext, opts: BrowserContextOpts) !*main.BrowserContext(TestCDP) {
|
||||||
@@ -163,6 +164,10 @@ const TestContext = struct {
|
|||||||
bc.id = id;
|
bc.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.target_id) |tid| {
|
||||||
|
bc.target_id = tid;
|
||||||
|
}
|
||||||
|
|
||||||
if (opts.session_id) |sid| {
|
if (opts.session_id) |sid| {
|
||||||
bc.session_id = sid;
|
bc.session_id = sid;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user