Skip to content

Commit f38a0d2

Browse files
committed
Remove BrowserContext URL
Add BrowserContext.getURL which gets the URL from the session.page.
1 parent b76875b commit f38a0d2

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/cdp/cdp.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ pub fn BrowserContext(comptime CDP_T: type) type {
284284
// we should reject it.
285285
session_id: ?[]const u8,
286286

287-
// State
288-
url: []const u8,
289287
loader_id: []const u8,
290288
security_origin: []const u8,
291289
page_life_cycle_events: bool,
@@ -306,7 +304,6 @@ pub fn BrowserContext(comptime CDP_T: type) type {
306304
.cdp = cdp,
307305
.target_id = null,
308306
.session_id = null,
309-
.url = URL_BASE,
310307
.security_origin = URL_BASE,
311308
.secure_context_type = "Secure", // TODO = enum
312309
.loader_id = LOADER_ID,
@@ -336,6 +333,11 @@ pub fn BrowserContext(comptime CDP_T: type) type {
336333
};
337334
}
338335

336+
pub fn getURL(self: *const Self) ?[]const u8 {
337+
const page = self.session.currentPage() orelse return null;
338+
return page.rawuri;
339+
}
340+
339341
pub fn onInspectorResponse(ctx: *anyopaque, _: u32, msg: []const u8) void {
340342
if (std.log.defaultLogEnabled(.debug)) {
341343
// msg should be {"id":<id>,...

src/cdp/domains/page.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ fn getFrameTree(cmd: anytype) !void {
6161
return cmd.sendResult(.{
6262
.frameTree = .{
6363
.frame = Frame{
64-
.url = bc.url,
6564
.id = target_id,
6665
.loaderId = bc.loader_id,
6766
.securityOrigin = bc.security_origin,
67+
.url = bc.getURL() orelse "about:blank",
6868
.secureContextType = bc.secure_context_type,
6969
},
7070
},
@@ -154,7 +154,6 @@ pub fn navigateToUrl(cmd: anytype, url: []const u8, send_result: bool) !void {
154154

155155
// change state
156156
bc.reset();
157-
bc.url = url;
158157
bc.loader_id = cmd.cdp.loader_id_gen.next();
159158

160159
const LifecycleEvent = struct {
@@ -285,7 +284,7 @@ test "cdp.page: getFrameTree" {
285284
.frame = .{
286285
.id = "TID-3",
287286
.loaderId = bc.loader_id,
288-
.url = bc.url,
287+
.url = "about:blank",
289288
.domainAndRegistry = "",
290289
.securityOrigin = bc.security_origin,
291290
.mimeType = "text/html",

src/cdp/domains/target.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ fn createTarget(cmd: anytype) !void {
132132
_ = try bc.session.createPage(aux_data);
133133

134134
// change CDP state
135-
bc.url = "about:blank";
136135
bc.security_origin = "://";
137136
bc.secure_context_type = "InsecureScheme";
138137
bc.loader_id = LOADER_ID;
@@ -142,11 +141,11 @@ fn createTarget(cmd: anytype) !void {
142141
// has been enabled?
143142
try cmd.sendEvent("Target.targetCreated", .{
144143
.targetInfo = TargetInfo{
145-
.url = bc.url,
144+
.attached = false,
146145
.targetId = target_id,
147146
.title = "about:blank",
148147
.browserContextId = bc.id,
149-
.attached = false,
148+
.url = "about:blank",
150149
},
151150
}, .{});
152151

src/cdp/testing.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const Session = struct {
8585
return error.MockBrowserPageAlreadyExists;
8686
}
8787
self.page = .{
88+
.rawuri = "",
8889
.session = self,
8990
.aux_data = try self.arena.dupe(u8, aux_data orelse ""),
9091
};
@@ -103,6 +104,7 @@ const Session = struct {
103104

104105
const Page = struct {
105106
session: *Session,
107+
rawuri: []const u8,
106108
aux_data: []const u8 = "",
107109
doc: ?*parser.Document = null,
108110

@@ -111,10 +113,9 @@ const Page = struct {
111113
_ = aux_data;
112114
}
113115

116+
const MouseEvent = @import("../browser/browser.zig").Page.MouseEvent;
114117
const ClickResult = @import("../browser/browser.zig").Page.ClickResult;
115-
pub fn click(_: *Page, _: Allocator, x: u32, y: u32) !?ClickResult {
116-
_ = x;
117-
_ = y;
118+
pub fn mouseEvent(_: *Page, _: Allocator, _: MouseEvent) !?ClickResult {
118119
return null;
119120
}
120121
};

0 commit comments

Comments
 (0)