server: newSession on disposeBrowserContext

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-07 21:14:55 +02:00
parent 4c225e515d
commit 76a9034668
3 changed files with 29 additions and 4 deletions

View File

@@ -82,7 +82,10 @@ pub const Cmd = struct {
}
// read and execute input
self.msg_buf.read(self.alloc(), input, self, Cmd.do) catch unreachable;
self.msg_buf.read(self.alloc(), input, self, Cmd.do) catch |err| {
std.log.err("do error: {any}", .{err});
return;
};
// continue receving incomming messages asynchronously
self.loop.io.recv(*Cmd, self, cbk, completion, self.socket, self.buf);
@@ -99,7 +102,13 @@ pub const Cmd = struct {
}
fn do(self: *Cmd, cmd: []const u8) anyerror!void {
const res = try cdp.do(self.alloc(), cmd, self);
const res = cdp.do(self.alloc(), cmd, self) catch |err| {
if (err == error.DisposeBrowserContext) {
try self.newSession();
return;
}
return err;
};
// send result
if (!std.mem.eql(u8, res, "")) {
@@ -108,6 +117,13 @@ pub const Cmd = struct {
}
}
fn newSession(self: *Cmd) !void {
std.log.info("new session", .{});
try self.browser.newSession(self.alloc(), self.loop);
const cmd_opaque = @as(*anyopaque, @ptrCast(self));
try self.browser.currentSession().setInspector(cmd_opaque, Cmd.onInspectorResp, Cmd.onInspectorNotif);
}
// Inspector
pub fn sendInspector(self: *Cmd, msg: []const u8) void {