mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Remove BrowserContext URL
Add BrowserContext.getURL which gets the URL from the session.page.
This commit is contained in:
@@ -284,8 +284,6 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
// we should reject it.
|
||||
session_id: ?[]const u8,
|
||||
|
||||
// State
|
||||
url: []const u8,
|
||||
loader_id: []const u8,
|
||||
security_origin: []const u8,
|
||||
page_life_cycle_events: bool,
|
||||
@@ -306,7 +304,6 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
.cdp = cdp,
|
||||
.target_id = null,
|
||||
.session_id = null,
|
||||
.url = URL_BASE,
|
||||
.security_origin = URL_BASE,
|
||||
.secure_context_type = "Secure", // TODO = enum
|
||||
.loader_id = LOADER_ID,
|
||||
@@ -336,6 +333,11 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn getURL(self: *const Self) ?[]const u8 {
|
||||
const page = self.session.currentPage() orelse return null;
|
||||
return page.rawuri;
|
||||
}
|
||||
|
||||
pub fn onInspectorResponse(ctx: *anyopaque, _: u32, msg: []const u8) void {
|
||||
if (std.log.defaultLogEnabled(.debug)) {
|
||||
// msg should be {"id":<id>,...
|
||||
|
||||
@@ -61,10 +61,10 @@ fn getFrameTree(cmd: anytype) !void {
|
||||
return cmd.sendResult(.{
|
||||
.frameTree = .{
|
||||
.frame = Frame{
|
||||
.url = bc.url,
|
||||
.id = target_id,
|
||||
.loaderId = bc.loader_id,
|
||||
.securityOrigin = bc.security_origin,
|
||||
.url = bc.getURL() orelse "about:blank",
|
||||
.secureContextType = bc.secure_context_type,
|
||||
},
|
||||
},
|
||||
@@ -154,7 +154,6 @@ pub fn navigateToUrl(cmd: anytype, url: []const u8, send_result: bool) !void {
|
||||
|
||||
// change state
|
||||
bc.reset();
|
||||
bc.url = url;
|
||||
bc.loader_id = cmd.cdp.loader_id_gen.next();
|
||||
|
||||
const LifecycleEvent = struct {
|
||||
@@ -285,7 +284,7 @@ test "cdp.page: getFrameTree" {
|
||||
.frame = .{
|
||||
.id = "TID-3",
|
||||
.loaderId = bc.loader_id,
|
||||
.url = bc.url,
|
||||
.url = "about:blank",
|
||||
.domainAndRegistry = "",
|
||||
.securityOrigin = bc.security_origin,
|
||||
.mimeType = "text/html",
|
||||
|
||||
@@ -132,7 +132,6 @@ fn createTarget(cmd: anytype) !void {
|
||||
_ = try bc.session.createPage(aux_data);
|
||||
|
||||
// change CDP state
|
||||
bc.url = "about:blank";
|
||||
bc.security_origin = "://";
|
||||
bc.secure_context_type = "InsecureScheme";
|
||||
bc.loader_id = LOADER_ID;
|
||||
@@ -142,11 +141,11 @@ fn createTarget(cmd: anytype) !void {
|
||||
// has been enabled?
|
||||
try cmd.sendEvent("Target.targetCreated", .{
|
||||
.targetInfo = TargetInfo{
|
||||
.url = bc.url,
|
||||
.attached = false,
|
||||
.targetId = target_id,
|
||||
.title = "about:blank",
|
||||
.browserContextId = bc.id,
|
||||
.attached = false,
|
||||
.url = "about:blank",
|
||||
},
|
||||
}, .{});
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@ const Session = struct {
|
||||
return error.MockBrowserPageAlreadyExists;
|
||||
}
|
||||
self.page = .{
|
||||
.rawuri = "",
|
||||
.session = self,
|
||||
.aux_data = try self.arena.dupe(u8, aux_data orelse ""),
|
||||
};
|
||||
@@ -103,6 +104,7 @@ const Session = struct {
|
||||
|
||||
const Page = struct {
|
||||
session: *Session,
|
||||
rawuri: []const u8,
|
||||
aux_data: []const u8 = "",
|
||||
doc: ?*parser.Document = null,
|
||||
|
||||
@@ -111,10 +113,9 @@ const Page = struct {
|
||||
_ = aux_data;
|
||||
}
|
||||
|
||||
const MouseEvent = @import("../browser/browser.zig").Page.MouseEvent;
|
||||
const ClickResult = @import("../browser/browser.zig").Page.ClickResult;
|
||||
pub fn click(_: *Page, _: Allocator, x: u32, y: u32) !?ClickResult {
|
||||
_ = x;
|
||||
_ = y;
|
||||
pub fn mouseEvent(_: *Page, _: Allocator, _: MouseEvent) !?ClickResult {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user