mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-04-04 00:20:32 +00:00
mcp/cdp: fix inactivity timeout
- Fixed CDP inactivity timeout by resetting it when the browser is busy (loading or executing macrotasks). - Removed the placeholder screenshot tool. - Refactored MCP tool schemas to constants to avoid duplication.
This commit is contained in:
@@ -330,6 +330,11 @@ pub const Client = struct {
|
||||
ms_remaining = self.ws.timeout_ms;
|
||||
},
|
||||
.done => {
|
||||
if (self.isBusy()) {
|
||||
last_message = milliTimestamp(.monotonic);
|
||||
ms_remaining = self.ws.timeout_ms;
|
||||
continue;
|
||||
}
|
||||
const now = milliTimestamp(.monotonic);
|
||||
const elapsed = now - last_message;
|
||||
if (elapsed >= ms_remaining) {
|
||||
@@ -343,6 +348,24 @@ pub const Client = struct {
|
||||
}
|
||||
}
|
||||
|
||||
fn isBusy(self: *const Client) bool {
|
||||
if (self.http.active > 0 or self.http.intercepted > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const cdp = switch (self.mode) {
|
||||
.cdp => |*c| c,
|
||||
.http => return false,
|
||||
};
|
||||
|
||||
const session = cdp.browser.session orelse return false;
|
||||
if (session.browser.hasBackgroundTasks() or session.browser.msToNextMacrotask() != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
fn blockingReadStart(ctx: *anyopaque) bool {
|
||||
const self: *Client = @ptrCast(@alignCast(ctx));
|
||||
self.ws.setBlocking(true) catch |err| {
|
||||
|
||||
Reference in New Issue
Block a user