mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 12:44:43 +00:00
Add cleanup to Range
In https://github.com/lightpanda-io/browser/pull/1774 we started to track Ranges in the page in order to correctly make them "live". But, without correct lifetime, they would continue to be "live" even if out of scope in JS. This commit adds finalizers to Range via reference counting similar to Events. It _is_ possible for a Range to outlive its page, so we can't just remove the range from the Page's _live_range list - the page might not be valid. This commit gives every page an unique id and the ability to try and get the page by id from the session. By capturing the page_id at creation-time, a Range can defensively remove itself from the page's list. If the page is already gone, then there's no need to do anything.
This commit is contained in:
@@ -53,8 +53,8 @@ fn getFullAXTree(cmd: anytype) !void {
|
||||
const frame_id = params.frameId orelse {
|
||||
break :blk session.currentPage() orelse return error.PageNotLoaded;
|
||||
};
|
||||
const page_id = try id.toPageId(.frame_id, frame_id);
|
||||
break :blk session.findPage(page_id) orelse {
|
||||
const page_frame_id = try id.toPageId(.frame_id, frame_id);
|
||||
break :blk session.findPageByFrameId(page_frame_id) orelse {
|
||||
return cmd.sendError(-32000, "Frame with the given id does not belong to the target.", .{});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -502,9 +502,9 @@ fn getFrameOwner(cmd: anytype) !void {
|
||||
})) orelse return error.InvalidParams;
|
||||
|
||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||
const page_id = try id.toPageId(.frame_id, params.frameId);
|
||||
const page_frame_id = try id.toPageId(.frame_id, params.frameId);
|
||||
|
||||
const page = bc.session.findPage(page_id) orelse {
|
||||
const page = bc.session.findPageByFrameId(page_frame_id) orelse {
|
||||
return cmd.sendError(-32000, "Frame with the given id does not belong to the target.", .{});
|
||||
};
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ pub fn httpRequestStart(bc: anytype, msg: *const Notification.RequestStart) !voi
|
||||
const transfer = msg.transfer;
|
||||
const req = &transfer.req;
|
||||
const frame_id = req.frame_id;
|
||||
const page = bc.session.findPage(frame_id) orelse return;
|
||||
const page = bc.session.findPageByFrameId(frame_id) orelse return;
|
||||
|
||||
// Modify request with extra CDP headers
|
||||
for (bc.extra_headers.items) |extra| {
|
||||
|
||||
Reference in New Issue
Block a user