mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-14 23:38:57 +00:00
cdp: return document's title on targetinfo
This commit is contained in:
@@ -1222,6 +1222,10 @@ pub const Page = struct {
|
|||||||
const current_origin = try self.origin(self.call_arena);
|
const current_origin = try self.origin(self.call_arena);
|
||||||
return std.mem.startsWith(u8, url, current_origin);
|
return std.mem.startsWith(u8, url, current_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getTitle(self: *const Page) ![]const u8 {
|
||||||
|
return try parser.documentHTMLGetTitle(self.window.document);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const NavigateReason = enum {
|
pub const NavigateReason = enum {
|
||||||
|
|||||||
@@ -468,6 +468,14 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
|||||||
return if (raw_url.len == 0) null else raw_url;
|
return if (raw_url.len == 0) null else raw_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getTitle(self: *const Self) ?[]const u8 {
|
||||||
|
const page = self.session.currentPage() orelse return null;
|
||||||
|
return page.getTitle() catch |err| {
|
||||||
|
log.err(.cdp, "page title", .{ .err = err });
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn networkEnable(self: *Self) !void {
|
pub fn networkEnable(self: *Self) !void {
|
||||||
try self.cdp.browser.notification.register(.http_request_fail, self, onHttpRequestFail);
|
try self.cdp.browser.notification.register(.http_request_fail, self, onHttpRequestFail);
|
||||||
try self.cdp.browser.notification.register(.http_request_start, self, onHttpRequestStart);
|
try self.cdp.browser.notification.register(.http_request_start, self, onHttpRequestStart);
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ fn createTarget(cmd: anytype) !void {
|
|||||||
.targetInfo = TargetInfo{
|
.targetInfo = TargetInfo{
|
||||||
.attached = false,
|
.attached = false,
|
||||||
.targetId = target_id,
|
.targetId = target_id,
|
||||||
.title = params.url,
|
.title = "about:blank",
|
||||||
.browserContextId = bc.id,
|
.browserContextId = bc.id,
|
||||||
.url = "about:blank",
|
.url = "about:blank",
|
||||||
},
|
},
|
||||||
@@ -271,8 +271,8 @@ fn getTargetInfo(cmd: anytype) !void {
|
|||||||
.targetInfo = TargetInfo{
|
.targetInfo = TargetInfo{
|
||||||
.targetId = target_id,
|
.targetId = target_id,
|
||||||
.type = "page",
|
.type = "page",
|
||||||
.title = "",
|
.title = bc.getTitle() orelse "about:blank",
|
||||||
.url = "",
|
.url = bc.getURL() orelse "about:blank",
|
||||||
.attached = true,
|
.attached = true,
|
||||||
.canAccessOpener = false,
|
.canAccessOpener = false,
|
||||||
},
|
},
|
||||||
@@ -283,8 +283,8 @@ fn getTargetInfo(cmd: anytype) !void {
|
|||||||
.targetInfo = TargetInfo{
|
.targetInfo = TargetInfo{
|
||||||
.targetId = "TID-STARTUP-B",
|
.targetId = "TID-STARTUP-B",
|
||||||
.type = "browser",
|
.type = "browser",
|
||||||
.title = "",
|
.title = "about:blank",
|
||||||
.url = "",
|
.url = "about:blank",
|
||||||
.attached = true,
|
.attached = true,
|
||||||
.canAccessOpener = false,
|
.canAccessOpener = false,
|
||||||
},
|
},
|
||||||
@@ -630,8 +630,8 @@ test "cdp.target: getTargetInfo" {
|
|||||||
try ctx.expectSentResult(.{
|
try ctx.expectSentResult(.{
|
||||||
.targetInfo = .{
|
.targetInfo = .{
|
||||||
.type = "browser",
|
.type = "browser",
|
||||||
.title = "",
|
.title = "about:blank",
|
||||||
.url = "",
|
.url = "about:blank",
|
||||||
.attached = true,
|
.attached = true,
|
||||||
.canAccessOpener = false,
|
.canAccessOpener = false,
|
||||||
},
|
},
|
||||||
@@ -664,7 +664,7 @@ test "cdp.target: getTargetInfo" {
|
|||||||
.targetId = "TID-A",
|
.targetId = "TID-A",
|
||||||
.type = "page",
|
.type = "page",
|
||||||
.title = "",
|
.title = "",
|
||||||
.url = "",
|
.url = "about:blank",
|
||||||
.attached = true,
|
.attached = true,
|
||||||
.canAccessOpener = false,
|
.canAccessOpener = false,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user