Skip to content

Commit e97c995

Browse files
committed
cdp: add page.Close
1 parent 68e9d3b commit e97c995

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/cdp/domains/page.zig

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn processMessage(cmd: anytype) !void {
3333
createIsolatedWorld,
3434
navigate,
3535
stopLoading,
36+
close,
3637
}, cmd.input.action) orelse return error.UnknownMethod;
3738

3839
switch (action) {
@@ -43,6 +44,7 @@ pub fn processMessage(cmd: anytype) !void {
4344
.createIsolatedWorld => return createIsolatedWorld(cmd),
4445
.navigate => return navigate(cmd),
4546
.stopLoading => return cmd.sendResult(null, .{}),
47+
.close => return close(cmd),
4648
}
4749
}
4850

@@ -130,6 +132,43 @@ fn addScriptToEvaluateOnNewDocument(cmd: anytype) !void {
130132
}, .{});
131133
}
132134

135+
fn close(cmd: anytype) !void {
136+
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
137+
138+
const target_id = bc.target_id orelse return error.TargetNotLoaded;
139+
140+
// can't be null if we have a target_id
141+
std.debug.assert(bc.session.page != null);
142+
143+
try cmd.sendResult(.{}, .{});
144+
145+
// Following code is similar to target.closeTarget
146+
//
147+
// could be null, created but never attached
148+
if (bc.session_id) |session_id| {
149+
// Inspector.detached event
150+
try cmd.sendEvent("Inspector.detached", .{
151+
.reason = "Render process gone.",
152+
}, .{ .session_id = session_id });
153+
154+
// detachedFromTarget event
155+
try cmd.sendEvent("Target.detachedFromTarget", .{
156+
.targetId = target_id,
157+
.sessionId = session_id,
158+
.reason = "Render process gone.",
159+
}, .{});
160+
161+
bc.session_id = null;
162+
}
163+
164+
bc.session.removePage();
165+
for (bc.isolated_worlds.items) |*world| {
166+
world.deinit();
167+
}
168+
bc.isolated_worlds.clearRetainingCapacity();
169+
bc.target_id = null;
170+
}
171+
133172
fn createIsolatedWorld(cmd: anytype) !void {
134173
const params = (try cmd.params(struct {
135174
frameId: []const u8,

0 commit comments

Comments
 (0)