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:
Karl Seguin
2026-03-12 10:38:07 +08:00
parent 1522c90294
commit 619d27c773
9 changed files with 147 additions and 37 deletions

View File

@@ -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| {