@mearl/browser-core 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browserActionProtocol.d.ts +13 -1
- package/dist/browserActionProtocol.js +7 -1
- package/dist/extensionAgentAccess.d.ts +9 -0
- package/dist/extensionAgentAccess.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/pageWebMcp.d.ts +57 -0
- package/dist/pageWebMcp.js +125 -0
- package/dist/proxyPermissions.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BrowserCapabilityCatalog } from './browserCapabilities.js';
|
|
2
|
+
import type { PageCallToolParams } from './pageWebMcp.js';
|
|
2
3
|
export interface GetCapabilitiesParams {
|
|
3
4
|
/** Include method and setting details for this installed App ID. */
|
|
4
5
|
app?: string;
|
|
@@ -652,6 +653,7 @@ export interface PageSnapshotQuery {
|
|
|
652
653
|
}
|
|
653
654
|
export interface PageSnapshotParams {
|
|
654
655
|
tabId: number;
|
|
656
|
+
includeWebMcp?: 'full';
|
|
655
657
|
depth?: number;
|
|
656
658
|
maxChars?: number;
|
|
657
659
|
maxNodes?: number;
|
|
@@ -904,6 +906,12 @@ export interface BrowserActionMap {
|
|
|
904
906
|
request: PageEvalParams;
|
|
905
907
|
response: unknown;
|
|
906
908
|
};
|
|
909
|
+
page_call_tool: {
|
|
910
|
+
request: PageCallToolParams;
|
|
911
|
+
response: {
|
|
912
|
+
result: unknown;
|
|
913
|
+
};
|
|
914
|
+
};
|
|
907
915
|
page_runtime: {
|
|
908
916
|
request: Record<string, unknown>;
|
|
909
917
|
response: unknown;
|
|
@@ -973,7 +981,7 @@ export type BrowserActionResponse<A extends BrowserAction> = BrowserActionMap[A]
|
|
|
973
981
|
};
|
|
974
982
|
export type BrowserCommandAction = Exclude<BrowserAction, 'browser_select_browser'>;
|
|
975
983
|
export type ExtensionBrowserAction = Exclude<BrowserCommandAction, 'browser_list' | 'browser_launch' | 'browser_close' | 'browser_control' | 'page_download'>;
|
|
976
|
-
export declare const TAB_ID_REQUIRED_ACTIONS: readonly ["tab_checkpoint", "capture_checkpoint", "get_requests", "get_logs", "get_events", "set_mock", "get_mocks", "page_screenshot", "tab_close", "page_click", "page_drag", "page_type", "page_scroll", "page_hover", "page_eval", "page_inspect", "page_snapshot", "page_press", "page_wait", "page_navigate", "page_upload", "page_download", "page_frames", "set_device_emulation", "set_app_profile", "set_timezone", "run_actions"];
|
|
984
|
+
export declare const TAB_ID_REQUIRED_ACTIONS: readonly ["tab_checkpoint", "capture_checkpoint", "get_requests", "get_logs", "get_events", "set_mock", "get_mocks", "page_screenshot", "tab_close", "page_click", "page_drag", "page_type", "page_scroll", "page_hover", "page_eval", "page_call_tool", "page_inspect", "page_snapshot", "page_press", "page_wait", "page_navigate", "page_upload", "page_download", "page_frames", "set_device_emulation", "set_app_profile", "set_timezone", "run_actions"];
|
|
977
985
|
export type TabIdRequiredAction = (typeof TAB_ID_REQUIRED_ACTIONS)[number];
|
|
978
986
|
export declare function actionRequiresTabId(action: unknown): action is TabIdRequiredAction;
|
|
979
987
|
export declare function validateRequiredActionTabId(action: string, data: unknown): void;
|
|
@@ -1009,6 +1017,7 @@ export declare const BROWSER_ACTIONS: {
|
|
|
1009
1017
|
readonly page_scroll: true;
|
|
1010
1018
|
readonly page_hover: true;
|
|
1011
1019
|
readonly page_eval: true;
|
|
1020
|
+
readonly page_call_tool: true;
|
|
1012
1021
|
readonly page_runtime: true;
|
|
1013
1022
|
readonly page_inspect: true;
|
|
1014
1023
|
readonly page_snapshot: true;
|
|
@@ -1054,6 +1063,7 @@ export declare const BROWSER_COMMAND_ACTIONS: {
|
|
|
1054
1063
|
readonly page_scroll: true;
|
|
1055
1064
|
readonly page_hover: true;
|
|
1056
1065
|
readonly page_eval: true;
|
|
1066
|
+
readonly page_call_tool: true;
|
|
1057
1067
|
readonly page_runtime: true;
|
|
1058
1068
|
readonly page_inspect: true;
|
|
1059
1069
|
readonly page_snapshot: true;
|
|
@@ -1094,6 +1104,7 @@ export declare const EXTENSION_BROWSER_ACTIONS: {
|
|
|
1094
1104
|
readonly page_scroll: true;
|
|
1095
1105
|
readonly page_hover: true;
|
|
1096
1106
|
readonly page_eval: true;
|
|
1107
|
+
readonly page_call_tool: true;
|
|
1097
1108
|
readonly page_runtime: true;
|
|
1098
1109
|
readonly page_inspect: true;
|
|
1099
1110
|
readonly page_snapshot: true;
|
|
@@ -1135,6 +1146,7 @@ export declare const BROWSER_CAPABILITY_ACTIONS: {
|
|
|
1135
1146
|
readonly page_scroll: true;
|
|
1136
1147
|
readonly page_hover: true;
|
|
1137
1148
|
readonly page_eval: true;
|
|
1149
|
+
readonly page_call_tool: true;
|
|
1138
1150
|
readonly page_runtime: true;
|
|
1139
1151
|
readonly page_inspect: true;
|
|
1140
1152
|
readonly page_snapshot: true;
|
|
@@ -58,6 +58,7 @@ export const TAB_ID_REQUIRED_ACTIONS = [
|
|
|
58
58
|
'page_scroll',
|
|
59
59
|
'page_hover',
|
|
60
60
|
'page_eval',
|
|
61
|
+
'page_call_tool',
|
|
61
62
|
'page_inspect',
|
|
62
63
|
'page_snapshot',
|
|
63
64
|
'page_press',
|
|
@@ -76,7 +77,9 @@ export function actionRequiresTabId(action) {
|
|
|
76
77
|
return typeof action === 'string' && TAB_ID_REQUIRED_ACTION_SET.has(action);
|
|
77
78
|
}
|
|
78
79
|
export function validateRequiredActionTabId(action, data) {
|
|
79
|
-
if (action === 'get_capabilities' &&
|
|
80
|
+
if (action === 'get_capabilities' &&
|
|
81
|
+
data &&
|
|
82
|
+
typeof data === 'object' &&
|
|
80
83
|
['tabId', 'tabIds', 'openerTabId'].some(key => Object.hasOwn(data, key))) {
|
|
81
84
|
throw new Error('get_capabilities does not accept page targets');
|
|
82
85
|
}
|
|
@@ -140,6 +143,7 @@ export const BROWSER_ACTIONS = {
|
|
|
140
143
|
page_scroll: true,
|
|
141
144
|
page_hover: true,
|
|
142
145
|
page_eval: true,
|
|
146
|
+
page_call_tool: true,
|
|
143
147
|
page_runtime: true,
|
|
144
148
|
page_inspect: true,
|
|
145
149
|
page_snapshot: true,
|
|
@@ -185,6 +189,7 @@ export const BROWSER_COMMAND_ACTIONS = {
|
|
|
185
189
|
page_scroll: true,
|
|
186
190
|
page_hover: true,
|
|
187
191
|
page_eval: true,
|
|
192
|
+
page_call_tool: true,
|
|
188
193
|
page_runtime: true,
|
|
189
194
|
page_inspect: true,
|
|
190
195
|
page_snapshot: true,
|
|
@@ -225,6 +230,7 @@ export const EXTENSION_BROWSER_ACTIONS = {
|
|
|
225
230
|
page_scroll: true,
|
|
226
231
|
page_hover: true,
|
|
227
232
|
page_eval: true,
|
|
233
|
+
page_call_tool: true,
|
|
228
234
|
page_runtime: true,
|
|
229
235
|
page_inspect: true,
|
|
230
236
|
page_snapshot: true,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Native Messaging management handshake; independent of Agent page access. */
|
|
2
|
+
export interface ExtensionAgentPolicy {
|
|
3
|
+
revision: number;
|
|
4
|
+
providerIds: string[];
|
|
5
|
+
available?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Internal file references grant payload trust, not permission to operate pages. */
|
|
8
|
+
export declare function requiresExtensionAgentAccess(action: string, data: any, trustedInternal?: boolean): boolean;
|
|
9
|
+
export declare function isExtensionAgentPolicy(value: unknown): value is ExtensionAgentPolicy;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Internal file references grant payload trust, not permission to operate pages. */
|
|
2
|
+
export function requiresExtensionAgentAccess(action, data, trustedInternal = false) {
|
|
3
|
+
if (!trustedInternal)
|
|
4
|
+
return true;
|
|
5
|
+
if (!action.startsWith('__') && action !== 'get_browser_info')
|
|
6
|
+
return true;
|
|
7
|
+
if (action === '__capture_download' || action === '__export_cookies')
|
|
8
|
+
return true;
|
|
9
|
+
if (action === '__send_request_files')
|
|
10
|
+
return data?.operation !== 'abort';
|
|
11
|
+
if (action === '__browser_enhancement')
|
|
12
|
+
return data?.operation !== 'release';
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
export function isExtensionAgentPolicy(value) {
|
|
16
|
+
const policy = value;
|
|
17
|
+
return (!!policy &&
|
|
18
|
+
Number.isSafeInteger(policy.revision) &&
|
|
19
|
+
policy.revision >= 0 &&
|
|
20
|
+
(policy.available === undefined || typeof policy.available === 'boolean') &&
|
|
21
|
+
Array.isArray(policy.providerIds) &&
|
|
22
|
+
policy.providerIds.length <= 100 &&
|
|
23
|
+
policy.providerIds.every(id => typeof id === 'string' && id.length > 0 && id.length <= 256 && !/[\x00-\x1f]/.test(id)));
|
|
24
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from './backendNodeRefs.js';
|
|
|
30
30
|
export * from './pageEffectRefs.js';
|
|
31
31
|
export * from './pageWait.js';
|
|
32
32
|
export * from './pageNavigation.js';
|
|
33
|
+
export * from './pageWebMcp.js';
|
|
33
34
|
export * from './tabMatching.js';
|
|
34
35
|
export * from './agentChat.js';
|
|
35
36
|
export * from './agentSkills.js';
|
|
@@ -65,3 +66,4 @@ export * from './extensionVersion.js';
|
|
|
65
66
|
export { MEARL_NATIVE_HOST_NAMES, type NativeHostIntegrationMode } from './nativeHostNames.js';
|
|
66
67
|
export * from './dataStructure.js';
|
|
67
68
|
export * from './requestMetadata.js';
|
|
69
|
+
export * from './extensionAgentAccess.js';
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from './backendNodeRefs.js';
|
|
|
29
29
|
export * from './pageEffectRefs.js';
|
|
30
30
|
export * from './pageWait.js';
|
|
31
31
|
export * from './pageNavigation.js';
|
|
32
|
+
export * from './pageWebMcp.js';
|
|
32
33
|
export * from './tabMatching.js';
|
|
33
34
|
export * from './agentChat.js';
|
|
34
35
|
export * from './agentSkills.js';
|
|
@@ -64,3 +65,4 @@ export * from './extensionVersion.js';
|
|
|
64
65
|
export { MEARL_NATIVE_HOST_NAMES } from './nativeHostNames.js';
|
|
65
66
|
export * from './dataStructure.js';
|
|
66
67
|
export * from './requestMetadata.js';
|
|
68
|
+
export * from './extensionAgentAccess.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface PageCallToolParams {
|
|
2
|
+
tabId: number;
|
|
3
|
+
toolRef: string;
|
|
4
|
+
arguments?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface PageWebMcpTool {
|
|
7
|
+
ref?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
inputSchema?: Record<string, unknown>;
|
|
11
|
+
annotations?: Record<string, unknown>;
|
|
12
|
+
origin: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PageWebMcpCatalog {
|
|
15
|
+
url: string;
|
|
16
|
+
status: 'ready' | 'unsupported' | 'discovery-only';
|
|
17
|
+
tools: PageWebMcpTool[];
|
|
18
|
+
truncated: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type PageWebMcpRequest = {
|
|
21
|
+
operation: 'discover';
|
|
22
|
+
} | {
|
|
23
|
+
operation: 'call';
|
|
24
|
+
toolRef: string;
|
|
25
|
+
input: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
export type PageWebMcpResult = {
|
|
28
|
+
catalog: PageWebMcpCatalog;
|
|
29
|
+
} | {
|
|
30
|
+
result: unknown;
|
|
31
|
+
} | {
|
|
32
|
+
error: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function pageWebMcpCallRequest(params: PageCallToolParams): PageWebMcpRequest;
|
|
35
|
+
/** Runs in an isolated world. Native tool objects stay in their original document. */
|
|
36
|
+
export declare function executePageWebMcp(request: PageWebMcpRequest): Promise<PageWebMcpResult>;
|
|
37
|
+
/** Passive discovery never delays the browser action that triggered it. */
|
|
38
|
+
export declare class PageWebMcpObservation {
|
|
39
|
+
private catalog?;
|
|
40
|
+
private pending?;
|
|
41
|
+
private refs;
|
|
42
|
+
protected get hasCatalog(): boolean;
|
|
43
|
+
reset(): void;
|
|
44
|
+
assertRef(toolRef: string): void;
|
|
45
|
+
refresh(probe: () => Promise<PageWebMcpResult>): Promise<void>;
|
|
46
|
+
fields(url: string | undefined, full?: boolean): {
|
|
47
|
+
webmcp: never[];
|
|
48
|
+
webmcpStatus: string;
|
|
49
|
+
} | {
|
|
50
|
+
webmcp?: undefined;
|
|
51
|
+
webmcpStatus?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
webmcpTruncated?: boolean | undefined;
|
|
54
|
+
webmcpStatus?: "unsupported" | "ready" | "discovery-only" | undefined;
|
|
55
|
+
webmcp: PageWebMcpTool[];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export function pageWebMcpCallRequest(params) {
|
|
2
|
+
const { toolRef, arguments: input = {} } = params;
|
|
3
|
+
if (typeof toolRef !== 'string' || !/^webmcp:[0-9a-f-]{36}$/.test(toolRef))
|
|
4
|
+
throw new Error('page_call_tool requires a toolRef from the page WebMCP catalog');
|
|
5
|
+
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
6
|
+
throw new Error('page_call_tool arguments must be a JSON object');
|
|
7
|
+
return { operation: 'call', toolRef, input };
|
|
8
|
+
}
|
|
9
|
+
/** Runs in an isolated world. Native tool objects stay in their original document. */
|
|
10
|
+
export async function executePageWebMcp(request) {
|
|
11
|
+
const world = globalThis;
|
|
12
|
+
const context = document.modelContext;
|
|
13
|
+
if (request.operation === 'call') {
|
|
14
|
+
const tool = world.__mearlWebMcpRefs?.get(request.toolRef);
|
|
15
|
+
if (!context || !tool || tool.window !== window)
|
|
16
|
+
return {
|
|
17
|
+
error: 'WEBMCP_STALE_TOOL: Refresh the page WebMCP catalog before calling this tool',
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const result = await context.executeTool(tool, request.input, {
|
|
21
|
+
signal: AbortSignal.timeout(10_000),
|
|
22
|
+
});
|
|
23
|
+
return { result: result ?? null };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return { error: `WEBMCP_CALL_FAILED: ${String(error)}. Check page state before retrying.` };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const catalog = {
|
|
30
|
+
url: location.href,
|
|
31
|
+
status: 'unsupported',
|
|
32
|
+
tools: [],
|
|
33
|
+
truncated: false,
|
|
34
|
+
};
|
|
35
|
+
if (typeof context?.getTools !== 'function' || typeof context.executeTool !== 'function')
|
|
36
|
+
return { catalog };
|
|
37
|
+
// Older Chrome returns dictionaries and dispatches by name, even with an old tool object.
|
|
38
|
+
const toolPrototype = world.Tool?.prototype;
|
|
39
|
+
catalog.status = toolPrototype ? 'ready' : 'discovery-only';
|
|
40
|
+
const refs = (world.__mearlWebMcpRefs ??= new Map());
|
|
41
|
+
let remaining = 64_000;
|
|
42
|
+
for (const tool of await context.getTools()) {
|
|
43
|
+
if (tool.window !== window)
|
|
44
|
+
continue;
|
|
45
|
+
const { name, description, inputSchema, annotations, origin } = tool;
|
|
46
|
+
const metadata = { name, description, inputSchema, annotations, origin };
|
|
47
|
+
const length = JSON.stringify(metadata).length;
|
|
48
|
+
if (catalog.tools.length >= 64 || length > remaining) {
|
|
49
|
+
catalog.truncated = true;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (toolPrototype && Object.getPrototypeOf(tool) === toolPrototype) {
|
|
53
|
+
metadata.ref = `webmcp:${crypto.randomUUID()}`;
|
|
54
|
+
refs.set(metadata.ref, tool);
|
|
55
|
+
}
|
|
56
|
+
catalog.tools.push(metadata);
|
|
57
|
+
remaining -= length;
|
|
58
|
+
}
|
|
59
|
+
while (refs.size > 256)
|
|
60
|
+
refs.delete(refs.keys().next().value);
|
|
61
|
+
return { catalog };
|
|
62
|
+
}
|
|
63
|
+
/** Passive discovery never delays the browser action that triggered it. */
|
|
64
|
+
export class PageWebMcpObservation {
|
|
65
|
+
catalog;
|
|
66
|
+
pending;
|
|
67
|
+
refs = new Set();
|
|
68
|
+
get hasCatalog() {
|
|
69
|
+
return this.catalog !== undefined;
|
|
70
|
+
}
|
|
71
|
+
reset() {
|
|
72
|
+
this.catalog = undefined;
|
|
73
|
+
this.pending = undefined;
|
|
74
|
+
this.refs.clear();
|
|
75
|
+
}
|
|
76
|
+
assertRef(toolRef) {
|
|
77
|
+
if (!this.refs.has(toolRef))
|
|
78
|
+
throw new Error('WEBMCP_STALE_TOOL: Refresh the page WebMCP catalog before calling this tool');
|
|
79
|
+
}
|
|
80
|
+
refresh(probe) {
|
|
81
|
+
if (this.pending)
|
|
82
|
+
return this.pending;
|
|
83
|
+
let cancelTimeout = () => { };
|
|
84
|
+
const timeout = new Promise(resolve => {
|
|
85
|
+
const timer = setTimeout(resolve, 500);
|
|
86
|
+
cancelTimeout = () => clearTimeout(timer);
|
|
87
|
+
});
|
|
88
|
+
const pending = Promise.race([Promise.resolve().then(probe), timeout])
|
|
89
|
+
.catch(() => undefined)
|
|
90
|
+
.then(result => {
|
|
91
|
+
if (this.pending !== pending)
|
|
92
|
+
return;
|
|
93
|
+
this.catalog =
|
|
94
|
+
result && typeof result === 'object' && 'catalog' in result ? result.catalog : undefined;
|
|
95
|
+
for (const tool of this.catalog?.tools ?? []) {
|
|
96
|
+
if (tool.ref)
|
|
97
|
+
this.refs.add(tool.ref);
|
|
98
|
+
}
|
|
99
|
+
while (this.refs.size > 256)
|
|
100
|
+
this.refs.delete(this.refs.values().next().value);
|
|
101
|
+
})
|
|
102
|
+
.finally(() => {
|
|
103
|
+
cancelTimeout();
|
|
104
|
+
if (this.pending === pending)
|
|
105
|
+
this.pending = undefined;
|
|
106
|
+
});
|
|
107
|
+
this.pending = pending;
|
|
108
|
+
return pending;
|
|
109
|
+
}
|
|
110
|
+
fields(url, full = false) {
|
|
111
|
+
const catalog = this.catalog;
|
|
112
|
+
if (!catalog || (url && catalog.url !== url))
|
|
113
|
+
return full ? { webmcp: [], webmcpStatus: 'unavailable' } : {};
|
|
114
|
+
if (!full && !catalog.tools.length && !catalog.truncated)
|
|
115
|
+
return {};
|
|
116
|
+
const tools = full ? catalog.tools : catalog.tools.slice(0, 8);
|
|
117
|
+
return {
|
|
118
|
+
webmcp: tools,
|
|
119
|
+
...(full || catalog.status !== 'ready' ? { webmcpStatus: catalog.status } : {}),
|
|
120
|
+
...(catalog.truncated || tools.length < catalog.tools.length
|
|
121
|
+
? { webmcpTruncated: true }
|
|
122
|
+
: {}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
package/dist/proxyPermissions.js
CHANGED
|
@@ -6,7 +6,7 @@ export class DomainPermissionError extends Error {
|
|
|
6
6
|
domain;
|
|
7
7
|
code = 'DOMAIN_PERMISSION_REQUIRED';
|
|
8
8
|
requestDispatched = false;
|
|
9
|
-
constructor(action, domain, message = `${action}: Access to "${domain}" is not authorized.
|
|
9
|
+
constructor(action, domain, message = `${action}: Access to "${domain}" is not authorized. Request user authorization, then retry:\nmearl request_permission --payload '${JSON.stringify({ domain }).replace(/'/g, "'\\''")}'`) {
|
|
10
10
|
super(message);
|
|
11
11
|
this.action = action;
|
|
12
12
|
this.domain = domain;
|
package/package.json
CHANGED