Skip to content

Commit 1412c58

Browse files
Merge pull request #1218 from lightpanda-io/cdp-targetinfo-title
cdp: return document's title on targetinfo
2 parents b18ec4d + 4f236d0 commit 1412c58

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/browser/page.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,10 @@ pub const Page = struct {
12221222
const current_origin = try self.origin(self.call_arena);
12231223
return std.mem.startsWith(u8, url, current_origin);
12241224
}
1225+
1226+
pub fn getTitle(self: *const Page) ![]const u8 {
1227+
return try parser.documentHTMLGetTitle(self.window.document);
1228+
}
12251229
};
12261230

12271231
pub const NavigateReason = enum {

src/cdp/cdp.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ pub fn BrowserContext(comptime CDP_T: type) type {
468468
return if (raw_url.len == 0) null else raw_url;
469469
}
470470

471+
pub fn getTitle(self: *const Self) ?[]const u8 {
472+
const page = self.session.currentPage() orelse return null;
473+
return page.getTitle() catch |err| {
474+
log.err(.cdp, "page title", .{ .err = err });
475+
return null;
476+
};
477+
}
478+
471479
pub fn networkEnable(self: *Self) !void {
472480
try self.cdp.browser.notification.register(.http_request_fail, self, onHttpRequestFail);
473481
try self.cdp.browser.notification.register(.http_request_start, self, onHttpRequestStart);

src/cdp/domains/target.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn createTarget(cmd: anytype) !void {
167167
.targetInfo = TargetInfo{
168168
.attached = false,
169169
.targetId = target_id,
170-
.title = params.url,
170+
.title = "about:blank",
171171
.browserContextId = bc.id,
172172
.url = "about:blank",
173173
},
@@ -271,8 +271,8 @@ fn getTargetInfo(cmd: anytype) !void {
271271
.targetInfo = TargetInfo{
272272
.targetId = target_id,
273273
.type = "page",
274-
.title = "",
275-
.url = "",
274+
.title = bc.getTitle() orelse "about:blank",
275+
.url = bc.getURL() orelse "about:blank",
276276
.attached = true,
277277
.canAccessOpener = false,
278278
},
@@ -283,8 +283,8 @@ fn getTargetInfo(cmd: anytype) !void {
283283
.targetInfo = TargetInfo{
284284
.targetId = "TID-STARTUP-B",
285285
.type = "browser",
286-
.title = "",
287-
.url = "",
286+
.title = "about:blank",
287+
.url = "about:blank",
288288
.attached = true,
289289
.canAccessOpener = false,
290290
},
@@ -630,8 +630,8 @@ test "cdp.target: getTargetInfo" {
630630
try ctx.expectSentResult(.{
631631
.targetInfo = .{
632632
.type = "browser",
633-
.title = "",
634-
.url = "",
633+
.title = "about:blank",
634+
.url = "about:blank",
635635
.attached = true,
636636
.canAccessOpener = false,
637637
},
@@ -664,7 +664,7 @@ test "cdp.target: getTargetInfo" {
664664
.targetId = "TID-A",
665665
.type = "page",
666666
.title = "",
667-
.url = "",
667+
.url = "about:blank",
668668
.attached = true,
669669
.canAccessOpener = false,
670670
},

0 commit comments

Comments
 (0)