Merge pull request #1768 from lightpanda-io/inspector_cleanup

Call `resetContextGroup` on page removal
This commit is contained in:
Pierre Tachoire
2026-03-10 15:32:47 +01:00
committed by GitHub
3 changed files with 16 additions and 1 deletions

View File

@@ -130,6 +130,12 @@ pub fn contextCreated(
pub fn contextDestroyed(self: *Inspector, context: *const v8.Context) void { pub fn contextDestroyed(self: *Inspector, context: *const v8.Context) void {
v8.v8_inspector__Inspector__ContextDestroyed(self.handle, context); v8.v8_inspector__Inspector__ContextDestroyed(self.handle, context);
if (self.default_context) |*dc| {
if (v8.v8__Global__IsEqual(dc, context)) {
self.default_context = null;
}
}
} }
pub fn resetContextGroup(self: *const Inspector) void { pub fn resetContextGroup(self: *const Inspector) void {

View File

@@ -459,6 +459,12 @@ pub fn BrowserContext(comptime CDP_T: type) type {
} }
self.isolated_worlds.clearRetainingCapacity(); self.isolated_worlds.clearRetainingCapacity();
// do this before closeSession, since we don't want to process any
// new notification (Or maybe, instead of the deinit above, we just
// rely on those notifications to do our normal cleanup?)
self.notification.unregisterAll(self);
// If the session has a page, we need to clear it first. The page // If the session has a page, we need to clear it first. The page
// context is always nested inside of the isolated world context, // context is always nested inside of the isolated world context,
// so we need to shutdown the page one first. // so we need to shutdown the page one first.
@@ -466,7 +472,6 @@ pub fn BrowserContext(comptime CDP_T: type) type {
self.node_registry.deinit(); self.node_registry.deinit();
self.node_search_list.deinit(); self.node_search_list.deinit();
self.notification.unregisterAll(self);
self.notification.deinit(); self.notification.deinit();
if (self.http_proxy_changed) { if (self.http_proxy_changed) {

View File

@@ -292,6 +292,10 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
} }
pub fn pageRemove(bc: anytype) !void { pub fn pageRemove(bc: anytype) !void {
// Clear all remote object mappings to prevent stale objectIds from being used
// after the context is destroy
bc.inspector_session.inspector.resetContextGroup();
// The main page is going to be removed, we need to remove contexts from other worlds first. // The main page is going to be removed, we need to remove contexts from other worlds first.
for (bc.isolated_worlds.items) |isolated_world| { for (bc.isolated_worlds.items) |isolated_world| {
try isolated_world.removeContext(); try isolated_world.removeContext();