@jackwener/browsermcp 0.0.32 → 0.0.34-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 +24 -1
- package/README.md +67 -7
- package/adapters/discord/_shared.js +1 -1
- package/adapters/facebook/_graphql.js +1 -1
- package/adapters/facebook/events.js +1 -1
- package/adapters/facebook/feed.js +2 -2
- package/adapters/facebook/friends.js +1 -1
- package/adapters/facebook/groups.js +1 -1
- package/adapters/facebook/notifications.js +1 -1
- package/adapters/gmail/_shared.js +1 -1
- package/cordis.patch.yml +1 -3
- package/dist/docs/api-reference.md +22 -16
- package/dist/docs/api-use.md +69 -65
- package/dist/docs/capabilities/webmcp.md +5 -1
- package/dist/docs/define-tools.md +1 -1
- package/dist/docs/errors.md +1 -1
- package/dist/docs/instructions.md +1 -1
- package/dist/docs/js-tool.md +4 -2
- package/dist/docs/sites.md +1 -1
- package/dist/src/api/action-input.d.ts +47 -0
- package/dist/src/api/action-input.js +13 -7
- package/dist/src/api/action-input.js.map +1 -1
- package/dist/src/api/agent.d.ts +10 -0
- package/dist/src/api/api.d.ts +50 -0
- package/dist/src/api/api.js +8 -9
- package/dist/src/api/api.js.map +1 -1
- package/dist/src/api/browser.d.ts +89 -0
- package/dist/src/api/browser.js +25 -6
- package/dist/src/api/browser.js.map +1 -1
- package/dist/src/api/context.d.ts +7 -0
- package/dist/src/api/diff.d.ts +8 -0
- package/dist/src/api/errors.d.ts +12 -0
- package/dist/src/api/network.d.ts +10 -0
- package/dist/src/api/observation.d.ts +4 -0
- package/dist/src/api/observation.js +2 -1
- package/dist/src/api/observation.js.map +1 -1
- package/dist/src/api/streams.d.ts +13 -0
- package/dist/src/api/streams.js +1 -1
- package/dist/src/api/streams.js.map +1 -1
- package/dist/src/api/tab.d.ts +308 -0
- package/dist/src/api/tab.js +86 -13
- package/dist/src/api/tab.js.map +1 -1
- package/dist/src/api/webmcp.d.ts +19 -0
- package/dist/src/api/webmcp.js +43 -0
- package/dist/src/api/webmcp.js.map +1 -0
- package/dist/src/backends/backend.d.ts +14 -0
- package/dist/src/backends/backend.js +2 -0
- package/dist/src/backends/backend.js.map +1 -0
- package/dist/src/backends/browser-helpers.d.ts +17 -0
- package/dist/src/backends/extension-page.d.ts +5 -0
- package/dist/src/backends/extension-page.js +23 -6
- package/dist/src/backends/extension-page.js.map +1 -1
- package/dist/src/backends/managed-page.d.ts +57 -0
- package/dist/src/backends/managed-page.js +2 -0
- package/dist/src/backends/managed-page.js.map +1 -0
- package/dist/src/backends/page-transport.d.ts +10 -0
- package/dist/src/backends/page-transport.js +2 -0
- package/dist/src/backends/page-transport.js.map +1 -0
- package/dist/src/backends/page-types.d.ts +82 -0
- package/dist/src/docs/embedded.d.ts +2 -0
- package/dist/src/docs/embedded.js +33 -0
- package/dist/src/docs/embedded.js.map +1 -0
- package/dist/src/docs/manifest.d.ts +23 -0
- package/dist/src/docs/manifest.js +6 -3
- package/dist/src/docs/manifest.js.map +1 -1
- package/dist/src/docs/surface.d.ts +12 -0
- package/dist/src/electron/backend.d.ts +46 -0
- package/dist/src/electron/backend.js +333 -0
- package/dist/src/electron/backend.js.map +1 -0
- package/dist/src/electron/chrome.d.ts +24 -0
- package/dist/src/electron/chrome.js +135 -0
- package/dist/src/electron/chrome.js.map +1 -0
- package/dist/src/electron/driver.d.ts +42 -0
- package/dist/src/electron/driver.js +238 -0
- package/dist/src/electron/driver.js.map +1 -0
- package/dist/src/electron/event-buffer.d.ts +16 -0
- package/dist/src/electron/event-buffer.js +59 -0
- package/dist/src/electron/event-buffer.js.map +1 -0
- package/dist/src/electron/page.js +834 -0
- package/dist/src/electron/registry.d.ts +33 -0
- package/dist/src/electron/registry.js +85 -0
- package/dist/src/electron/registry.js.map +1 -0
- package/dist/src/electron/streams.d.ts +16 -0
- package/dist/src/electron/streams.js +48 -0
- package/dist/src/electron/streams.js.map +1 -0
- package/dist/src/embedded/index.d.ts +30 -0
- package/dist/src/embedded/index.js +57 -0
- package/dist/src/embedded/index.js.map +1 -0
- package/dist/src/host/bridge.d.ts +50 -0
- package/dist/src/host/doctor.d.ts +34 -0
- package/dist/src/host/extension.d.ts +3 -0
- package/dist/src/host/extension.js +1 -1
- package/dist/src/host/extension.js.map +1 -1
- package/dist/src/host/host.d.ts +3 -0
- package/dist/src/host/host.js +2 -1
- package/dist/src/host/host.js.map +1 -1
- package/dist/src/host/ipc.d.ts +14 -0
- package/dist/src/host/ipc.js +1 -1
- package/dist/src/host/ipc.js.map +1 -1
- package/dist/src/host/jsonc-config.d.ts +1 -0
- package/dist/src/host/jsonc-config.js +4 -7
- package/dist/src/host/jsonc-config.js.map +1 -1
- package/dist/src/host/launch.d.ts +11 -0
- package/dist/src/host/launch.js +3 -3
- package/dist/src/host/launch.js.map +1 -1
- package/dist/src/host/native-messaging.d.ts +28 -0
- package/dist/src/host/opencode.d.ts +6 -0
- package/dist/src/host/opencode.js +1 -1
- package/dist/src/host/opencode.js.map +1 -1
- package/dist/src/host/pi.d.ts +6 -0
- package/dist/src/host/pi.js +1 -1
- package/dist/src/host/pi.js.map +1 -1
- package/dist/src/host/registration.d.ts +24 -0
- package/dist/src/host/registration.js +2 -2
- package/dist/src/host/registration.js.map +1 -1
- package/dist/src/host/setup.d.ts +7 -0
- package/dist/src/host/setup.js +0 -8
- package/dist/src/host/setup.js.map +1 -1
- package/dist/src/host/socket.d.ts +25 -0
- package/dist/src/host/socket.js +1 -1
- package/dist/src/host/socket.js.map +1 -1
- package/dist/src/host/state.d.ts +39 -0
- package/dist/src/host/state.js +5 -6
- package/dist/src/host/state.js.map +1 -1
- package/dist/src/launcher/stdio.d.ts +3 -0
- package/dist/src/launcher/stdio.js +1 -1
- package/dist/src/launcher/stdio.js.map +1 -1
- package/dist/src/lib/paths.d.ts +1 -0
- package/dist/src/lib/paths.js +4 -0
- package/dist/src/lib/paths.js.map +1 -0
- package/dist/src/lib/sources.d.ts +5 -0
- package/dist/src/lib/sources.js +2 -2
- package/dist/src/lib/sources.js.map +1 -1
- package/dist/src/main.d.ts +2 -0
- package/dist/src/mcp/catalog.d.ts +202 -0
- package/dist/src/mcp/js-evaluator.mjs +3 -3
- package/dist/src/mcp/js-session.d.ts +63 -0
- package/dist/src/mcp/server.d.ts +15 -0
- package/dist/src/mcp/server.js +5 -5
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/protocol.d.ts +318 -0
- package/dist/src/protocol.js +1 -1
- package/dist/src/protocol.js.map +1 -1
- package/dist/src/recon/analyzer.d.ts +43 -0
- package/dist/src/recon/discover.d.ts +48 -0
- package/dist/src/runtime/runtime.d.ts +148 -0
- package/dist/src/runtime/runtime.js +79 -34
- package/dist/src/runtime/runtime.js.map +1 -1
- package/dist/src/shared/aria-tree.d.ts +2 -0
- package/dist/src/shared/element-ref.d.ts +4 -0
- package/dist/src/shared/engine.d.ts +50 -0
- package/dist/src/shared/engine.js +3 -3
- package/dist/src/shared/engine.js.map +1 -1
- package/dist/src/shared/injected-source.d.ts +2 -0
- package/dist/src/shared/page-contract.d.ts +256 -0
- package/dist/src/shared/page-contract.js +3 -3
- package/dist/src/shared/page-contract.js.map +1 -1
- package/dist/src/sites/define.d.ts +28 -0
- package/dist/src/sites/define.js +25 -29
- package/dist/src/sites/define.js.map +1 -1
- package/dist/src/sites/drafts.d.ts +39 -0
- package/dist/src/sites/drafts.js +117 -115
- package/dist/src/sites/drafts.js.map +1 -1
- package/dist/src/sites/executor.d.ts +34 -0
- package/dist/src/sites/loader.d.ts +84 -0
- package/dist/src/sites/loader.js +1 -1
- package/dist/src/sites/schema.d.ts +11 -0
- package/docs/api-reference.md +22 -16
- package/docs/api-use.md +69 -65
- package/docs/capabilities/webmcp.md +5 -1
- package/docs/define-tools.md +1 -1
- package/docs/errors.md +1 -1
- package/docs/guide.zh-CN.md +4 -4
- package/docs/instructions.md +1 -1
- package/docs/js-tool.md +4 -2
- package/docs/observation-design.md +11 -3
- package/docs/releasing.md +8 -0
- package/docs/setup.md +22 -8
- package/docs/sites.md +1 -1
- package/extension/dist/background.js +20 -22
- package/extension/dist/content/cursor.js +3 -3
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/page.js +48 -15
- package/package.json +12 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.js","sourceRoot":"","sources":["../../../src/api/observation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,mFAAmF;AACnF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC,+FAA+F;AAC/F,MAAM,UAAU,eAAe,CAAC,OAAsB,EAAE,MAAe;IACrE,MAAM,KAAK,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAsB,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;IACzE,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;QACnM,MAAM,IAAI,WAAW,CAAC,mBAAmB,EAAE,2CAA2C,EAAE,0CAA0C,CAAC,CAAC;IACtI,CAAC;IACD,MAAM,EAA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O,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Command, StreamBatch, StreamOptions, StreamReadOptions } from '../protocol.js';
|
|
2
|
+
import type { SessionContext } from './context.js';
|
|
3
|
+
export interface EventStream {
|
|
4
|
+
/** Reads after the handle's last read, or an explicit cursor. Filtering still advances the cursor. */
|
|
5
|
+
read(options?: StreamReadOptions): Promise<StreamBatch>;
|
|
6
|
+
/** Idempotently releases this subscription. */
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function browserCommand(ctx: SessionContext, feature: import('../protocol.js').BrowserFeature, action: Command['action'], params?: Partial<Command>): Promise<unknown>;
|
|
10
|
+
export declare function watch(ctx: SessionContext, source: 'chrome' | 'cdp' | 'console' | 'extension', event?: string, options?: StreamOptions, page?: string, route?: {
|
|
11
|
+
session: string;
|
|
12
|
+
surface: 'browser' | 'adapter';
|
|
13
|
+
}): Promise<EventStream>;
|
package/dist/src/api/streams.js
CHANGED
|
@@ -7,7 +7,7 @@ export async function browserCommand(ctx, feature, action, params = {}) {
|
|
|
7
7
|
await ctx.rt.getBrowserPage(ctx.sessionId);
|
|
8
8
|
if (action === 'stream-watch' || (action === 'chrome-call' && ['tabs.create', 'tabs.duplicate', 'windows.create'].includes(params.chromeMethod ?? '')))
|
|
9
9
|
ctx.state.finalized = false;
|
|
10
|
-
return (await ctx.rt.
|
|
10
|
+
return (await ctx.rt.browserCommand(action, { session: `mcp:${ctx.sessionId}`, surface: 'browser', ...params })).data;
|
|
11
11
|
}
|
|
12
12
|
export async function watch(ctx, source, event, options, page, route) {
|
|
13
13
|
const descriptor = await browserCommand(ctx, 'streams', 'stream-watch', { ...route, streamSource: source, eventName: event, streamOptions: options, page });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../../../src/api/streams.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CA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f,CAAC;QACD,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,IAAI,MAAM;gBAAE,OAAO;YACnB,MAAM,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,cAAc,EAAE,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5F,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { type PageTool, type PageToolsUpdate } from './webmcp.js';
|
|
2
|
+
import type { StreamOptions, StreamReadOptions } from '../protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* Tab — one browser tab of a session: observe (aria snapshot + semantic diff), find, act, expect, evaluate, screenshot,
|
|
5
|
+
* network/console/dialog/webmcp/frames. A Tab owns the page object bound to its identity; operations are serialized per tab.
|
|
6
|
+
*/
|
|
7
|
+
import type { RuntimePage } from '../backends/page-types.js';
|
|
8
|
+
import type { Target, FindResult, QueryFindResult, ElementAtResult, Expectation, CheckResult, ReadTextResult, FrameOwner, DomSnapshot, ElementDetails } from '../shared/page-contract.js';
|
|
9
|
+
import type { DialogInfo, DownloadWaitResult, FrameStep } from '../protocol.js';
|
|
10
|
+
import type { SessionContext } from './context.js';
|
|
11
|
+
export type { Target } from '../shared/page-contract.js';
|
|
12
|
+
export type ActAction = 'click' | 'dblclick' | 'hover' | 'focus' | 'fill' | 'type' | 'press' | 'select' | 'check' | 'uncheck' | 'upload' | 'drag' | 'scroll' | 'back' | 'forward' | 'reload';
|
|
13
|
+
export interface ActOptions {
|
|
14
|
+
target?: Target;
|
|
15
|
+
action: ActAction;
|
|
16
|
+
value?: string;
|
|
17
|
+
files?: string[];
|
|
18
|
+
to?: Target;
|
|
19
|
+
direction?: 'up' | 'down' | 'left' | 'right';
|
|
20
|
+
amount?: number;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
settleMs?: number; /** click only. `dom` runs HTMLElement.click() and sends no mouse event. Default is a real mouse event. */
|
|
23
|
+
method?: 'cdp' | 'dom';
|
|
24
|
+
}
|
|
25
|
+
/** Input delivery and control verification are separate from completion of the site's task. */
|
|
26
|
+
export interface ActionOutcome {
|
|
27
|
+
action: ActAction;
|
|
28
|
+
delivery: 'applied' | 'received' | 'dispatched';
|
|
29
|
+
controlState: 'verified' | 'unverified';
|
|
30
|
+
network?: {
|
|
31
|
+
afterSequence: number;
|
|
32
|
+
cursor: number;
|
|
33
|
+
};
|
|
34
|
+
matches_n?: number;
|
|
35
|
+
navigated?: boolean;
|
|
36
|
+
url?: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
timedOut?: boolean;
|
|
39
|
+
ref?: string;
|
|
40
|
+
/** For fill/type, true only when the settled value matches the requested result. */
|
|
41
|
+
filled?: boolean;
|
|
42
|
+
verified?: boolean;
|
|
43
|
+
actual?: string;
|
|
44
|
+
checked?: boolean;
|
|
45
|
+
changed?: boolean;
|
|
46
|
+
selected?: string[];
|
|
47
|
+
files?: number;
|
|
48
|
+
openedTabs?: Array<{
|
|
49
|
+
tab?: string;
|
|
50
|
+
tabId: number;
|
|
51
|
+
url?: string;
|
|
52
|
+
title?: string;
|
|
53
|
+
pending?: true;
|
|
54
|
+
}>;
|
|
55
|
+
download?: {
|
|
56
|
+
tab: string;
|
|
57
|
+
afterSequence: number;
|
|
58
|
+
started: Array<{
|
|
59
|
+
seq: number;
|
|
60
|
+
guid?: string;
|
|
61
|
+
url: string;
|
|
62
|
+
suggestedFilename: string;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
/** Present when the action used DOM activation or a native control setter. */
|
|
66
|
+
method?: 'dom';
|
|
67
|
+
}
|
|
68
|
+
export interface ObserveOptions {
|
|
69
|
+
/** Continue the previous immutable capture. Pass cursor alone; a fresh observation replaces it. */
|
|
70
|
+
cursor?: string;
|
|
71
|
+
mode?: 'state' | 'screenshot' | 'both';
|
|
72
|
+
/** ARIA overview (default) or independent visible controls and live DOM attributes. */
|
|
73
|
+
format?: 'aria' | 'dom';
|
|
74
|
+
/** Frame path from an observation; identical to target.frame in act/find/read. */
|
|
75
|
+
frame?: FrameStep | FrameStep[];
|
|
76
|
+
/** Return a diff only against this exact snapshot id; otherwise return full state. ARIA only. */
|
|
77
|
+
since?: string;
|
|
78
|
+
/** ARIA defaults to the whole document; DOM defaults to the viewport. */
|
|
79
|
+
viewport?: boolean;
|
|
80
|
+
/** Open a branch in the selected frame. */
|
|
81
|
+
ref?: string;
|
|
82
|
+
/** Observe a known container using the same locator contract as read/act, without first obtaining a ref. */
|
|
83
|
+
target?: Target;
|
|
84
|
+
/** DOM pagination within the selected frame. The live page can change between calls. */
|
|
85
|
+
start?: number;
|
|
86
|
+
limit?: number;
|
|
87
|
+
/** Include child frames, without scrolling. Default true. */
|
|
88
|
+
includeFrames?: boolean;
|
|
89
|
+
/** Overlay main-frame ref labels on the screenshot. */
|
|
90
|
+
annotate?: boolean;
|
|
91
|
+
fullPage?: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface ObservedContent {
|
|
94
|
+
metadataTruncated?: boolean; /** A single oversized text line can span pages. Concatenate these fragments before interpreting it. */
|
|
95
|
+
stateContinued?: boolean;
|
|
96
|
+
stateContinues?: boolean;
|
|
97
|
+
state?: string;
|
|
98
|
+
dom?: DomSnapshot;
|
|
99
|
+
warnings?: string[];
|
|
100
|
+
diff?: boolean;
|
|
101
|
+
changed?: {
|
|
102
|
+
added: number;
|
|
103
|
+
removed: number;
|
|
104
|
+
changed?: number;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export interface ObservedFrame extends ObservedContent {
|
|
108
|
+
frame: FrameStep[];
|
|
109
|
+
owner: FrameOwner;
|
|
110
|
+
unavailable?: string;
|
|
111
|
+
}
|
|
112
|
+
export interface ObserveResult extends ObservedContent {
|
|
113
|
+
/** Whether this is the final output page, not a claim that all dynamic page content was captured. */
|
|
114
|
+
complete?: boolean;
|
|
115
|
+
/** Page-provided tool catalog changes in the observed root frame; schemas are fetched explicitly. */
|
|
116
|
+
webmcp?: PageToolsUpdate;
|
|
117
|
+
/** Continue this captured state with observe({cursor: nextCursor}). */
|
|
118
|
+
nextCursor?: string;
|
|
119
|
+
/** Pass directly to tab.observe(result.next) to continue this capture. */
|
|
120
|
+
next?: {
|
|
121
|
+
cursor: string;
|
|
122
|
+
};
|
|
123
|
+
url: string | null;
|
|
124
|
+
title: string | null;
|
|
125
|
+
snapshotId?: string;
|
|
126
|
+
image?: ImageValue;
|
|
127
|
+
/** Child frames and explicit routes for semantic locators or document reads; refs route automatically. */
|
|
128
|
+
frames?: ObservedFrame[];
|
|
129
|
+
/** False if a discovered frame could not be captured or the bounded traversal stopped. */
|
|
130
|
+
framesComplete?: boolean;
|
|
131
|
+
}
|
|
132
|
+
export interface ReadOptions {
|
|
133
|
+
maxChars?: number; /** character offset returned as nextStart by a previous read */
|
|
134
|
+
start?: number; /** capture id returned by that same read */
|
|
135
|
+
readId?: string;
|
|
136
|
+
frame?: FrameStep | FrameStep[];
|
|
137
|
+
}
|
|
138
|
+
export interface DocumentReadResult extends ReadTextResult {
|
|
139
|
+
next?: ReadOptions;
|
|
140
|
+
}
|
|
141
|
+
export interface ReadElementOptions {
|
|
142
|
+
target: Target;
|
|
143
|
+
}
|
|
144
|
+
export interface ImageValue {
|
|
145
|
+
__image: true;
|
|
146
|
+
mimeType: string;
|
|
147
|
+
base64: string;
|
|
148
|
+
}
|
|
149
|
+
export declare class Tab {
|
|
150
|
+
private readonly initialId;
|
|
151
|
+
private readonly ctx;
|
|
152
|
+
private readonly bound?;
|
|
153
|
+
/** A Tab owns the page object bound to its identity; `bound` lets an adapter pass an existing page. */
|
|
154
|
+
/** `id` is the Chrome tab id as a string; `tabId` is the numeric id when claimed from a user tab. */
|
|
155
|
+
readonly tabId?: number;
|
|
156
|
+
constructor(initialId: string, ctx: SessionContext, bound?: RuntimePage | undefined, tabId?: number);
|
|
157
|
+
get id(): string;
|
|
158
|
+
toJSON(): {
|
|
159
|
+
type: 'Tab';
|
|
160
|
+
id: string;
|
|
161
|
+
tabId?: number;
|
|
162
|
+
};
|
|
163
|
+
private closed;
|
|
164
|
+
/** Run `fn` on this tab's own page object. Operations are serialized per tab, never across tabs. */
|
|
165
|
+
use<T>(fn: (page: RuntimePage) => Promise<T>): Promise<T>;
|
|
166
|
+
/** Reuse the document namespace already present in refs; no second element-id system. */
|
|
167
|
+
private rememberRefs;
|
|
168
|
+
private routeTarget;
|
|
169
|
+
goto(url: string, opts?: {
|
|
170
|
+
waitUntil?: 'load' | 'none';
|
|
171
|
+
settleMs?: number;
|
|
172
|
+
}): Promise<{
|
|
173
|
+
url: string | null;
|
|
174
|
+
title: string | null;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Pull captured requests into the session's bounded network log. Best effort — never fails a step.
|
|
178
|
+
*/
|
|
179
|
+
private harvest;
|
|
180
|
+
private logNetwork;
|
|
181
|
+
private info;
|
|
182
|
+
url(): Promise<string | null>;
|
|
183
|
+
title(): Promise<string | null>;
|
|
184
|
+
back(): Promise<void>;
|
|
185
|
+
forward(): Promise<void>;
|
|
186
|
+
reload(): Promise<void>;
|
|
187
|
+
/** Close this tab, whether it was opened or claimed by this session. */
|
|
188
|
+
close(): Promise<void>;
|
|
189
|
+
/** Keep this tab open and give up this session's control of it. */
|
|
190
|
+
release(): Promise<void>;
|
|
191
|
+
/** ARIA overview by default; format:'dom' reveals visible controls and live attributes. Observed refs automatically route to their frame. */
|
|
192
|
+
observe(opts?: ObserveOptions): Promise<ObserveResult>;
|
|
193
|
+
screenshot(opts?: {
|
|
194
|
+
fullPage?: boolean;
|
|
195
|
+
annotate?: boolean;
|
|
196
|
+
format?: 'png' | 'jpeg';
|
|
197
|
+
quality?: number;
|
|
198
|
+
}): Promise<ImageValue>;
|
|
199
|
+
private screenshotOn;
|
|
200
|
+
find(target: (Target & {
|
|
201
|
+
limit?: number;
|
|
202
|
+
}) | {
|
|
203
|
+
query: string;
|
|
204
|
+
limit?: number;
|
|
205
|
+
frame?: FrameStep | FrameStep[];
|
|
206
|
+
}): Promise<FindResult | ElementAtResult | QueryFindResult>;
|
|
207
|
+
/**
|
|
208
|
+
* With target: exact current element text, attributes and live values, without scrolling.
|
|
209
|
+
* Otherwise: bounded document text scan (including open shadow roots), restores scroll; pass result.next to continue.
|
|
210
|
+
* A growing feed returns reason `unbounded`; the scan stops rather than chasing an endless bottom.
|
|
211
|
+
*/
|
|
212
|
+
read(opts: ReadElementOptions): Promise<ElementDetails>;
|
|
213
|
+
read(opts?: ReadOptions): Promise<DocumentReadResult>;
|
|
214
|
+
/** wait + act in one call at the runtime edge: locate → wait actionable → hit-test → real input → settle. `method:'dom'` skips the mouse event. */
|
|
215
|
+
act(opts: ActOptions): Promise<ActionOutcome>;
|
|
216
|
+
/** WebMCP: tools the page itself registers via navigator.modelContext (page-provided tool source). */
|
|
217
|
+
readonly webmcp: {
|
|
218
|
+
/** List names/descriptions, or fetch one full schema by name. Scoped to the requested frame. */
|
|
219
|
+
list: (options?: {
|
|
220
|
+
name?: string;
|
|
221
|
+
frame?: FrameStep | FrameStep[];
|
|
222
|
+
}) => Promise<PageTool[]>;
|
|
223
|
+
call: (name: string, input?: Record<string, unknown>, options?: {
|
|
224
|
+
frame?: FrameStep | FrameStep[];
|
|
225
|
+
}) => Promise<unknown>;
|
|
226
|
+
};
|
|
227
|
+
/** Assert what the page must show now (polled up to timeoutMs). */
|
|
228
|
+
expect(what: Expectation, opts?: {
|
|
229
|
+
timeoutMs?: number;
|
|
230
|
+
}): Promise<CheckResult>;
|
|
231
|
+
/** Main World page code; functions receive only opts.arg, never host closures. Dispatched scripts are never replayed. */
|
|
232
|
+
evaluate(script: string | ((arg: any) => any), opts?: {
|
|
233
|
+
arg?: unknown;
|
|
234
|
+
frame?: FrameStep | FrameStep[];
|
|
235
|
+
timeoutMs?: number;
|
|
236
|
+
}): Promise<unknown>;
|
|
237
|
+
/** Native CDP on this Tab's shared debugger attachment. Parameters are not rewritten. */
|
|
238
|
+
readonly cdp: {
|
|
239
|
+
send: (method: string, params?: Record<string, unknown>, target?: {
|
|
240
|
+
frameId: string;
|
|
241
|
+
}) => Promise<unknown>;
|
|
242
|
+
watch: (event: string, options?: StreamOptions) => Promise<import("./streams.js").EventStream>;
|
|
243
|
+
};
|
|
244
|
+
/** Native alert/confirm/prompt dialogs block the page; commands fail with `dialog_open` until answered. */
|
|
245
|
+
readonly dialog: {
|
|
246
|
+
get: () => Promise<DialogInfo | null>;
|
|
247
|
+
accept: (text?: string) => Promise<DialogInfo | null>;
|
|
248
|
+
dismiss: () => Promise<DialogInfo | null>;
|
|
249
|
+
};
|
|
250
|
+
/** Console messages and uncaught exceptions since the tab was attached (the plugin's tab.dev.logs); cursor-paged like network.read. */
|
|
251
|
+
readonly console: {
|
|
252
|
+
read: (opts?: StreamReadOptions) => Promise<import("../protocol.js").StreamBatch>;
|
|
253
|
+
watch: (options?: StreamOptions) => Promise<import("./streams.js").EventStream>;
|
|
254
|
+
};
|
|
255
|
+
readonly network: {
|
|
256
|
+
start: (pattern?: string) => Promise<boolean>;
|
|
257
|
+
list: (opts?: {
|
|
258
|
+
filter?: string;
|
|
259
|
+
limit?: number;
|
|
260
|
+
afterSequence?: number;
|
|
261
|
+
}) => Promise<{
|
|
262
|
+
cursor: number;
|
|
263
|
+
entries: Record<string, unknown>[];
|
|
264
|
+
hasMore: boolean;
|
|
265
|
+
}>;
|
|
266
|
+
detail: (opts: {
|
|
267
|
+
seq?: number;
|
|
268
|
+
requestId?: string;
|
|
269
|
+
part?: "request" | "response";
|
|
270
|
+
start?: number;
|
|
271
|
+
maxChars?: number;
|
|
272
|
+
}) => Promise<Record<string, unknown>>;
|
|
273
|
+
/**
|
|
274
|
+
* Cursor-paged read: pass `afterSequence` from the previous result to get only new requests. Returns network rows
|
|
275
|
+
* only; endpoint candidates come from the explicit `recon.discover(tab)` (not a hidden side effect of reading).
|
|
276
|
+
*/
|
|
277
|
+
read: (opts?: {
|
|
278
|
+
pattern?: string;
|
|
279
|
+
limit?: number;
|
|
280
|
+
includeStatic?: boolean;
|
|
281
|
+
afterSequence?: number;
|
|
282
|
+
}) => Promise<{
|
|
283
|
+
cursor: number;
|
|
284
|
+
entries: unknown[];
|
|
285
|
+
hasMore: boolean;
|
|
286
|
+
}>;
|
|
287
|
+
};
|
|
288
|
+
cookies(domain: string): Promise<unknown[]>;
|
|
289
|
+
/**
|
|
290
|
+
* Read one cookie's value at run time — useful for per-request tokens an adapter needs (csrf/ct0/
|
|
291
|
+
* csrftoken/XSRF-TOKEN). Defaults to the current page's host. Returns undefined when the cookie is absent.
|
|
292
|
+
*/
|
|
293
|
+
cookie(name: string, opts?: {
|
|
294
|
+
domain?: string;
|
|
295
|
+
}): Promise<string | undefined>;
|
|
296
|
+
/** Fetch JSON through the page (its cookies and origin) after verifying the endpoint. */
|
|
297
|
+
fetchJson(url: string, opts?: Record<string, unknown>): Promise<unknown>;
|
|
298
|
+
frames(): Promise<Array<{
|
|
299
|
+
index: number;
|
|
300
|
+
frameId: string;
|
|
301
|
+
url: string;
|
|
302
|
+
name: string;
|
|
303
|
+
crossOrigin?: boolean;
|
|
304
|
+
oopif?: boolean;
|
|
305
|
+
}>>;
|
|
306
|
+
/** Wait for the page download begun after a tab.act cursor, then check Chrome's file state. */
|
|
307
|
+
download(download: NonNullable<ActionOutcome['download']>, timeoutMs?: number): Promise<DownloadWaitResult>;
|
|
308
|
+
}
|
package/dist/src/api/tab.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { pageTools, pageToolsUpdate } from './webmcp.js';
|
|
1
2
|
import { watch } from './streams.js';
|
|
2
3
|
import { ActionError } from './errors.js';
|
|
3
4
|
import { checkActInput, checkExpect } from './action-input.js';
|
|
5
|
+
import { ARIA_REF_LINE } from '../shared/element-ref.js';
|
|
4
6
|
import { ariaDiff } from './diff.js';
|
|
5
7
|
import { networkDetail, networkSummary } from './network.js';
|
|
6
8
|
import { compactAria } from '../shared/aria-tree.js';
|
|
@@ -41,6 +43,32 @@ export class Tab {
|
|
|
41
43
|
release();
|
|
42
44
|
}
|
|
43
45
|
}
|
|
46
|
+
/** Reuse the document namespace already present in refs; no second element-id system. */
|
|
47
|
+
rememberRefs(refs, frame = []) {
|
|
48
|
+
let routes = this.ctx.state.refFrames.get(this.id);
|
|
49
|
+
if (!routes)
|
|
50
|
+
this.ctx.state.refFrames.set(this.id, routes = new Map());
|
|
51
|
+
for (const ref of refs) {
|
|
52
|
+
const scope = /^e([a-f0-9]{16})_/.exec(ref)?.[1];
|
|
53
|
+
if (!scope || routes.has(scope))
|
|
54
|
+
continue;
|
|
55
|
+
// A newer document at this exact route replaces its old routing entry.
|
|
56
|
+
for (const [key, path] of routes)
|
|
57
|
+
if (JSON.stringify(path) === JSON.stringify(frame))
|
|
58
|
+
routes.delete(key);
|
|
59
|
+
routes.set(scope, frame);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
routeTarget(target) {
|
|
63
|
+
if (target.frame !== undefined)
|
|
64
|
+
return target;
|
|
65
|
+
const identity = 'ref' in target ? target.ref : target.within;
|
|
66
|
+
const scope = /^e([a-f0-9]{16})_/.exec(String(identity ?? ''))?.[1];
|
|
67
|
+
const frame = scope && this.ctx.state.refFrames.get(this.id)?.get(scope);
|
|
68
|
+
if (scope && !frame)
|
|
69
|
+
throw new ActionError('stale_ref', 'This ref has no observed document in this tab.', 'Observe or find the target again; use its returned ref.');
|
|
70
|
+
return frame?.length ? { ...target, frame } : target;
|
|
71
|
+
}
|
|
44
72
|
async goto(url, opts = {}) {
|
|
45
73
|
if (!/^(https?:\/\/|data:text\/html)/i.test(url))
|
|
46
74
|
throw new ActionError('invalid_url', 'Only http(s) (or data:text/html) URLs can be opened', 'Pass an absolute http:// or https:// URL');
|
|
@@ -102,8 +130,17 @@ export class Tab {
|
|
|
102
130
|
async close() { await this.use((p) => p.closeTab(this.id)); this.closed = true; this.ctx.rt.forgetPage(this.ctx.sessionId, this.id); }
|
|
103
131
|
/** Keep this tab open and give up this session's control of it. */
|
|
104
132
|
async release() { await this.use((p) => p.releaseTab(this.id)); this.closed = true; this.ctx.rt.forgetPage(this.ctx.sessionId, this.id); }
|
|
105
|
-
/** ARIA overview by default; format:'dom' reveals visible controls and live attributes.
|
|
133
|
+
/** ARIA overview by default; format:'dom' reveals visible controls and live attributes. Observed refs automatically route to their frame. */
|
|
106
134
|
async observe(opts = {}) {
|
|
135
|
+
if (opts.ref && opts.target)
|
|
136
|
+
throw new ActionError('invalid_target', 'Use target or ref, not both.');
|
|
137
|
+
if (opts.ref) {
|
|
138
|
+
opts = { ...opts, target: { ref: opts.ref, ...(opts.frame !== undefined && { frame: opts.frame }) } };
|
|
139
|
+
delete opts.ref;
|
|
140
|
+
delete opts.frame;
|
|
141
|
+
}
|
|
142
|
+
if (opts.target)
|
|
143
|
+
opts = { ...opts, target: this.routeTarget(opts.target) };
|
|
107
144
|
const mode = opts.mode ?? 'state';
|
|
108
145
|
return this.use(async (page) => {
|
|
109
146
|
if (opts.cursor !== undefined) {
|
|
@@ -128,8 +165,9 @@ export class Tab {
|
|
|
128
165
|
const base = frameSteps(opts.target?.frame ?? opts.frame);
|
|
129
166
|
const viewport = opts.ref || opts.target ? false : opts.viewport ?? (opts.format === 'dom');
|
|
130
167
|
const render = (capture, frame, ref) => {
|
|
168
|
+
this.rememberRefs(capture.dom ? capture.dom.entries.map(entry => entry.ref) : (capture.state ?? '').split('\n').flatMap(line => { const match = ARIA_REF_LINE.exec(line); return match ? [match[2]] : []; }), frame);
|
|
131
169
|
if (capture.dom)
|
|
132
|
-
return { dom: capture.dom };
|
|
170
|
+
return { dom: { ...capture.dom, ...(capture.dom.nextStart !== undefined && { next: { format: 'dom', ...(frame.length === base.length && opts.target ? { target: opts.target } : { frame }), start: capture.dom.nextStart, limit: opts.limit, viewport: !!viewport, includeFrames: false } }) } };
|
|
133
171
|
let text = compactAria(capture.state ?? '');
|
|
134
172
|
const key = `${this.id}:${JSON.stringify(frame)}:${viewport ? 'vp' : 'all'}:${ref ?? (frame.length === base.length ? selector ?? '' : '')}`;
|
|
135
173
|
const prev = this.ctx.state.lastObserve.get(key);
|
|
@@ -186,6 +224,10 @@ export class Tab {
|
|
|
186
224
|
}
|
|
187
225
|
}
|
|
188
226
|
if (mode === 'state' || mode === 'both') {
|
|
227
|
+
if (this.ctx.rt.hasFeature('webmcp')) {
|
|
228
|
+
const frame = frameSteps(opts.target?.frame ?? opts.frame);
|
|
229
|
+
out.webmcp = await pageToolsUpdate(page, this.ctx.state.webmcpCatalogs, `${this.id}:${JSON.stringify(frame)}`, frame);
|
|
230
|
+
}
|
|
189
231
|
this.ctx.state.observations.set(this.id, out);
|
|
190
232
|
const result = observationPage(out);
|
|
191
233
|
if (mode === 'both')
|
|
@@ -213,21 +255,26 @@ export class Tab {
|
|
|
213
255
|
}
|
|
214
256
|
}
|
|
215
257
|
async find(target) {
|
|
258
|
+
if (!('query' in target))
|
|
259
|
+
target = this.routeTarget(target);
|
|
216
260
|
return this.use(async (page) => {
|
|
261
|
+
const remember = (result) => { this.rememberRefs(result.entries.flatMap(entry => entry.ref ? [entry.ref] : []), frameSteps(target.frame)); return result; };
|
|
217
262
|
if ('query' in target)
|
|
218
|
-
return await page.pageCall('findByQuery', { query: target.query, limit: target.limit ?? 20 }, undefined, target.frame);
|
|
263
|
+
return remember(await page.pageCall('findByQuery', { query: target.query, limit: target.limit ?? 20 }, undefined, target.frame));
|
|
219
264
|
// a viewport point (screenshot coordinates) → the element there and its ancestors, as locators
|
|
220
265
|
if ('x' in target)
|
|
221
|
-
return await page.pageCall('elementAt', { x: target.x, y: target.y }, undefined, target.frame);
|
|
266
|
+
return remember(await page.pageCall('elementAt', { x: target.x, y: target.y }, undefined, target.frame));
|
|
222
267
|
// same engine and the same compiled selector as act: what find lists is exactly what act would resolve
|
|
223
268
|
const spec = target;
|
|
224
269
|
const selector = targetToSelector(spec);
|
|
225
270
|
if (!selector)
|
|
226
271
|
throw new ActionError('invalid_target', 'find needs a selector, an observed ref, a semantic locator (role/name/label/text/testid), or a point {x,y}', 'Pass one of: {ref} from observe, {selector}, {role,name}, {label}, {text}, {testid}, or {x,y}.');
|
|
227
|
-
return await page.pageCall('find', { selector, fallback: fallbackSelector(spec), limit: target.limit ?? 20 }, undefined, target.frame);
|
|
272
|
+
return remember(await page.pageCall('find', { selector, fallback: fallbackSelector(spec), limit: target.limit ?? 20 }, undefined, target.frame));
|
|
228
273
|
});
|
|
229
274
|
}
|
|
230
275
|
async read(opts = {}) {
|
|
276
|
+
if ('target' in opts)
|
|
277
|
+
opts = { ...opts, target: this.routeTarget(opts.target) };
|
|
231
278
|
return this.use(async (page) => {
|
|
232
279
|
if ('target' in opts) {
|
|
233
280
|
const selector = targetToSelector(opts.target);
|
|
@@ -236,6 +283,7 @@ export class Tab {
|
|
|
236
283
|
const result = await page.pageCall('readElement', { selector, fallback: fallbackSelector(opts.target), limit: 1 }, undefined, opts.target.frame);
|
|
237
284
|
if ('error' in result)
|
|
238
285
|
throw new ActionError(result.error.code, result.error.message, result.error.hint);
|
|
286
|
+
this.rememberRefs([result.ref], frameSteps(opts.target.frame));
|
|
239
287
|
return result;
|
|
240
288
|
}
|
|
241
289
|
if (opts.start !== undefined && !opts.readId)
|
|
@@ -243,12 +291,16 @@ export class Tab {
|
|
|
243
291
|
const r = await page.pageCall('readText', opts, undefined, opts.frame);
|
|
244
292
|
if (r.reason === 'stale')
|
|
245
293
|
throw new ActionError('stale_read', 'This page no longer has that text capture.', 'Call tab.read without readId to start a new capture.');
|
|
246
|
-
return r;
|
|
294
|
+
return { ...r, ...(r.nextStart !== undefined && { next: { ...opts, readId: r.readId, start: r.nextStart } }) };
|
|
247
295
|
});
|
|
248
296
|
}
|
|
249
297
|
/** wait + act in one call at the runtime edge: locate → wait actionable → hit-test → real input → settle. `method:'dom'` skips the mouse event. */
|
|
250
298
|
async act(opts) {
|
|
251
299
|
opts = { ...opts, ...checkActInput(opts) };
|
|
300
|
+
if (opts.target)
|
|
301
|
+
opts.target = this.routeTarget(opts.target);
|
|
302
|
+
if (opts.to)
|
|
303
|
+
opts.to = this.routeTarget(opts.to);
|
|
252
304
|
const { action } = opts;
|
|
253
305
|
return this.use(async (page) => {
|
|
254
306
|
try {
|
|
@@ -273,6 +325,8 @@ export class Tab {
|
|
|
273
325
|
const r = await page.act({ kind: action, target: opts.target, value: opts.value, files: opts.files, to: opts.to, direction: opts.direction, amount: opts.amount, timeoutMs: opts.timeoutMs, settleMs: opts.settleMs ?? 600, cursor: this.ctx.rt.cursorEnabled, ...(opts.method ? { method: opts.method } : {}) });
|
|
274
326
|
if (capture)
|
|
275
327
|
await this.harvest(page);
|
|
328
|
+
if (r.ref)
|
|
329
|
+
this.rememberRefs([r.ref], frameSteps(opts.target.frame));
|
|
276
330
|
const delivery = action === 'fill' || action === 'type' ? (r.verified ? 'applied' : 'dispatched') : r.method === 'dom' || ['check', 'uncheck', 'select', 'upload', 'focus'].includes(action) ? 'applied' : action === 'click' || action === 'dblclick' ? 'received' : 'dispatched';
|
|
277
331
|
const controlVerified = r.verified === true || (action === 'check' && r.checked === true) || (action === 'uncheck' && r.checked === false) || (action === 'select' && Array.isArray(r.selected) && r.selected.length > 0);
|
|
278
332
|
// Return the outcome and the fields needed to choose the next action.
|
|
@@ -289,7 +343,7 @@ export class Tab {
|
|
|
289
343
|
...(r.selected !== undefined ? { selected: r.selected } : {}),
|
|
290
344
|
...(r.files !== undefined ? { files: r.files } : {}),
|
|
291
345
|
...(r.openedTabs?.length ? { openedTabs: r.openedTabs.map(({ page, tabId, url, title, pending }) => ({ ...(page && { tab: page }), tabId, url, title, ...(pending && { pending }) })) } : {}),
|
|
292
|
-
...(r.download ? { download: r.download } : {}),
|
|
346
|
+
...(r.download ? { download: { ...r.download, tab: this.id } } : {}),
|
|
293
347
|
...(['click', 'fill', 'select'].includes(action) && r.method === 'dom' ? { method: 'dom' } : {}),
|
|
294
348
|
};
|
|
295
349
|
}
|
|
@@ -303,17 +357,32 @@ export class Tab {
|
|
|
303
357
|
}
|
|
304
358
|
/** WebMCP: tools the page itself registers via navigator.modelContext (page-provided tool source). */
|
|
305
359
|
webmcp = {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
360
|
+
/** List names/descriptions, or fetch one full schema by name. Scoped to the requested frame. */
|
|
361
|
+
list: async (options = {}) => this.use(async (page) => {
|
|
362
|
+
const tools = await pageTools(page, frameSteps(options.frame));
|
|
363
|
+
return options.name !== undefined ? tools.filter(tool => tool.name === options.name) : tools.map(({ name, description }) => ({ name, description }));
|
|
309
364
|
}),
|
|
310
|
-
call: async (name, input = {}) => this.use(async (
|
|
311
|
-
|
|
365
|
+
call: async (name, input = {}, options = {}) => this.use(async (page) => {
|
|
366
|
+
const script = `(async () => {
|
|
367
|
+
const name = ${JSON.stringify(name)}, input = ${JSON.stringify(input)};
|
|
368
|
+
const mc = navigator.modelContext || document.modelContext;
|
|
369
|
+
if (typeof mc?.executeTool === 'function') return mc.executeTool(name, input);
|
|
370
|
+
if (typeof navigator.modelContextTesting?.executeTool === 'function') return navigator.modelContextTesting.executeTool(name, JSON.stringify(input));
|
|
371
|
+
const tools = await mc?.getTools?.();
|
|
372
|
+
const tool = tools?.find(t => t.name === name);
|
|
373
|
+
if (typeof tool?.execute !== 'function') throw new Error('Page tool is unavailable; refresh webmcp.list.');
|
|
374
|
+
return tool.execute(input);
|
|
375
|
+
})()`;
|
|
376
|
+
return options.frame !== undefined ? page.evaluateInFrame(script, options.frame) : page.evaluate(script);
|
|
312
377
|
}),
|
|
313
378
|
};
|
|
314
379
|
/** Assert what the page must show now (polled up to timeoutMs). */
|
|
315
380
|
async expect(what, opts = {}) {
|
|
381
|
+
if (opts.timeoutMs !== undefined && (!Number.isFinite(opts.timeoutMs) || opts.timeoutMs < 0))
|
|
382
|
+
throw new ActionError('invalid_args', 'timeoutMs must be a finite non-negative number.');
|
|
316
383
|
checkExpect(what);
|
|
384
|
+
if (what.target)
|
|
385
|
+
what = { ...what, target: this.routeTarget(what.target) };
|
|
317
386
|
return this.use(async (page) => {
|
|
318
387
|
try {
|
|
319
388
|
return await page.expect(what, opts);
|
|
@@ -411,6 +480,10 @@ export class Tab {
|
|
|
411
480
|
async fetchJson(url, opts = {}) { return this.use((p) => p.fetchJson(url, opts)); }
|
|
412
481
|
async frames() { return this.use((p) => p.frames()); }
|
|
413
482
|
/** Wait for the page download begun after a tab.act cursor, then check Chrome's file state. */
|
|
414
|
-
async download(
|
|
483
|
+
async download(download, timeoutMs = 30_000) {
|
|
484
|
+
if (!download || download.tab !== this.id || !Number.isSafeInteger(download.afterSequence) || download.afterSequence < 0)
|
|
485
|
+
throw new ActionError('invalid_args', 'Pass the download object returned by an action on this tab.', 'Use await tab.download(result.download).');
|
|
486
|
+
return this.use((p) => p.waitForDownload(download.afterSequence, timeoutMs));
|
|
487
|
+
}
|
|
415
488
|
}
|
|
416
489
|
//# sourceMappingURL=tab.js.map
|