Fix page re-navigate

It isn't safe/correct to call `navigate` on the same page multiple times. A page
is meant to have 1 navigate call. The caller should either remove the page
and create a new one, or call Session.replacePage.

This commit removes the *Page from the MCP Server and instead interacts with
the session to create or remove+create the page as needed, and lets the Session
own the *Page.

It also adds a bit of defensiveness around parameter parsing, e.g. calling
{"method": "tools/call"} (without an id) now errors instead of crashing.
This commit is contained in:
Karl Seguin
2026-03-07 10:19:37 +08:00
parent 21313adf9c
commit ae4ad713ec
4 changed files with 42 additions and 27 deletions

View File

@@ -17,7 +17,6 @@ http_client: *HttpClient,
notification: *lp.Notification,
browser: lp.Browser,
session: *lp.Session,
page: *lp.Page,
writer: *std.io.Writer,
mutex: std.Thread.Mutex = .{},
@@ -45,12 +44,8 @@ pub fn init(allocator: std.mem.Allocator, app: *App, writer: *std.io.Writer) !*S
.http_client = http_client,
.notification = notification,
.session = undefined,
.page = undefined,
};
self.session = try self.browser.newSession(self.notification);
self.page = try self.session.createPage();
return self;
}