@jackwener/browsermcp 0.0.34-embedded.3 → 0.0.35-embedded.0
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/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/docs/api-reference.md +10 -4
- package/dist/docs/errors.md +26 -0
- package/dist/docs/js-tool.md +10 -2
- package/dist/docs/tab-lifecycle.md +1 -1
- package/dist/src/api/api.js +2 -1
- package/dist/src/api/api.js.map +1 -1
- package/dist/src/api/browser.d.ts +6 -4
- package/dist/src/api/browser.js +7 -1
- package/dist/src/api/browser.js.map +1 -1
- package/dist/src/api/tab.d.ts +2 -5
- package/dist/src/api/tab.js +9 -6
- package/dist/src/api/tab.js.map +1 -1
- package/dist/src/backends/extension-page.js +8 -1
- package/dist/src/backends/extension-page.js.map +1 -1
- package/dist/src/backends/managed-page.d.ts +3 -15
- package/dist/src/electron/backend.js +6 -2
- package/dist/src/electron/backend.js.map +1 -1
- package/dist/src/electron/driver.d.ts +1 -0
- package/dist/src/electron/driver.js +10 -7
- package/dist/src/electron/driver.js.map +1 -1
- package/dist/src/mcp/js-session.d.ts +1 -0
- package/dist/src/mcp/js-session.js +29 -18
- package/dist/src/mcp/js-session.js.map +1 -1
- package/dist/src/mcp/js-worker.mjs +46 -15
- package/dist/src/protocol.d.ts +3 -2
- package/dist/src/protocol.js +1 -1
- package/dist/src/protocol.js.map +1 -1
- package/dist/src/shared/api-contract.d.ts +86 -0
- package/dist/src/shared/api-contract.js +117 -0
- package/dist/src/shared/api-contract.js.map +1 -0
- package/docs/api-reference.md +10 -4
- package/docs/errors.md +26 -0
- package/docs/js-tool.md +10 -2
- package/docs/tab-lifecycle.md +1 -1
- package/extension/dist/background.js +20043 -274
- package/package.json +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Executable contracts shared by the public API, backend discovery and documentation. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/** Internal RPC function source; user data objects cannot impersonate this marker. */
|
|
4
|
+
export declare class PageFunction {
|
|
5
|
+
readonly source: string;
|
|
6
|
+
constructor(source: string);
|
|
7
|
+
}
|
|
8
|
+
export declare function parseInput<T>(method: string, schema: z.ZodType<T>, input: unknown): T;
|
|
9
|
+
export declare function checkArity(method: string, count: number, min: number, max: number): void;
|
|
10
|
+
export declare const evaluateOptions: z.ZodObject<{
|
|
11
|
+
arg: z.ZodOptional<z.ZodUnknown>;
|
|
12
|
+
frame: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>>;
|
|
13
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
export type EvaluateOptions = z.infer<typeof evaluateOptions>;
|
|
16
|
+
/** Reject values that JSON would silently drop or alter. Undefined is only allowed as the root argument. */
|
|
17
|
+
export declare function pageArgument(value: unknown): string;
|
|
18
|
+
export declare const discoveryOptions: z.ZodObject<{
|
|
19
|
+
query: z.ZodOptional<z.ZodString>;
|
|
20
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export type TabDiscoveryOptions = z.infer<typeof discoveryOptions>;
|
|
24
|
+
export declare const userTabInfo: z.ZodObject<{
|
|
25
|
+
tabId: z.ZodNumber;
|
|
26
|
+
title: z.ZodOptional<z.ZodString>;
|
|
27
|
+
url: z.ZodOptional<z.ZodString>;
|
|
28
|
+
windowId: z.ZodNumber;
|
|
29
|
+
active: z.ZodBoolean;
|
|
30
|
+
groupId: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
lastAccessed: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
lifecycle: z.ZodOptional<z.ZodEnum<{
|
|
33
|
+
ready: "ready";
|
|
34
|
+
dormant: "dormant";
|
|
35
|
+
loading: "loading";
|
|
36
|
+
}>>;
|
|
37
|
+
availability: z.ZodOptional<z.ZodEnum<{
|
|
38
|
+
ready: "ready";
|
|
39
|
+
load_required: "load_required";
|
|
40
|
+
host_attachment_required: "host_attachment_required";
|
|
41
|
+
}>>;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
export type UserTabInfo = z.infer<typeof userTabInfo>;
|
|
44
|
+
export declare const discoveryResult: z.ZodObject<{
|
|
45
|
+
scope: z.ZodLiteral<"unclaimed">;
|
|
46
|
+
query: z.ZodString;
|
|
47
|
+
matching: z.ZodLiteral<"case-insensitive-substring">;
|
|
48
|
+
totalVisible: z.ZodNumber;
|
|
49
|
+
totalInScope: z.ZodNumber;
|
|
50
|
+
excluded: z.ZodObject<{
|
|
51
|
+
owned: z.ZodNumber;
|
|
52
|
+
unsupported: z.ZodNumber;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
matched: z.ZodNumber;
|
|
55
|
+
offset: z.ZodNumber;
|
|
56
|
+
limit: z.ZodNumber;
|
|
57
|
+
hasMore: z.ZodBoolean;
|
|
58
|
+
nextOffset: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
items: z.ZodArray<z.ZodObject<{
|
|
60
|
+
tabId: z.ZodNumber;
|
|
61
|
+
title: z.ZodOptional<z.ZodString>;
|
|
62
|
+
url: z.ZodOptional<z.ZodString>;
|
|
63
|
+
windowId: z.ZodNumber;
|
|
64
|
+
active: z.ZodBoolean;
|
|
65
|
+
groupId: z.ZodOptional<z.ZodNumber>;
|
|
66
|
+
lastAccessed: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
lifecycle: z.ZodOptional<z.ZodEnum<{
|
|
68
|
+
ready: "ready";
|
|
69
|
+
dormant: "dormant";
|
|
70
|
+
loading: "loading";
|
|
71
|
+
}>>;
|
|
72
|
+
availability: z.ZodOptional<z.ZodEnum<{
|
|
73
|
+
ready: "ready";
|
|
74
|
+
load_required: "load_required";
|
|
75
|
+
host_attachment_required: "host_attachment_required";
|
|
76
|
+
}>>;
|
|
77
|
+
}, z.core.$strict>>;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
export type TabDiscoveryResult = z.infer<typeof discoveryResult>;
|
|
80
|
+
export type TabInventoryEntry = {
|
|
81
|
+
tab: UserTabInfo;
|
|
82
|
+
owned: boolean;
|
|
83
|
+
supported: boolean;
|
|
84
|
+
};
|
|
85
|
+
/** One snapshot, then scope → literal query → recency order → pagination. Never loads or claims a tab. */
|
|
86
|
+
export declare function discoverTabs(inventory: TabInventoryEntry[], input?: TabDiscoveryOptions): TabDiscoveryResult;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Executable contracts shared by the public API, backend discovery and documentation. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ActionError } from '../api/errors.js';
|
|
4
|
+
/** Internal RPC function source; user data objects cannot impersonate this marker. */
|
|
5
|
+
export class PageFunction {
|
|
6
|
+
source;
|
|
7
|
+
constructor(source) {
|
|
8
|
+
this.source = source;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function parseInput(method, schema, input) {
|
|
12
|
+
const result = schema.safeParse(input);
|
|
13
|
+
if (!result.success)
|
|
14
|
+
throw new ActionError('invalid_args', `${method}: ${result.error.issues.map(i => `${i.path.join('.') || 'options'}: ${i.message}`).join('; ')}`, `Read docs_get api-reference for ${method}. Unknown fields are rejected.`, { method, dispatched: false, issues: result.error.issues.map(i => ({ path: i.path, message: i.message })) });
|
|
15
|
+
return result.data;
|
|
16
|
+
}
|
|
17
|
+
export function checkArity(method, count, min, max) {
|
|
18
|
+
if (count < min || count > max)
|
|
19
|
+
throw new ActionError('invalid_args', `${method} expects ${min}–${max} arguments; received ${count}.`, undefined, { method, dispatched: false });
|
|
20
|
+
}
|
|
21
|
+
const frameStep = z.union([z.string().min(1), z.number().int().nonnegative()]);
|
|
22
|
+
export const evaluateOptions = z.strictObject({
|
|
23
|
+
arg: z.unknown().optional(),
|
|
24
|
+
frame: z.union([frameStep, z.array(frameStep).min(1)]).optional(),
|
|
25
|
+
timeoutMs: z.number().int().min(1).max(300_000).optional(),
|
|
26
|
+
});
|
|
27
|
+
/** Reject values that JSON would silently drop or alter. Undefined is only allowed as the root argument. */
|
|
28
|
+
export function pageArgument(value) {
|
|
29
|
+
const seen = new WeakSet();
|
|
30
|
+
function visit(v, path) {
|
|
31
|
+
const fail = () => {
|
|
32
|
+
throw new ActionError('invalid_args', `Tab.evaluate: ${path} must be plain JSON data (finite numbers, strings, booleans, null, arrays or objects).`, 'Convert special values explicitly before calling evaluate.', { method: 'Tab.evaluate', path, dispatched: false });
|
|
33
|
+
};
|
|
34
|
+
if (v === null || typeof v === 'string' || typeof v === 'boolean')
|
|
35
|
+
return;
|
|
36
|
+
if (typeof v === 'number') {
|
|
37
|
+
if (!Number.isFinite(v) || Object.is(v, -0))
|
|
38
|
+
fail();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (typeof v !== 'object' || !v)
|
|
42
|
+
return fail();
|
|
43
|
+
if (seen.has(v))
|
|
44
|
+
return fail();
|
|
45
|
+
const proto = Object.getPrototypeOf(v);
|
|
46
|
+
if (!Array.isArray(v) && proto !== Object.prototype && proto !== null)
|
|
47
|
+
return fail();
|
|
48
|
+
seen.add(v);
|
|
49
|
+
const keys = Reflect.ownKeys(v);
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
if (Array.isArray(v) && key === 'length')
|
|
52
|
+
continue;
|
|
53
|
+
if (typeof key !== 'string')
|
|
54
|
+
return fail();
|
|
55
|
+
const descriptor = Object.getOwnPropertyDescriptor(v, key);
|
|
56
|
+
if (!descriptor.enumerable || !('value' in descriptor))
|
|
57
|
+
return fail();
|
|
58
|
+
if (Array.isArray(v) && !/^(0|[1-9]\d*)$/.test(key))
|
|
59
|
+
return fail();
|
|
60
|
+
visit(descriptor.value, `${path}.${key}`);
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(v) && keys.length !== v.length + 1)
|
|
63
|
+
return fail();
|
|
64
|
+
seen.delete(v);
|
|
65
|
+
}
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
return 'undefined';
|
|
68
|
+
visit(value, 'arg');
|
|
69
|
+
return `JSON.parse(${JSON.stringify(JSON.stringify(value))})`;
|
|
70
|
+
}
|
|
71
|
+
export const discoveryOptions = z.strictObject({
|
|
72
|
+
query: z.string().optional(),
|
|
73
|
+
limit: z.number().int().min(1).max(100).optional(),
|
|
74
|
+
offset: z.number().int().nonnegative().optional(),
|
|
75
|
+
});
|
|
76
|
+
export const userTabInfo = z.strictObject({
|
|
77
|
+
tabId: z.number().int().positive(), title: z.string().optional(), url: z.string().optional(),
|
|
78
|
+
windowId: z.number().int(), active: z.boolean(), groupId: z.number().int().optional(),
|
|
79
|
+
lastAccessed: z.number().finite().optional(),
|
|
80
|
+
lifecycle: z.enum(['dormant', 'loading', 'ready']).optional(),
|
|
81
|
+
availability: z.enum(['ready', 'load_required', 'host_attachment_required']).optional(),
|
|
82
|
+
});
|
|
83
|
+
export const discoveryResult = z.strictObject({
|
|
84
|
+
scope: z.literal('unclaimed'), query: z.string(), matching: z.literal('case-insensitive-substring'),
|
|
85
|
+
totalVisible: z.number().int().nonnegative(), totalInScope: z.number().int().nonnegative(),
|
|
86
|
+
excluded: z.strictObject({ owned: z.number().int().nonnegative(), unsupported: z.number().int().nonnegative() }),
|
|
87
|
+
matched: z.number().int().nonnegative(), offset: z.number().int().nonnegative(), limit: z.number().int().min(1).max(100),
|
|
88
|
+
hasMore: z.boolean(), nextOffset: z.number().int().nonnegative().optional(), items: z.array(userTabInfo),
|
|
89
|
+
}).superRefine((r, ctx) => {
|
|
90
|
+
const count = Math.min(r.limit, Math.max(0, r.matched - r.offset));
|
|
91
|
+
const more = r.offset + count < r.matched;
|
|
92
|
+
if (r.totalVisible !== r.totalInScope + r.excluded.owned + r.excluded.unsupported || r.matched > r.totalInScope || r.items.length !== count || r.hasMore !== more || r.nextOffset !== (more ? r.offset + count : undefined))
|
|
93
|
+
ctx.addIssue({ code: 'custom', message: 'Inconsistent discovery counts or pagination' });
|
|
94
|
+
});
|
|
95
|
+
/** One snapshot, then scope → literal query → recency order → pagination. Never loads or claims a tab. */
|
|
96
|
+
export function discoverTabs(inventory, input = {}) {
|
|
97
|
+
const options = parseInput('Browser.user.openTabs', discoveryOptions, input);
|
|
98
|
+
const query = (options.query ?? '').trim().toLowerCase();
|
|
99
|
+
const limit = options.limit ?? 20, offset = options.offset ?? 0;
|
|
100
|
+
const excluded = { owned: 0, unsupported: 0 };
|
|
101
|
+
const scope = inventory.filter(entry => {
|
|
102
|
+
if (!entry.supported) {
|
|
103
|
+
excluded.unsupported++;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (entry.owned) {
|
|
107
|
+
excluded.owned++;
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}).map(entry => entry.tab);
|
|
112
|
+
const matches = scope.filter(tab => !query || [tab.url, tab.title].some(value => value?.toLowerCase().includes(query)))
|
|
113
|
+
.sort((a, b) => (b.lastAccessed ?? 0) - (a.lastAccessed ?? 0) || a.tabId - b.tabId);
|
|
114
|
+
const items = matches.slice(offset, offset + limit), hasMore = offset + items.length < matches.length;
|
|
115
|
+
return { scope: 'unclaimed', query, matching: 'case-insensitive-substring', totalVisible: inventory.length, totalInScope: scope.length, excluded, matched: matches.length, offset, limit, hasMore, ...(hasMore ? { nextOffset: offset + items.length } : {}), items };
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=api-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-contract.js","sourceRoot":"","sources":["../../../src/shared/api-contract.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,sFAAsF;AACtF,MAAM,OAAO,YAAY;IAAwB;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,YAAY,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AACxQ,CAAC"}
|
package/docs/api-reference.md
CHANGED
|
@@ -40,7 +40,7 @@ class Browser {
|
|
|
40
40
|
finalize(opts?: { keep?: Array<{ tab: string | Tab; status: "handoff" | "deliverable"; }>; }): Promise<{ closed: Array<string>; kept: Array<string>; failed: Array<{ page: string; reason: string; }>; }>;
|
|
41
41
|
};
|
|
42
42
|
user: {
|
|
43
|
-
openTabs(options?: { query?: string; limit?: number; }): Promise<Array<
|
|
43
|
+
openTabs(...args: [options?: { query?: string | undefined; limit?: number | undefined; offset?: number | undefined; }]): Promise<{ scope: "unclaimed"; query: string; matching: "case-insensitive-substring"; totalVisible: number; totalInScope: number; excluded: { owned: number; unsupported: number; }; matched: number; offset: number; limit: number; hasMore: boolean; items: Array<{ tabId: number; windowId: number; active: boolean; title?: string | undefined; url?: string | undefined; groupId?: number | undefined; lastAccessed?: number | undefined; lifecycle?: "dormant" | "loading" | "ready" | undefined; availability?: "ready" | "load_required" | "host_attachment_required" | undefined; }>; nextOffset?: number | undefined; }>; // Unclaimed supported tabs in the visible scope. Query is trimmed, case-insensitive literal substring of URL OR title (no token splitting). Inspect items, matched, totalInScope, excluded and hasMore; continue with nextOffset. Each call takes a fresh snapshot.
|
|
44
44
|
claimTab(tab: { tabId?: number; active?: boolean; title?: string; url?: string; expectedUrl?: string; expectedTitle?: string; }): Promise<Tab>; // Claim by foreground, id, or unique url/title lookup; expected fields verify the tab's current identity.
|
|
45
45
|
closeTabs(tabIds: Array<number>): Promise<CloseUserTabsResult>; // Close user tabs by Chrome id without claiming or loading their pages.
|
|
46
46
|
};
|
|
@@ -77,7 +77,7 @@ class Tab {
|
|
|
77
77
|
call(name: string, input?: Record<string, unknown>, options?: { frame?: FrameStep | Array<FrameStep>; }): Promise<unknown>;
|
|
78
78
|
};
|
|
79
79
|
expect(what: Expectation, opts?: { timeoutMs?: number; }): Promise<CheckResult>; // Assert what the page must show now (polled up to timeoutMs).
|
|
80
|
-
evaluate(script: string | ((arg: any) => any), opts?: { arg?: unknown; frame?:
|
|
80
|
+
evaluate(script: string | ((arg: any) => any), opts?: { arg?: unknown; frame?: string | number | Array<string | number> | undefined; timeoutMs?: number | undefined; }): Promise<unknown>; // Main World page code; functions receive only opts.arg, never host closures. Dispatched scripts are never replayed.
|
|
81
81
|
cdp: { // Native CDP on this Tab's shared debugger attachment. Parameters are not rewritten.
|
|
82
82
|
send(method: string, params?: Record<string, unknown>, target?: { frameId: string; }): Promise<unknown>;
|
|
83
83
|
watch(event: string, options?: StreamOptions): Promise<EventStream>;
|
|
@@ -167,8 +167,6 @@ interface DialogInfo { type: 'alert' | 'confirm' | 'prompt' | 'beforeunload'; me
|
|
|
167
167
|
|
|
168
168
|
interface ConsoleEntry { seq: number; level: 'debug' | 'info' | 'log' | 'warn' | 'error'; message: string; timestamp: string; url?: string; line?: number }
|
|
169
169
|
|
|
170
|
-
interface UserTabInfo { tabId: number; title?: string; url?: string; windowId: number; active: boolean; groupId?: number; lastAccessed?: number; lifecycle?: 'dormant' | 'loading' | 'ready'; availability?: 'ready' | 'load_required' | 'host_attachment_required' }
|
|
171
|
-
|
|
172
170
|
interface CloseUserTabsResult {
|
|
173
171
|
complete: boolean;
|
|
174
172
|
closed: number[];
|
|
@@ -193,6 +191,14 @@ interface DownloadWaitResult {
|
|
|
193
191
|
elapsedMs: number;
|
|
194
192
|
}
|
|
195
193
|
|
|
194
|
+
type EvaluateOptions = { arg?: unknown; frame?: string | number | Array<string | number> | undefined; timeoutMs?: number | undefined; };
|
|
195
|
+
|
|
196
|
+
type TabDiscoveryOptions = { query?: string | undefined; limit?: number | undefined; offset?: number | undefined; };
|
|
197
|
+
|
|
198
|
+
type UserTabInfo = { tabId: number; windowId: number; active: boolean; title?: string | undefined; url?: string | undefined; groupId?: number | undefined; lastAccessed?: number | undefined; lifecycle?: "dormant" | "loading" | "ready" | undefined; availability?: "ready" | "load_required" | "host_attachment_required" | undefined; };
|
|
199
|
+
|
|
200
|
+
type TabDiscoveryResult = { scope: "unclaimed"; query: string; matching: "case-insensitive-substring"; totalVisible: number; totalInScope: number; excluded: { owned: number; unsupported: number; }; matched: number; offset: number; limit: number; hasMore: boolean; items: Array<{ tabId: number; windowId: number; active: boolean; title?: string | undefined; url?: string | undefined; groupId?: number | undefined; lastAccessed?: number | undefined; lifecycle?: "dormant" | "loading" | "ready" | undefined; availability?: "ready" | "load_required" | "host_attachment_required" | undefined; }>; nextOffset?: number | undefined; };
|
|
201
|
+
|
|
196
202
|
interface PageTool { name: string; description?: string; inputSchema?: unknown }
|
|
197
203
|
|
|
198
204
|
interface PageToolsUpdate { status: 'ready' | 'unavailable'; frame: FrameStep[]; tools: Array<{ name: string; description?: string }>; truncated?: boolean }
|
package/docs/errors.md
CHANGED
|
@@ -26,3 +26,29 @@ Every error has `code`, `message`, optional `hint`, and any structured data spre
|
|
|
26
26
|
| JavaScript | `js_error`, `js_timeout`, `js_cancelled`, `js_reset`, `js_busy`, `js_worker_failed`, `js_worker_exited` | ordinary exceptions preserve bindings; timeout, cancellation, reset and worker failure clear them. `js_busy`: wait for `doctor` javascript.pendingCalls to reach zero. See `repl-session` for execution and recovery semantics |
|
|
27
27
|
|
|
28
28
|
Native browser APIs report `chrome_api_unavailable`, `chrome_api_error`, `unsupported_call_shape`, and `runtime_state_conflict`. Inspect `browser.chrome.describe(member)` for context/signatures. Streams report loss/reset in their results; `stream_closed` requires a new watch. `command_outcome_unknown` means dispatched page code may have run: inspect before retrying. `result_not_serializable` requires returning plain data.
|
|
29
|
+
|
|
30
|
+
## Trustworthy API boundaries
|
|
31
|
+
|
|
32
|
+
`invalid_args` with `dispatched:false` rejects an invocation before browser effects; fix the indicated field and retry that call. Evaluation does not guess positional arguments or discard unknown options. REPL call transport rejects lossy values rather than applying display formatting to them.
|
|
33
|
+
|
|
34
|
+
`invalid_response` from tab discovery means a backend response violated the protocol, not that the browser has no tabs. Check `doctor` for host/backend versions. Protocol revision 4 requires the discovery envelope; update host and extension together.
|
|
35
|
+
|
|
36
|
+
For discovery, `totalInScope:0` means no eligible unclaimed tabs in the visible scope; `totalInScope>0, matched:0` means no literal query match. `excluded` explains ownership and unsupported-page exclusions. `hasMore` distinguishes a partial result from a complete match set. Search emptiness is not an exception.
|
|
37
|
+
|
|
38
|
+
Issues #18 and #19 exposed different evidence: #18's silent argument loss is reproducible. #19's literal `x.com/home` query matches `https://x.com/home` in the reported version's implementation; its reported live discrepancy is not established by that example alone. The discovery envelope and strict response validation address the confirmed ambiguity without asserting an unverified incident cause.
|
|
39
|
+
|
|
40
|
+
The design borrows explicit tool contracts from OpenAI's public function-calling guidance (https://developers.openai.com/api/docs/guides/function-calling) and observe/action feedback from the publicly described ChatGPT agent (https://openai.com/index/introducing-chatgpt-agent/). These sources do not disclose ChatGPT's internal tab-search implementation. In this REPL, an MCP schema for the outer `code` string cannot validate nested JavaScript API calls; runtime contracts remain necessary.
|
|
41
|
+
|
|
42
|
+
### Local client implementation evidence
|
|
43
|
+
|
|
44
|
+
A read-only inspection of the locally installed ChatGPT.app ASAR on 2026-10-22 found package `openai-codex-electron` version `26.1007.30912`. In `.vite/build/main-CqEoQDOU.js` (SHA-256 `09d19386e1f23cf4ccbc950fc40d85a1e8a064a08be588b2a4be6a89f6ada9e6`), these named methods remain visible in the bundled JavaScript:
|
|
45
|
+
|
|
46
|
+
- `getTabsForBrowserUse` and `serializeTab`: build inventory from host metadata and optional live runtime, expose stable provider identity and session-control status, and choose an active tab. This layer has no query argument; it does not establish how a separate search API works.
|
|
47
|
+
- `requireLiveTab`: recover a missing execution resource only when a concrete tab is needed. Inventory survives WebContents destruction.
|
|
48
|
+
- `requireBrowserUseTab`: enforce the session route before access.
|
|
49
|
+
- `assertTabMatchesCurrentBrowserUsePage`: check page identity and WebContents identity/liveness before dispatch, including after asynchronous waits.
|
|
50
|
+
- `runLoggedRequest`: attach session/request/turn context to failures and rethrow them.
|
|
51
|
+
|
|
52
|
+
These are observations of the installed desktop bundle, not claims about ChatGPT's server implementation or original source. We independently implement shared discovery contracts and retain host-owned logical tabs. We do not adopt its fallback to the first tab as an indication of the user's foreground intent. No vendor code is included in this repository.
|
|
53
|
+
|
|
54
|
+
The installed `openai-bundled/browser/26.1007.30912/scripts/browser-client.mjs` provides more direct evidence: `BrowserUser.openTabs()` accepts no query and returns `.tabs`; `PlaywrightAPI.evaluate` takes `(function, arg, options)`. Its argument serializer uses `JSON.stringify`; isolated execution confirmed `NaN` becomes `null` and `{x:undefined}` becomes `{}`. Those are reasons to enforce our own lossless contract, not copy that implementation. The positional signature explains a plausible source of API confusion, but does not establish what happened in either reporter's session.
|
package/docs/js-tool.md
CHANGED
|
@@ -13,9 +13,11 @@ await tab.observe();
|
|
|
13
13
|
Or borrow a user tab:
|
|
14
14
|
```js
|
|
15
15
|
let matches = await browser.user.openTabs({query: 'example.com', limit: 20});
|
|
16
|
-
matches;
|
|
16
|
+
matches.items;
|
|
17
17
|
```
|
|
18
|
-
|
|
18
|
+
The result reports `totalVisible`, `totalInScope`, `excluded`, `matched`, and `hasMore`. `scope:"unclaimed"` excludes actively owned and unsupported tabs. Query is a trimmed case-insensitive literal substring of URL OR title, without whitespace token splitting. For more results, pass `offset: matches.nextOffset` with the same query and limit; each call is a fresh snapshot. Zero matches is a valid result; invalid transport responses are errors.
|
|
19
|
+
|
|
20
|
+
Copy an item’s numeric `tabId` into `await browser.user.claimTab({tabId: ...})`. Store the returned Tab handle, then observe it. Session handles come from `await browser.tabs.list()` and `await browser.tabs.get(id)`.
|
|
19
21
|
|
|
20
22
|
After reading the observation, call `await tab.act({action:'click', target:{ref: '...'}})` using a returned ref, then `await tab.observe()` or `await tab.expect({text:'...'})` with the expected result. `await tab.read()` reads document text. Batch determined steps; return at new decision points.
|
|
21
23
|
|
|
@@ -36,3 +38,9 @@ Finish with `session_finalize`. Use `doctor` for connection/execution status and
|
|
|
36
38
|
Reuse the same target for verification: `await tab.expect({target, value:"42"})`. Continue captured output with `tab.observe(result.next)` or `tab.read(result.next)`. Pass an `openedTabs` entry directly to `browser.tabs.get`, and the returned download object to `tab.download(result.download)`.
|
|
37
39
|
|
|
38
40
|
Tab handles expose async methods: use `await tab.url()` and `await tab.title()`. Entries returned by `browser.tabs.list()` are snapshots with string `url` and `title` fields. Inspecting or converting a remote method to a string describes the method locally; it never reads the page.
|
|
41
|
+
|
|
42
|
+
### Page evaluation contract
|
|
43
|
+
|
|
44
|
+
Use `await tab.evaluate(value => value, {arg: data})`. The second argument is a strict options object with only `arg`, `frame`, and `timeoutMs`; extra positional arguments and unknown fields fail before dispatch. Source strings do not accept `arg`. Functions run in the page and cannot capture REPL variables.
|
|
45
|
+
|
|
46
|
+
Arguments are plain JSON data: null, booleans, strings, finite numbers (excluding negative zero), dense arrays and plain objects. Root `arg: undefined` is allowed. Nested undefined, non-finite numbers, BigInt, functions, special objects, accessors, symbol keys and cycles are rejected, never silently rewritten. Convert special values explicitly. API handles can be passed to APIs that accept them; they are not page data. Errors with `dispatched:false` mean the rejected invocation had no page effects. This does not undo earlier calls in the same cell.
|
package/docs/tab-lifecycle.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Use these methods in `js`, awaiting every call. Start with `await browser.nameSession('🔎 Research')`, then `let tab = await browser.tabs.new(url)`. Agent-created tabs open in a named Chrome group, in the background, muted until the user looks at them.
|
|
4
4
|
|
|
5
|
-
To use an existing tab, call `await browser.user.openTabs({query:'…',limit:20})`, then `let tab = await browser.user.claimTab({tabId})`. Discovery is recency-sorted,
|
|
5
|
+
To use an existing tab, call `await browser.user.openTabs({query:'…',limit:20})`, then `let tab = await browser.user.claimTab({tabId})`. Read the returned `items` array. Discovery reports its `scope:"unclaimed"`, visible/in-scope totals, excluded owned/unsupported counts, and match count. Matching is a trimmed, case-insensitive literal substring of URL OR title (no token splitting). Results are recency-sorted with tabId as a tie-breaker, default to 20 and allow up to 100 per page. Continue with `offset: nextOffset` while `hasMore`; each request is a fresh snapshot, so tab changes can shift pagination. Discovery never claims or loads a tab. To claim the foreground tab, use `{active:true}`. Unique URL/title lookup is also supported; `expectedUrl` and `expectedTitle` check exact identity when necessary. Claiming alone does not observe the page. Claimed user tabs stay outside the agent group and are never closed by finalize.
|
|
6
6
|
|
|
7
7
|
`await browser.tabs.list()` returns controlled tabs with string `id`, numeric backend `tabId`, `origin` and `state`. Obtain a handle with `await browser.tabs.get(id)`. The page id is stable across navigation and becomes stale after logical closure. In Electron it also survives WebContents replacement; `lifecycle` reports dormant, loading or ready. A newly attaching extension tab may return `pending:true` without an id; match its numeric `tabId` on a later list call. Unknown ids are rejected rather than adopted.
|
|
8
8
|
|