@mearl/native-host 2.21.0 → 3.0.0-beta.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.
Files changed (90) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +4 -0
  3. package/dist/THIRD_PARTY_NOTICES.txt +773 -0
  4. package/dist/agent/event-transport.d.ts +3 -0
  5. package/dist/agent/manager.d.ts +59 -0
  6. package/dist/agent/skill-manager.d.ts +52 -0
  7. package/dist/agent/workspace-directory.d.ts +4 -0
  8. package/dist/alipay-auth-code.d.ts +13 -0
  9. package/dist/analytics.d.ts +3 -0
  10. package/dist/app-profile-catalog.d.ts +11 -0
  11. package/dist/browser-artifacts.d.ts +26 -0
  12. package/dist/browser-inventory.d.ts +22 -0
  13. package/dist/browser-provider-coordinator.d.ts +24 -0
  14. package/dist/browser-provider.d.ts +30 -0
  15. package/dist/browser-registry.d.ts +93 -0
  16. package/dist/browser-socket-request.d.ts +5 -0
  17. package/dist/builtin-browser-providers.d.ts +8 -0
  18. package/dist/builtin-provider-options.d.ts +11 -0
  19. package/dist/capability-contracts.d.ts +73 -0
  20. package/dist/cdp-backend/action-registry.d.ts +36 -0
  21. package/dist/cdp-backend/app-profile-handlers.d.ts +62 -0
  22. package/dist/cdp-backend/browser-handlers.d.ts +6 -0
  23. package/dist/cdp-backend/buffers.d.ts +72 -0
  24. package/dist/cdp-backend/cdp-session.d.ts +102 -0
  25. package/dist/cdp-backend/cdp-utils.d.ts +41 -0
  26. package/dist/cdp-backend/client.d.ts +41 -0
  27. package/dist/cdp-backend/composite-handlers.d.ts +17 -0
  28. package/dist/cdp-backend/controlled-indicator.d.ts +18 -0
  29. package/dist/cdp-backend/cookie-handlers.d.ts +7 -0
  30. package/dist/cdp-backend/cookie-transfer.d.ts +37 -0
  31. package/dist/cdp-backend/device-shell.d.ts +26 -0
  32. package/dist/cdp-backend/discover.d.ts +29 -0
  33. package/dist/cdp-backend/domain-manager.d.ts +4 -0
  34. package/dist/cdp-backend/download-handlers.d.ts +9 -0
  35. package/dist/cdp-backend/fetch-interceptor.d.ts +26 -0
  36. package/dist/cdp-backend/frame-evaluation.d.ts +3 -0
  37. package/dist/cdp-backend/frame-tree.d.ts +16 -0
  38. package/dist/cdp-backend/handlers.d.ts +30 -0
  39. package/dist/cdp-backend/http-handlers.d.ts +33 -0
  40. package/dist/cdp-backend/interaction-handlers.d.ts +19 -0
  41. package/dist/cdp-backend/mock-handlers.d.ts +10 -0
  42. package/dist/cdp-backend/mtop-environment.d.ts +7 -0
  43. package/dist/cdp-backend/navigation-observer.d.ts +9 -0
  44. package/dist/cdp-backend/page-observer.d.ts +5 -0
  45. package/dist/cdp-backend/page-refs.d.ts +9 -0
  46. package/dist/cdp-backend/page-session-initializers.d.ts +6 -0
  47. package/dist/cdp-backend/plugin-pages.d.ts +12 -0
  48. package/dist/cdp-backend/release-control.d.ts +13 -0
  49. package/dist/cdp-backend/request-handlers.d.ts +10 -0
  50. package/dist/cdp-backend/rule-handlers.d.ts +11 -0
  51. package/dist/cdp-backend/send-request.d.ts +2 -0
  52. package/dist/cdp-backend/snapshot-handlers.d.ts +7 -0
  53. package/dist/cdp-backend/tab-handlers.d.ts +8 -0
  54. package/dist/cdp-backend/timezone-handlers.d.ts +4 -0
  55. package/dist/cloud-connector.d.ts +61 -0
  56. package/dist/config.d.ts +7 -0
  57. package/dist/control-session-manager.d.ts +30 -0
  58. package/dist/control-session.d.ts +31 -0
  59. package/dist/extension-file-transfer.d.ts +7 -0
  60. package/dist/extension-updater.d.ts +18 -0
  61. package/dist/host-updater.d.ts +39 -0
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.js +263 -353
  64. package/dist/install.d.ts +1 -0
  65. package/dist/internal-extension-actions.d.ts +10 -0
  66. package/dist/launcher.d.ts +1 -0
  67. package/dist/managed-browser.d.ts +61 -0
  68. package/dist/native-capability-services.d.ts +21 -0
  69. package/dist/node-capabilities.d.ts +20 -0
  70. package/dist/node-capabilities.js +4 -0
  71. package/dist/page-runtime-store.d.ts +27 -0
  72. package/dist/persistent-browser-record.d.ts +8 -0
  73. package/dist/plugin-host-services.d.ts +7 -0
  74. package/dist/plugin-page-results.d.ts +7 -0
  75. package/dist/plugin-task-host.js +22 -22
  76. package/dist/plugin-worker.js +20 -20
  77. package/dist/pluginModelSessionWorker.js +2 -2
  78. package/dist/preset-components.d.ts +35 -0
  79. package/dist/preset-installation.d.ts +19 -0
  80. package/dist/provider-control-host.d.ts +1 -0
  81. package/dist/provider-control.d.ts +28 -0
  82. package/dist/provider-request-timeout.d.ts +2 -0
  83. package/dist/runtimeArgs.d.ts +14 -0
  84. package/dist/sandbox-browser-access.d.ts +10 -0
  85. package/dist/send-request-file-utils.d.ts +14 -0
  86. package/dist/socketLines.d.ts +12 -0
  87. package/dist/toolbox-permissions.d.ts +8 -0
  88. package/dist/toolbox-service.d.ts +26 -0
  89. package/dist/version.d.ts +1 -0
  90. package/package.json +26 -16
@@ -0,0 +1,102 @@
1
+ /**
2
+ * CDP session manager — maintains browser-level and page-level CDP connections.
3
+ *
4
+ * - Browser client: connected to the browser's top-level WebSocket endpoint.
5
+ * Used for Target.* commands (list/open/close tabs).
6
+ * - Page sessions: per-target connections used for page interaction, screenshots,
7
+ * and buffered network/log/event collection.
8
+ */
9
+ import { type PageRuntimeOwner } from '../page-runtime-store.js';
10
+ import type { ResolvedEmulationConfig } from '@mearl/browser-core';
11
+ import { CdpClient, CdpChildSession } from './client.js';
12
+ import { type CdpBuffers } from './buffers.js';
13
+ export interface PageSession {
14
+ tabId: number;
15
+ client: CdpClient | CdpChildSession;
16
+ buffers: CdpBuffers;
17
+ targetId: string;
18
+ runtimeOwner?: PageRuntimeOwner;
19
+ url: string;
20
+ emulation?: {
21
+ mobile: boolean;
22
+ touch: boolean;
23
+ config?: ResolvedEmulationConfig;
24
+ deviceShell?: boolean;
25
+ splitScreen?: boolean;
26
+ };
27
+ }
28
+ export interface CdpSessionOptions {
29
+ port?: number;
30
+ userDataDir?: string;
31
+ endpointUrl?: string;
32
+ endpointResolver?: () => Promise<string>;
33
+ targetRegistryFile?: string;
34
+ }
35
+ export interface CdpAvailabilityProbe {
36
+ available: boolean;
37
+ error?: string;
38
+ }
39
+ export declare function isImplicitlySelectablePageUrl(url: string): boolean;
40
+ export declare class CdpSession {
41
+ readonly port: number;
42
+ readonly userDataDir?: string;
43
+ private readonly endpointUrl?;
44
+ private readonly endpointResolver?;
45
+ private readonly targetRegistryFile?;
46
+ private browserClient;
47
+ private runtimeBrowserOwner?;
48
+ private browserClientPromise;
49
+ private browserConnectedListeners;
50
+ private pageSessions;
51
+ private pageSessionPromises;
52
+ private pageSessionInitializers;
53
+ /** Virtual tabId counter → CDP targetId */
54
+ private tabIdMap;
55
+ private nextTabId;
56
+ constructor(options?: number | CdpSessionOptions);
57
+ getBrowserClient(): Promise<CdpClient>;
58
+ onBrowserConnected(listener: () => void): () => void;
59
+ browserSessionIdentity(): Promise<string>;
60
+ /**
61
+ * Get (or create) a page session.
62
+ *
63
+ * @param virtualTabId Numeric tabId returned by `tab_open` (optional).
64
+ * If omitted, connects to the first available page target.
65
+ */
66
+ getPageSession(virtualTabId?: number): Promise<PageSession>;
67
+ /** Register a newly opened target as a virtual tabId and return the numeric ID. */
68
+ registerTarget(targetId: string): Promise<number>;
69
+ /** Return the existing virtual tabId for a target, registering it when first discovered. */
70
+ ensureTargetRegistered(targetId: string): Promise<number>;
71
+ private restoreTargetRegistry;
72
+ private saveTargetRegistry;
73
+ addPageSessionInitializer(initializer: (session: PageSession) => Promise<void>): () => void;
74
+ attachOpenPageTargets(): Promise<void>;
75
+ private connectBrowserClient;
76
+ private createPageSession;
77
+ private getOrCreatePageSession;
78
+ private findTargetById;
79
+ private findDefaultPageTarget;
80
+ /** Effective port: from DevToolsActivePort file if present, else this.port */
81
+ private effectivePort;
82
+ /**
83
+ * Resolve the browser-level WebSocket URL.
84
+ * Priority: DevToolsActivePort file → HTTP /json/version → approval-mode WebSocket.
85
+ */
86
+ private resolveBrowserEndpoint;
87
+ /**
88
+ * Build a page-level WebSocket URL from a target ID.
89
+ * Used when HTTP /json is unavailable.
90
+ */
91
+ private pageWsUrl;
92
+ private isRemote;
93
+ private findTargetByIdViaCdp;
94
+ private findDefaultPageTargetViaCdp;
95
+ private fetchVersionInfo;
96
+ probeAvailability(): Promise<CdpAvailabilityProbe>;
97
+ isAvailable(): Promise<boolean>;
98
+ hasActiveConnections(): boolean;
99
+ listOpenPageSessions(): PageSession[];
100
+ listRegisteredTabIds(targetIds?: ReadonlySet<string>): number[];
101
+ close(): void;
102
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Shared utilities for CDP backend handlers.
3
+ *
4
+ * Contains: HTTP helper (nodeFetch), cookie utilities, page-load waiters,
5
+ * viewport helpers, and serialized function sources for page injection.
6
+ */
7
+ import { type PageClickPointerType, type PageDragPoint, type PageDragPointerType } from '@mearl/browser-core';
8
+ import type { PageSession } from './cdp-session.js';
9
+ export declare const TYPE_INTO_ELEMENT_SRC: string;
10
+ export declare const CLICK_ELEMENT_VIA_JS_SRC: string;
11
+ export declare const GET_CLICK_COORDS_FROM_NODE_SRC: string;
12
+ export declare function readCdpCurrentUrl(session: PageSession, action: string): Promise<string>;
13
+ export declare function nodeFetch(urlStr: string, options?: {
14
+ method?: string;
15
+ headers?: Record<string, string>;
16
+ body?: string | Uint8Array;
17
+ timeoutMs?: number;
18
+ }): Promise<{
19
+ status: number;
20
+ statusText: string;
21
+ headers: Record<string, string>;
22
+ body: string;
23
+ bodyBuffer: Buffer;
24
+ }>;
25
+ export declare function getCookiesForUrl(session: PageSession, targetUrl: string): Promise<Map<string, string>>;
26
+ export declare function buildMultipartFormBody(fields: Record<string, string>): {
27
+ contentType: string;
28
+ body: string;
29
+ };
30
+ export declare function waitForPageLoad(session: PageSession, timeoutMs: number, options?: {
31
+ probeReadyState?: boolean;
32
+ }): Promise<void>;
33
+ export declare function toCdpInputPoint(session: PageSession, x: number, y: number): Promise<{
34
+ x: number;
35
+ y: number;
36
+ }>;
37
+ export declare function dispatchCdpClick(session: PageSession, x: number, y: number, pointerType: PageClickPointerType): Promise<void>;
38
+ export declare function dispatchCdpDrag(session: PageSession, from: PageDragPoint, to: PageDragPoint, pointerType: PageDragPointerType, durationMs: number): Promise<{
39
+ steps: number;
40
+ }>;
41
+ export declare function resolveBackendNodeObjectId(session: PageSession, backendNodeId: number): Promise<string>;
@@ -0,0 +1,41 @@
1
+ /** WebSocket CDP client shared by local and remote browser sessions. */
2
+ type EventCallback = (params: any) => void;
3
+ export declare class CdpChildSession {
4
+ private readonly parent;
5
+ readonly sessionId: string;
6
+ getDefaultExecutionContexts(): ReadonlyMap<string, number>;
7
+ constructor(parent: CdpClient, sessionId: string);
8
+ sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
9
+ on(method: string, callback: EventCallback): () => void;
10
+ createChildSession(sessionId: string): CdpChildSession;
11
+ get closed(): boolean;
12
+ close(): void;
13
+ }
14
+ export declare class CdpClient {
15
+ private readonly socket;
16
+ /** Stable across reconnects to one browser endpoint without exposing its credentials. */
17
+ get identity(): string;
18
+ private nextId;
19
+ private pending;
20
+ private eventHandlers;
21
+ private sessionEventHandlers;
22
+ private _closed;
23
+ private defaultContexts;
24
+ /** Contexts emitted before a page subsystem starts listening remain available for reconnection. */
25
+ getDefaultExecutionContexts(sessionId?: string): ReadonlyMap<string, number>;
26
+ private constructor();
27
+ static connect(wsUrl: string, handshakeTimeoutMs?: number): Promise<CdpClient>;
28
+ createChildSession(sessionId: string): CdpChildSession;
29
+ sendCommandInSession(sessionId: string, method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
30
+ onSession(sessionId: string, method: string, callback: EventCallback): () => void;
31
+ sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
32
+ on(method: string, callback: EventCallback): () => void;
33
+ close(): void;
34
+ get closed(): boolean;
35
+ private sendRequest;
36
+ private consumeMessage;
37
+ private handleMessage;
38
+ private handleClosed;
39
+ private rejectPending;
40
+ }
41
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * CDP composite action handlers.
3
+ *
4
+ * Provides `run_actions` — sequential batch execution of multiple actions
5
+ * within a single request, sharing the same CDP session — and the observed
6
+ * page-action wrapper that gives page interaction actions their default
7
+ * built-in observation.
8
+ */
9
+ import type { CdpSession } from './cdp-session.js';
10
+ import { type ControlSource, type PageActAction, type RunActionsParams } from '@mearl/browser-core';
11
+ export declare function cdpRunActions(session: CdpSession, data: RunActionsParams, controlSource?: ControlSource): Promise<any>;
12
+ /**
13
+ * Runs a page interaction action with built-in observation. Diagnostics are
14
+ * collected only when the caller requests them.
15
+ * `run_actions` stays lightweight and never enters this wrapper.
16
+ */
17
+ export declare function cdpObservedPageAction(session: CdpSession, action: PageActAction, data: any, controlSource?: ControlSource): Promise<any>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * CDP 模式的受控页面视觉标识。
3
+ *
4
+ * 与扩展模式共享同一套 Mearl favicon 变体,本地操作显示绿色圆点角标,云端操作
5
+ * 显示紫色云朵角标。图标通过 data URL 内联到新文档脚本,不依赖扩展资源或网络。
6
+ *
7
+ * 注入通过 Page.addScriptToEvaluateOnNewDocument + runImmediately 完成:脚本在
8
+ * PageSession 存续期内跨导航生效;控制来源变化时替换脚本并立即更新当前文档。
9
+ */
10
+ import { type ControlSource } from '@mearl/browser-core';
11
+ import type { PageSession } from './cdp-session.js';
12
+ /**
13
+ * 确保受控标识已注入到该 page session。相同来源幂等;来源变化时替换跨导航脚本,
14
+ * runImmediately 同步更新当前文档。任何异常都不阻断 agent 动作本身。
15
+ */
16
+ export declare function ensureControlledIndicator(session: PageSession, controlSource?: ControlSource): Promise<void>;
17
+ /** browser_release 使用:停止跨导航注入并恢复当前文档的 favicon。 */
18
+ export declare function releaseControlledIndicator(session: PageSession): Promise<void>;
@@ -0,0 +1,7 @@
1
+ /** Read or write one named cookie in the default browser context or a selected tab's context. */
2
+ import { type ControlSource, type GetCookieParams, type SetCookieParams } from '@mearl/browser-core';
3
+ import type { CdpSession, PageSession } from './cdp-session.js';
4
+ export declare function cdpSetCookie(session: PageSession, data: SetCookieParams): Promise<any>;
5
+ export declare function cdpGetCookie(session: PageSession, data: GetCookieParams): Promise<any>;
6
+ export declare function cdpGetBrowserCookie(session: CdpSession, data: GetCookieParams): Promise<any>;
7
+ export declare function cdpSetBrowserCookie(session: CdpSession, data: SetCookieParams, controlSource?: ControlSource): Promise<any>;
@@ -0,0 +1,37 @@
1
+ /** Cookie export/import helpers for copying selected domains between CDP browsers. */
2
+ import type { BuiltinBrowserLaunchOptions } from '../builtin-provider-options.js';
3
+ import type { CdpSession } from './cdp-session.js';
4
+ export interface TransferableCookie {
5
+ name: string;
6
+ value: string;
7
+ domain: string;
8
+ path: string;
9
+ secure?: boolean;
10
+ httpOnly?: boolean;
11
+ sameSite?: 'Strict' | 'Lax' | 'None';
12
+ expires?: number;
13
+ priority?: 'Low' | 'Medium' | 'High';
14
+ sameParty?: boolean;
15
+ sourceScheme?: 'Unset' | 'NonSecure' | 'Secure';
16
+ sourcePort?: number;
17
+ partitionKey?: {
18
+ topLevelSite: string;
19
+ hasCrossSiteAncestor?: boolean;
20
+ };
21
+ }
22
+ interface CookieCommandClient {
23
+ sendCommand(method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
24
+ }
25
+ export declare function normalizeCookieDomain(input: string): string;
26
+ export declare function normalizeCookieDomains(inputs: unknown): string[];
27
+ export interface CookieCopyPlan {
28
+ domains: string[];
29
+ select(cookies: TransferableCookie[]): TransferableCookie[];
30
+ }
31
+ /** Explicit domains use the generic transport; named scopes belong to installed capabilities. */
32
+ export declare function resolveCookieCopyPlan(input: BuiltinBrowserLaunchOptions['copyCookieDomains']): CookieCopyPlan;
33
+ export declare function cookieMatchesDomain(cookieDomain: string, requestedDomain: string): boolean;
34
+ export declare function cdpExportCookies(session: CdpSession, domains: string[]): Promise<TransferableCookie[]>;
35
+ export declare function cdpImportCookies(session: CdpSession, cookies: TransferableCookie[]): Promise<number>;
36
+ export declare function cdpImportCookiesWithClient(browser: CookieCommandClient, cookies: TransferableCookie[]): Promise<number>;
37
+ export {};
@@ -0,0 +1,26 @@
1
+ import { type WebViewNavigationRequest, type WebViewDocumentResponse, type AppLayerUrlProxyConfig, type ResolvedEmulationConfig } from '@mearl/browser-core';
2
+ import type { CdpChildSession, CdpClient } from './client.js';
3
+ import type { PageSession } from './cdp-session.js';
4
+ export type CdpDeviceShellCommandClient = CdpClient | CdpChildSession;
5
+ interface ApplyCdpDeviceShellOptions {
6
+ rootContainerManagedByApp?: boolean;
7
+ }
8
+ export declare function setCdpDeviceShellNavigationProxy(session: PageSession, proxy?: AppLayerUrlProxyConfig): void;
9
+ /** 响应覆盖仍通过根文档交付,避免 Mock HTML 再次导航到业务地址。 */
10
+ export declare function fulfillCdpDeviceShellDocument(session: PageSession, params: WebViewNavigationRequest, response: WebViewDocumentResponse): Promise<boolean>;
11
+ export declare function isCdpDeviceShellActive(session: PageSession): boolean;
12
+ export declare function setCdpDeviceShellChildEnvironmentManagedByApp(session: PageSession, managed: boolean): void;
13
+ export declare function resolveCdpDeviceShellPageEndpoint(session: PageSession): Promise<{
14
+ client: CdpDeviceShellCommandClient;
15
+ frameId?: string;
16
+ url?: string;
17
+ }>;
18
+ export declare function sendCdpDeviceShellPageCommand(session: PageSession, method: string, params?: Record<string, any>, timeoutMs?: number): Promise<any>;
19
+ export declare function getCdpDeviceShellInputOffset(session: PageSession): Promise<{
20
+ x: number;
21
+ y: number;
22
+ }>;
23
+ export declare function applyCdpDeviceShell(session: PageSession, emulation: ResolvedEmulationConfig, options?: ApplyCdpDeviceShellOptions): Promise<boolean>;
24
+ export declare function clearCdpDeviceShell(session: PageSession): Promise<boolean>;
25
+ export declare function waitForCdpDeviceShellLoad(session: PageSession, timeoutMs?: number): Promise<void>;
26
+ export {};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * CDP target discovery.
3
+ *
4
+ * Strategy (in order):
5
+ * 1. Read Chrome's DevToolsActivePort file — written by Chrome when remote
6
+ * debugging is enabled (including via chrome://inspect/#remote-debugging).
7
+ * Contains the actual port and browser WebSocket path.
8
+ * 2. Fall back to HTTP /json REST API on the given port (requires Chrome
9
+ * launched with --remote-debugging-port).
10
+ * Chrome's approval-mode server also accepts /devtools/browser directly.
11
+ */
12
+ export interface CdpTarget {
13
+ id: string;
14
+ title: string;
15
+ type: string;
16
+ url: string;
17
+ webSocketDebuggerUrl: string;
18
+ faviconUrl?: string;
19
+ }
20
+ /**
21
+ * Read Chrome's DevToolsActivePort file.
22
+ * Returns { port, browserWsPath } or null if unavailable. Reports read failures
23
+ * other than a missing file to callers that need discovery diagnostics.
24
+ */
25
+ export declare function readDevToolsActivePort(userDataDir?: string, onError?: (error: Error) => void): {
26
+ port: number;
27
+ browserWsPath: string;
28
+ } | null;
29
+ export declare function discoverTargets(port?: number): Promise<CdpTarget[]>;
@@ -0,0 +1,4 @@
1
+ import type { CdpChildSession, CdpClient } from './client.js';
2
+ type DomainClient = CdpClient | CdpChildSession;
3
+ export declare function ensureCdpDomain(client: DomainClient, domain: string, params?: Record<string, unknown>): Promise<void>;
4
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { PageDownloadParams } from '@mearl/browser-core';
2
+ import type { CdpSession } from './cdp-session.js';
3
+ export declare function captureCdpDownload(session: CdpSession, data: PageDownloadParams, isolated: boolean, trigger: () => Promise<unknown>): Promise<{
4
+ filename: string;
5
+ filePath: string;
6
+ action: unknown;
7
+ owned: boolean;
8
+ directory: string | undefined;
9
+ }>;
@@ -0,0 +1,26 @@
1
+ /** Shared CDP Fetch-domain dispatcher for features that pause network requests. */
2
+ import type { PageSession } from './cdp-session.js';
3
+ export interface CdpFetchHeader {
4
+ name: string;
5
+ value: string;
6
+ }
7
+ export interface CdpFetchPauseContext {
8
+ session: PageSession;
9
+ params: any;
10
+ isResponseStage: boolean;
11
+ }
12
+ export interface CdpFetchPattern {
13
+ urlPattern: string;
14
+ requestStage: 'Request' | 'Response';
15
+ resourceType?: string;
16
+ }
17
+ export type CdpFetchPauseHandler = (context: CdpFetchPauseContext) => Promise<boolean> | boolean;
18
+ /** 注册一个有序 Fetch 处理器;同一 page session 只启用一个 CDP Fetch 监听器。 */
19
+ export declare function registerCdpFetchPauseHandler(session: PageSession, key: string, priority: number, handler: CdpFetchPauseHandler, patterns?: CdpFetchPattern[]): Promise<void>;
20
+ /** 移除一个处理器;没有其它功能依赖 Fetch 时恢复 CDP 默认网络行为。 */
21
+ export declare function unregisterCdpFetchPauseHandler(session: PageSession, key: string): Promise<void>;
22
+ /** browser_release 使用:丢弃指定会话注册表;底层 CDP 连接随后关闭并恢复默认网络行为。 */
23
+ export declare function clearCdpFetchInterceptionState(sessions?: Iterable<PageSession>): void;
24
+ export declare function ensureCorsHeaders(headers: CdpFetchHeader[], request: {
25
+ headers?: Record<string, string>;
26
+ }): CdpFetchHeader[];
@@ -0,0 +1,3 @@
1
+ import type { PageSession } from './cdp-session.js';
2
+ /** A temporary session enumerates main-world contexts without resetting ongoing page capture. */
3
+ export declare function evaluateCdpFrame(session: PageSession, frameId: string, params: Record<string, unknown>): Promise<any>;
@@ -0,0 +1,16 @@
1
+ import type { CdpChildSession } from './client.js';
2
+ import type { PageSession } from './cdp-session.js';
3
+ interface FrameEntry {
4
+ targetId: string;
5
+ frame: {
6
+ frameId: string;
7
+ parentFrameId: string | null;
8
+ url: string;
9
+ name: string;
10
+ isMainFrame: boolean;
11
+ };
12
+ }
13
+ export declare function withCdpFrameTarget<T>(session: PageSession, targetId: string, callback: (client: CdpChildSession) => Promise<T>): Promise<T>;
14
+ /** OOPIF trees belong to separate targets; parent relationships keep discovery within this page. */
15
+ export declare function readCdpFrameEntries(session: PageSession, requestedFrameId?: string): Promise<FrameEntry[]>;
16
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * CDP backend action handlers — re-export hub.
3
+ *
4
+ * All handler implementations live in dedicated sub-modules.
5
+ * Importing this file triggers side-effect registrations in the action registry.
6
+ */
7
+ import './request-handlers.js';
8
+ import './mock-handlers.js';
9
+ import './http-handlers.js';
10
+ import './browser-handlers.js';
11
+ import './rule-handlers.js';
12
+ import './tab-handlers.js';
13
+ import './interaction-handlers.js';
14
+ import './app-profile-handlers.js';
15
+ import './timezone-handlers.js';
16
+ import './cookie-handlers.js';
17
+ import './snapshot-handlers.js';
18
+ import './composite-handlers.js';
19
+ export { dispatchCdpAction, getRegisteredActionNames } from './action-registry.js';
20
+ export { cdpGetRequests, cdpGetLogs, cdpGetEvents } from './request-handlers.js';
21
+ export { cdpSetMock, cdpGetMocks } from './mock-handlers.js';
22
+ export { cdpSendRequest, cdpSendMtopRequest } from './http-handlers.js';
23
+ export { cdpPageScreenshot } from './browser-handlers.js';
24
+ export { cdpTabOpen, cdpTabClose, cdpTabList } from './tab-handlers.js';
25
+ export { cdpPageClick, cdpPageType, cdpPageScroll, cdpPageInspect, cdpPageEval, cdpPagePress, cdpPageWait, cdpPageNavigate, cdpPageUpload, cdpSetDeviceEmulation, } from './interaction-handlers.js';
26
+ export { cdpSetAppProfile } from './app-profile-handlers.js';
27
+ export { cdpPageSnapshot, cdpPageFrames } from './snapshot-handlers.js';
28
+ export { cdpRunActions, cdpObservedPageAction } from './composite-handlers.js';
29
+ export { cdpSetTimezone } from './timezone-handlers.js';
30
+ export { cdpGetCookie, cdpSetCookie } from './cookie-handlers.js';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * CDP HTTP proxy / MTOP request / API schema handlers.
3
+ */
4
+ import type { SendMtopRequestParams, SendRequestParams } from '@mearl/browser-core';
5
+ import type { PageSession } from './cdp-session.js';
6
+ export interface CdpMtopStreamRequestMetadata {
7
+ method: 'GET' | 'POST';
8
+ url: string;
9
+ requestHeaders: Array<{
10
+ name: string;
11
+ value: string;
12
+ }>;
13
+ }
14
+ export interface CdpMtopStreamResponseMetadata {
15
+ status: number;
16
+ statusText: string;
17
+ responseHeaders: Array<{
18
+ name: string;
19
+ value: string;
20
+ }>;
21
+ }
22
+ export interface CdpMtopStreamCallbacks {
23
+ onRequestPrepared?: (metadata: CdpMtopStreamRequestMetadata) => void | Promise<void>;
24
+ onResponse?: (metadata: CdpMtopStreamResponseMetadata) => void | Promise<void>;
25
+ onReceive: (data: unknown) => void | Promise<void>;
26
+ }
27
+ export declare function cdpSendRequest(session: PageSession, data: SendRequestParams): Promise<any>;
28
+ export declare function cdpSendMtopRequest(session: PageSession, data: SendMtopRequestParams): Promise<any>;
29
+ export declare function cdpSendMtopStreamRequest(session: PageSession, data: SendMtopRequestParams, callbacks: CdpMtopStreamCallbacks): Promise<{
30
+ success: true;
31
+ response: unknown;
32
+ requestData: unknown;
33
+ }>;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * CDP page interaction handlers.
3
+ *
4
+ * Covers: click, type, scroll, eval, press, wait, navigate, upload, device emulation.
5
+ */
6
+ import { type PageClickParams, type PageDragParams, type PageDragResultData, type PageEvalParams, type PageHoverParams, type PageInspectParams, type PageInspectResult, type PageNavigateParams, type PagePressParams, type PageScrollParams, type PageTypeParams, type PageUploadParams, type PageWaitParams, type SetDeviceEmulationParams } from '@mearl/browser-core';
7
+ import type { PageSession } from './cdp-session.js';
8
+ export declare function cdpPageClick(session: PageSession, data: PageClickParams): Promise<any>;
9
+ export declare function cdpPageDrag(session: PageSession, data: PageDragParams): Promise<PageDragResultData>;
10
+ export declare function cdpPageType(session: PageSession, data: PageTypeParams): Promise<any>;
11
+ export declare function cdpPageScroll(session: PageSession, data: PageScrollParams): Promise<any>;
12
+ export declare function cdpPageEval(session: PageSession, data: PageEvalParams): Promise<any>;
13
+ export declare function cdpPagePress(session: PageSession, data: PagePressParams): Promise<any>;
14
+ export declare function cdpPageWait(session: PageSession, data: PageWaitParams): Promise<any>;
15
+ export declare function cdpPageNavigate(session: PageSession, data: PageNavigateParams): Promise<any>;
16
+ export declare function cdpPageUpload(session: PageSession, data: PageUploadParams): Promise<any>;
17
+ export declare function cdpSetDeviceEmulation(session: PageSession, data: SetDeviceEmulationParams): Promise<any>;
18
+ export declare function cdpPageHover(session: PageSession, data: PageHoverParams): Promise<any>;
19
+ export declare function cdpPageInspect(session: PageSession, data: PageInspectParams): Promise<PageInspectResult>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CDP mock interception handlers.
3
+ */
4
+ import { type GetMocksParams, type SetMockParams } from '@mearl/browser-core';
5
+ import type { PageSession } from './cdp-session.js';
6
+ export declare function clearCdpPageMocks(session: PageSession): void;
7
+ /** browser_release 使用:丢弃所有依赖当前 CDP 会话的 mock 状态。 */
8
+ export declare function clearCdpMockState(): void;
9
+ export declare function cdpSetMock(session: PageSession, data: SetMockParams): Promise<any>;
10
+ export declare function cdpGetMocks(session: PageSession, data: GetMocksParams): any;
@@ -0,0 +1,7 @@
1
+ /** Per-tab MTop gateway environment switching for direct CDP browsers. */
2
+ import type { MtopEnvironment, MtopEnvironmentTarget } from '@mearl/browser-core';
3
+ import type { PageSession } from './cdp-session.js';
4
+ export declare function setCdpMtopEnvironment(session: PageSession, target: MtopEnvironment): Promise<void>;
5
+ export declare function getCdpMtopEnvironment(session: PageSession): MtopEnvironmentTarget | undefined;
6
+ /** browser_release 使用:清除指定 tab 的 MTop 环境选择。 */
7
+ export declare function clearCdpMtopEnvironmentState(sessions?: Iterable<PageSession>): void;
@@ -0,0 +1,9 @@
1
+ import { type PageActNavigationObserver } from '@mearl/browser-core';
2
+ import type { CdpSession, PageSession } from './cdp-session.js';
3
+ export declare function startCdpNavigationObserver(cdpSession: CdpSession, pageSession: PageSession, urlBefore: string, options?: {
4
+ trackNetwork?: boolean;
5
+ networkIdleMs?: number;
6
+ contentReadyAfterMs?: number;
7
+ trackOpenedTabs?: boolean;
8
+ sourceTabId?: number;
9
+ }): Promise<PageActNavigationObserver>;
@@ -0,0 +1,5 @@
1
+ import { type PageChangeSet, type PageNavigationChange, type PageObservationCheckpoint, type PageObservationWaitOptions } from '@mearl/browser-core';
2
+ import type { PageSession } from './cdp-session.js';
3
+ export declare function startPageObservation(session: PageSession): Promise<PageObservationCheckpoint>;
4
+ export declare function finishPageObservation(session: PageSession, checkpoint: PageObservationCheckpoint, options?: PageObservationWaitOptions): Promise<PageChangeSet | PageNavigationChange>;
5
+ export declare function disposePageObservation(session: PageSession): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { BackendNodeRefRegistry, type BackendNodeSnapshotRefAllocator, type PageChangeSet, type PageEffectRefEntry } from '@mearl/browser-core';
2
+ import type { PageSession } from './cdp-session.js';
3
+ export type PageRefEntry = PageEffectRefEntry;
4
+ export declare function getPageRefRegistry(session: PageSession): BackendNodeRefRegistry<PageRefEntry>;
5
+ export declare function beginPageSnapshotRefs(session: PageSession): BackendNodeSnapshotRefAllocator<PageRefEntry>;
6
+ export declare function resolvePageRef(session: PageSession, ref: string): PageRefEntry | undefined;
7
+ export declare function deletePageRef(session: PageSession, ref: string): void;
8
+ export declare function clearPageRefsForNavigation(session: PageSession): void;
9
+ export declare function enrichCdpPageChangeSetWithRefs(session: PageSession, observation: PageChangeSet): Promise<PageChangeSet>;
@@ -0,0 +1,6 @@
1
+ import type { PageSession } from './cdp-session.js';
2
+ type PageSessionInitializer = (session: PageSession) => Promise<void>;
3
+ /** Register state that must be reconstructed whenever a daemon attaches to a page target. */
4
+ export declare function registerPageSessionInitializer(initializer: PageSessionInitializer): void;
5
+ export declare function initializePageSession(session: PageSession): Promise<void>;
6
+ export {};
@@ -0,0 +1,12 @@
1
+ import { PluginPageRuntimeHost, type PluginPageNativeCall } from '@mearl/browser-core';
2
+ import type { CdpSession } from './cdp-session.js';
3
+ /** Session values belong to one browser lifetime; persistent activation rules outlive it. */
4
+ export declare function pruneCdpSessionStorage(storageFile: string, currentIdentity?: string): void;
5
+ /** Port-shaped bridge keeps the document runtime independent of Chrome extension APIs. */
6
+ export declare function installCdpPluginPageBridge(binding: string): void;
7
+ export declare class CdpPluginPageHost extends PluginPageRuntimeHost {
8
+ constructor(cdp: CdpSession, native: PluginPageNativeCall, options: {
9
+ browserId: string;
10
+ storageFile?: string;
11
+ });
12
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Browser-level CDP control release.
3
+ *
4
+ * Closes Mearl's browser/page WebSocket sessions while keeping Chrome and all
5
+ * targets alive. A later browser action may create a fresh CdpSession.
6
+ */
7
+ import type { CdpSession } from './cdp-session.js';
8
+ export interface CdpReleaseResult {
9
+ released: boolean;
10
+ hadActiveControl: boolean;
11
+ affectedTabIds: number[];
12
+ }
13
+ export declare function releaseCdpControl(session: CdpSession): Promise<CdpReleaseResult>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CDP request/log/event buffer query handlers.
3
+ */
4
+ import type { CaptureCheckpointParams, GetEventsParams, GetLogsParams, GetRequestsParams, PageDiagnosticsOptions } from '@mearl/browser-core';
5
+ import type { PageSession } from './cdp-session.js';
6
+ export declare function cdpGetRequests(session: PageSession, data: GetRequestsParams): Promise<any>;
7
+ export declare function cdpGetLogs(session: PageSession, data: GetLogsParams): Promise<any>;
8
+ export declare function cdpCaptureCheckpoint(session: PageSession, _data: CaptureCheckpointParams): Promise<any>;
9
+ export declare function collectCdpPageDiagnostics(session: PageSession, after: string, diagnostics: PageDiagnosticsOptions): Promise<Record<string, any>>;
10
+ export declare function cdpGetEvents(session: PageSession, data: GetEventsParams): Promise<any>;
@@ -0,0 +1,11 @@
1
+ /** CDP request-header rules, scoped to the current browser control session. */
2
+ import type { RulesResult, SetRuleParams } from '@mearl/browser-core';
3
+ import type { CdpSession } from './cdp-session.js';
4
+ export declare function cdpSetRule(session: CdpSession, data: SetRuleParams): Promise<{
5
+ success: boolean;
6
+ ruleId: number;
7
+ affectedCount: number;
8
+ message: string;
9
+ }>;
10
+ export declare function cdpGetRules(session: CdpSession): Promise<RulesResult>;
11
+ export declare function clearCdpRuleState(session: CdpSession): void;
@@ -0,0 +1,2 @@
1
+ import { type SendRequestParams } from '@mearl/browser-core';
2
+ export declare function executeNodeSendRequest(data: SendRequestParams, cookieMap?: Map<string, string>): Promise<any>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * CDP accessibility tree snapshot and frame handlers.
3
+ */
4
+ import { type PageFramesParams, type PageSnapshotParams } from '@mearl/browser-core';
5
+ import type { PageSession } from './cdp-session.js';
6
+ export declare function cdpPageSnapshot(session: PageSession, data: PageSnapshotParams): Promise<any>;
7
+ export declare function cdpPageFrames(session: PageSession, _data: PageFramesParams): Promise<any>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * CDP tab management handlers.
3
+ */
4
+ import { type ControlSource, type TabCloseParams, type TabOpenParams } from '@mearl/browser-core';
5
+ import { type CdpSession } from './cdp-session.js';
6
+ export declare function cdpTabOpen(session: CdpSession, data: TabOpenParams, controlSource?: ControlSource): Promise<any>;
7
+ export declare function cdpTabClose(session: CdpSession, data: TabCloseParams): Promise<any>;
8
+ export declare function cdpTabList(session: CdpSession, _data: any): Promise<any>;
@@ -0,0 +1,4 @@
1
+ /** CDP timezone override handler. */
2
+ import type { SetTimezoneParams } from '@mearl/browser-core';
3
+ import type { PageSession } from './cdp-session.js';
4
+ export declare function cdpSetTimezone(session: PageSession, data: SetTimezoneParams): Promise<any>;