fix(browser): distinguish WebMCP registration frame owners (#813)
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
@@ -12,7 +12,7 @@ REA can attach to a user-owned Chrome-family browser through the Chrome DevTools
|
|||||||
- `inspect_web_page` / `rea inspect-web-page` captures DOM structure, accessibility nodes, scripts, resources, safe response/DOM metadata, attach-window network and console metadata, WebSocket frame sizes, workers, quota, and optionally selected storage key names, redacted storage-content fingerprints, or script sources.
|
- `inspect_web_page` / `rea inspect-web-page` captures DOM structure, accessibility nodes, scripts, resources, safe response/DOM metadata, attach-window network and console metadata, WebSocket frame sizes, workers, quota, and optionally selected storage key names, redacted storage-content fingerprints, or script sources.
|
||||||
- `analyze_web_bundle` / `rea analyze-web-bundle` parses selected script artifacts without execution and derives chunk edges, route and endpoint candidates, vendor fingerprints, static WebMCP declarations, and optionally source-map/original-source evidence.
|
- `analyze_web_bundle` / `rea analyze-web-bundle` parses selected script artifacts without execution and derives chunk edges, route and endpoint candidates, vendor fingerprints, static WebMCP declarations, and optionally source-map/original-source evidence.
|
||||||
- `observe_web_session` / `rea observe-web-session` arms an observation window of the requested duration for an external user action and records ordered reload, SPA navigation, redirect, failure, lifecycle, and target-termination metadata.
|
- `observe_web_session` / `rea observe-web-session` arms an observation window of the requested duration for an external user action and records ordered reload, SPA navigation, redirect, failure, lifecycle, and target-termination metadata.
|
||||||
- `discover_webmcp_tools` / `rea discover-webmcp-tools` uses the experimental CDP WebMCP domain to return every in-scope registration and its complete structural input-schema summary inline. REA never exposes `WebMCP.invokeTool`; malformed protocol payloads fail explicitly instead of returning incomplete tool metadata.
|
- `discover_webmcp_tools` / `rea discover-webmcp-tools` uses the experimental CDP WebMCP domain to return every in-scope registration and its complete structural input-schema summary inline. Registrations with the same name and URL in distinct observed frames retain separate identities. `tool_key` includes the observed frame ID; it is not a stable identity across navigation or browser sessions. Same-frame registration updates replace that owner only, and removal leaves other owners intact. REA never exposes `WebMCP.invokeTool`; malformed protocol payloads fail explicitly instead of returning incomplete tool metadata.
|
||||||
- `compare_web_captures` / `rea compare-web-captures` compares passive captures or exact-step-aligned browser scenarios. Scenario results commit reproducible literal normalization and expose alignment failures plus artifact-level action, screenshot, DOM, accessibility, URL, history, storage, and event differences. Missing or truncated evidence is never treated as equivalence.
|
- `compare_web_captures` / `rea compare-web-captures` compares passive captures or exact-step-aligned browser scenarios. Scenario results commit reproducible literal normalization and expose alignment failures plus artifact-level action, screenshot, DOM, accessibility, URL, history, storage, and event differences. Missing or truncated evidence is never treated as equivalence.
|
||||||
- `capture_web_screenshot` / `rea capture-web-screenshot` returns a content-addressed visible-viewport PNG.
|
- `capture_web_screenshot` / `rea capture-web-screenshot` returns a content-addressed visible-viewport PNG.
|
||||||
- `compare_web_screenshots` / `rea compare-web-screenshots` performs bounded local PNG pixel comparison without OCR or external services.
|
- `compare_web_screenshots` / `rea compare-web-screenshots` performs bounded local PNG pixel comparison without OCR or external services.
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ const normalizeTool = (
|
|||||||
const description = stringValue(value.description) ?? "";
|
const description = stringValue(value.description) ?? "";
|
||||||
const annotations = recordValue(value.annotations);
|
const annotations = recordValue(value.annotations);
|
||||||
return {
|
return {
|
||||||
tool_key: toolKey(frame.url, name),
|
tool_key: toolKey(frame.url, frameId, name),
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
frame_id: frameId,
|
frame_id: frameId,
|
||||||
@@ -497,8 +497,8 @@ const buildWebMcpResult = (options: WebMcpResultOptions): WebMcpDiscovery => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const toolKey = (frameUrl: string, name: string): string =>
|
const toolKey = (frameUrl: string, frameId: string, name: string): string =>
|
||||||
`webmcp_${createHash("sha256").update(`${frameUrl}\0${name}`).digest("hex")}`;
|
`webmcp_${createHash("sha256").update(`${frameUrl}\0${frameId}\0${name}`).digest("hex")}`;
|
||||||
|
|
||||||
const booleanOrNull = (value: unknown): boolean | null =>
|
const booleanOrNull = (value: unknown): boolean | null =>
|
||||||
typeof value === "boolean" ? value : null;
|
typeof value === "boolean" ? value : null;
|
||||||
|
|||||||
@@ -500,3 +500,51 @@ describeBrowser("CdpBrowserProvider: document script 4", () => {
|
|||||||
expect(result.value.storage.content_fingerprints).toEqual([]);
|
expect(result.value.storage.content_fingerprints).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describeBrowser("CdpBrowserProvider: WebMCP registration owners", () => {
|
||||||
|
it.each(["retain", "remove-second"] as const)(
|
||||||
|
"keeps same-URL frame owners separate: %s",
|
||||||
|
async (mode) => {
|
||||||
|
const browser = await startFakeCdpBrowser({
|
||||||
|
webMcpSameUrlRegistrations: mode,
|
||||||
|
});
|
||||||
|
trackBrowser(browser);
|
||||||
|
const result = await new CdpBrowserProvider().discoverWebMcpTools(
|
||||||
|
discoverWebMcpToolsInputSchema.parse({
|
||||||
|
cdp_endpoint: browser.endpoint,
|
||||||
|
allowed_origins: [browser.allowedOrigin],
|
||||||
|
target_id: "allowed-page",
|
||||||
|
observation_ms: 0,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (!result.ok) throw result.error;
|
||||||
|
const tools = result.value.tools.items;
|
||||||
|
expect(tools).toHaveLength(mode === "retain" ? 2 : 1);
|
||||||
|
expect(result.value.tools.total).toBe(tools.length);
|
||||||
|
expect(tools).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
name: "read_item",
|
||||||
|
frame_id: "webmcp-frame-0",
|
||||||
|
description: "First owner updated",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (mode === "retain") {
|
||||||
|
expect(tools).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
name: "read_item",
|
||||||
|
frame_id: "webmcp-frame-1",
|
||||||
|
description: "Second owner",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(new Set(tools.map((tool) => tool.tool_key)).size).toBe(2);
|
||||||
|
expect(new Set(tools.map((tool) => tool.frame_url)).size).toBe(1);
|
||||||
|
}
|
||||||
|
expect(browser.commands.map(({ method }) => method)).not.toContain(
|
||||||
|
"WebMCP.invokeTool",
|
||||||
|
);
|
||||||
|
expect(browser.commands.map(({ method }) => method)).not.toContain(
|
||||||
|
"Runtime.evaluate",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
+45
@@ -22,6 +22,13 @@ const emitWebMcpEvents = (
|
|||||||
port: number,
|
port: number,
|
||||||
options: FakeOptions,
|
options: FakeOptions,
|
||||||
): void => {
|
): void => {
|
||||||
|
if (
|
||||||
|
command.method === "WebMCP.enable" &&
|
||||||
|
options.webMcpSameUrlRegistrations !== undefined
|
||||||
|
) {
|
||||||
|
emitSameUrlWebMcpRegistrations(socket, command, options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (command.method === "WebMCP.enable" && options.webMcpTools === true) {
|
if (command.method === "WebMCP.enable" && options.webMcpTools === true) {
|
||||||
const inputSchemaProperties =
|
const inputSchemaProperties =
|
||||||
options.webMcpSchemaPropertyCount === undefined
|
options.webMcpSchemaPropertyCount === undefined
|
||||||
@@ -160,6 +167,44 @@ const emitWebMcpEvents = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const emitSameUrlWebMcpRegistrations = (
|
||||||
|
socket: WebSocket,
|
||||||
|
command: FakeCdpCommand,
|
||||||
|
options: FakeOptions,
|
||||||
|
): void => {
|
||||||
|
event(socket, "WebMCP.toolsAdded", command.sessionId, {
|
||||||
|
tools: [
|
||||||
|
{
|
||||||
|
name: "read_item",
|
||||||
|
description: "First owner",
|
||||||
|
frameId: "webmcp-frame-0",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
event(socket, "WebMCP.toolsAdded", command.sessionId, {
|
||||||
|
tools: [
|
||||||
|
{
|
||||||
|
name: "read_item",
|
||||||
|
description: "First owner updated",
|
||||||
|
frameId: "webmcp-frame-0",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
event(socket, "WebMCP.toolsAdded", command.sessionId, {
|
||||||
|
tools: [
|
||||||
|
{
|
||||||
|
name: "read_item",
|
||||||
|
description: "Second owner",
|
||||||
|
frameId: "webmcp-frame-1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (options.webMcpSameUrlRegistrations === "remove-second")
|
||||||
|
event(socket, "WebMCP.toolsRemoved", command.sessionId, {
|
||||||
|
tools: [{ name: "read_item", frameId: "webmcp-frame-1" }],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const emitSessionTimeline = (
|
const emitSessionTimeline = (
|
||||||
socket: WebSocket,
|
socket: WebSocket,
|
||||||
command: FakeCdpCommand,
|
command: FakeCdpCommand,
|
||||||
|
|||||||
+15
-10
@@ -66,7 +66,9 @@ const frameTreeResult = (
|
|||||||
? ":"
|
? ":"
|
||||||
: (options.electronFileUrl ?? options.attachedFrameUrl),
|
: (options.electronFileUrl ?? options.attachedFrameUrl),
|
||||||
options.extraCollections === true,
|
options.extraCollections === true,
|
||||||
options.webMcpFrameCount,
|
options.webMcpSameUrlRegistrations === undefined
|
||||||
|
? options.webMcpFrameCount
|
||||||
|
: "same-url",
|
||||||
);
|
);
|
||||||
|
|
||||||
const resourceTreeResult = (port: number, options: FakeOptions) =>
|
const resourceTreeResult = (port: number, options: FakeOptions) =>
|
||||||
@@ -236,7 +238,7 @@ const frameTree = (
|
|||||||
port: number,
|
port: number,
|
||||||
overrideUrl?: string,
|
overrideUrl?: string,
|
||||||
extraCollections = false,
|
extraCollections = false,
|
||||||
webMcpFrameCount = 0,
|
webMcpFrameCount: number | "same-url" = 0,
|
||||||
): Readonly<Record<string, unknown>> => ({
|
): Readonly<Record<string, unknown>> => ({
|
||||||
frameTree: {
|
frameTree: {
|
||||||
frame: {
|
frame: {
|
||||||
@@ -259,14 +261,17 @@ const frameTree = (
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
...Array.from({ length: webMcpFrameCount }, (_value, index) => ({
|
...Array.from(
|
||||||
frame: {
|
{ length: webMcpFrameCount === "same-url" ? 2 : webMcpFrameCount },
|
||||||
id: `webmcp-frame-${String(index)}`,
|
(_value, index) => ({
|
||||||
parentId: "frame-main",
|
frame: {
|
||||||
loaderId: `loader-webmcp-${String(index)}`,
|
id: `webmcp-frame-${String(index)}`,
|
||||||
url: `http://127.0.0.1:${String(port)}/webmcp-frame/${String(index)}`,
|
parentId: "frame-main",
|
||||||
},
|
loaderId: `loader-webmcp-${String(index)}`,
|
||||||
})),
|
url: `http://127.0.0.1:${String(port)}/webmcp-frame/${webMcpFrameCount === "same-url" ? "shared" : String(index)}`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
{
|
{
|
||||||
frame: {
|
frame: {
|
||||||
id: "frame-private",
|
id: "frame-private",
|
||||||
|
|||||||
+1
@@ -62,6 +62,7 @@ export interface FakeOptions {
|
|||||||
readonly cachedResponseBody?: string;
|
readonly cachedResponseBody?: string;
|
||||||
readonly invalidResponseBodyBase64?: boolean;
|
readonly invalidResponseBodyBase64?: boolean;
|
||||||
readonly webMcpTools?: boolean;
|
readonly webMcpTools?: boolean;
|
||||||
|
readonly webMcpSameUrlRegistrations?: "retain" | "remove-second";
|
||||||
readonly webMcpFrameCount?: number;
|
readonly webMcpFrameCount?: number;
|
||||||
readonly webMcpSchemaPropertyCount?: number;
|
readonly webMcpSchemaPropertyCount?: number;
|
||||||
readonly webMcpChildLeavesScope?: boolean;
|
readonly webMcpChildLeavesScope?: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user