Skip to content

Lightpanda: the headless browser designed for AI and automation

session: drop a closed page's session history when the page is destroyed

Pierre Tachoiree893fd0ed148
diff --git a/src/browser/Page.zig b/src/browser/Page.zig
index ff4e4fd18..7a51b0c06 100644
--- a/src/browser/Page.zig
+++ b/src/browser/Page.zig
@@ -311,8 +311,16 @@ pub fn deinit(self: *Page) void {
}
self.closed_frames = .empty;
+ const frame_id = self.frame._frame_id;
self.frame.deinit();
+ // The JS of a closed page can run until now, so its session history must
+ // stay until now too. A root navigation's replacement page reuses the
+ // frame id and keeps the history.
+ if (self.session.livePage(frame_id) == null) {
+ self.session.removeNavigation(frame_id);
+ }
+
{
var svg_point_lists = self._svg_point_lists.valueIterator();
while (svg_point_lists.next()) |list| {
diff --git a/src/browser/Session.zig b/src/browser/Session.zig
index 8b7a3a75f..40cfa615e 100644
--- a/src/browser/Session.zig
+++ b/src/browser/Session.zig
@@ -409,8 +409,6 @@ pub fn closePage(self: *Session, frame_id: u32) void {
self.discardPendingPage(pending);
}
self.tearDownPage(live);
- // Unlike a root navigation, this browsing context is gone for good.
- self.removeNavigation(frame_id);
}
// Creates the session history of `frame`, a new top-level browsing context: