@xbrowser/cli 1.29.0 → 1.30.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 (36) hide show
  1. package/README.md +2 -2
  2. package/dist/{browser-XD3IOU5I.js → browser-6PFTHZI3.js} +2 -2
  3. package/dist/{browser-2K3XYAKM.js → browser-I2NLJN2A.js} +1 -1
  4. package/dist/{browser-OTEMG5NL.js → browser-KOUA4ZDA.js} +2 -2
  5. package/dist/{cdp-driver-AAS55KT2.js → cdp-driver-3ETNFQA4.js} +1 -1
  6. package/dist/{cdp-driver-XTPY7EXP.js → cdp-driver-U7HDQMQ5.js} +257 -19
  7. package/dist/{cdp-driver-O5I7SJ24.js → cdp-driver-WBFJNOLD.js} +1 -1
  8. package/dist/{chunk-SCYBNSOG.js → chunk-3K57RYVC.js} +378 -115
  9. package/dist/{chunk-FNXA6FDM.js → chunk-BND5O5KC.js} +2 -1
  10. package/dist/{chunk-P33R7F2D.js → chunk-BOZTIIBT.js} +30 -45
  11. package/dist/{chunk-GDKKVT2P.js → chunk-KPTD3SNJ.js} +379 -116
  12. package/dist/{chunk-CO2ZVOVT.js → chunk-NINETOM4.js} +30 -45
  13. package/dist/{chunk-SOPN4XDK.js → chunk-O5PASNI7.js} +2 -1
  14. package/dist/{chunk-NQPXZ74W.js → chunk-OCECE22C.js} +257 -19
  15. package/dist/{chunk-LFSLNHW5.js → chunk-OSIDUT4H.js} +286 -63
  16. package/dist/{chunk-HBMEFSTB.js → chunk-QCV2PI7U.js} +2 -1
  17. package/dist/{chunk-UZ6XPUBD.js → chunk-RMYKVZIZ.js} +78 -0
  18. package/dist/{chunk-N5XTLNKS.js → chunk-SPNWUUHA.js} +257 -19
  19. package/dist/{chunk-PGKV24QN.js → chunk-TBJUSUKF.js} +1 -1
  20. package/dist/{chunk-FCPVQFTQ.js → chunk-VYTQLZAX.js} +78 -0
  21. package/dist/cli.js +45 -16
  22. package/dist/daemon-main.js +581 -157
  23. package/dist/{human-interaction-CTZ4IWXJ.js → human-interaction-ISMMOJOK.js} +2 -2
  24. package/dist/{human-interaction-HJCK45SL.js → human-interaction-STTZZZ5N.js} +1 -1
  25. package/dist/{human-interaction-V3VDGHHI.js → human-interaction-UXFYV7DU.js} +1 -1
  26. package/dist/index.d.ts +106 -12
  27. package/dist/index.js +195 -46
  28. package/dist/{recovery-EBKORYEU.js → recovery-JFGV3DBX.js} +1 -1
  29. package/dist/{recovery-5C4FBA5O.js → recovery-ORHJSBDN.js} +2 -2
  30. package/dist/{recovery-IMZUGWSS.js → recovery-XDKN63O5.js} +1 -1
  31. package/dist/{server-ZTI2K5YJ.js → server-TG47W7MV.js} +3 -3
  32. package/dist/{server-LNZTDAKT.js → server-U3YAX5MJ.js} +2 -2
  33. package/dist/{session-recorder-DF2YGH2E.js → session-recorder-N7VEKJVW.js} +1 -1
  34. package/dist/{session-recorder-R3GDGXLJ.js → session-recorder-RUNQOJ7T.js} +1 -1
  35. package/dist/{session-replayer-CLTZ2URU.js → session-replayer-XLWQ47BB.js} +1 -1
  36. package/package.json +4 -1
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  HumanInteractionManager
3
- } from "./chunk-PGKV24QN.js";
4
- import "./chunk-HBMEFSTB.js";
3
+ } from "./chunk-TBJUSUKF.js";
4
+ import "./chunk-QCV2PI7U.js";
5
5
  import "./chunk-KFQGP6VL.js";
6
6
  export {
7
7
  HumanInteractionManager
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  HumanInteractionManager
3
- } from "./chunk-SOPN4XDK.js";
3
+ } from "./chunk-O5PASNI7.js";
4
4
  import "./chunk-ZTHE5RBZ.js";
5
5
  import "./chunk-KFQGP6VL.js";
6
6
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  HumanInteractionManager
3
- } from "./chunk-FNXA6FDM.js";
3
+ } from "./chunk-BND5O5KC.js";
4
4
  import "./chunk-ZTHE5RBZ.js";
5
5
  import "./chunk-KFQGP6VL.js";
6
6
  export {
package/dist/index.d.ts CHANGED
@@ -148,6 +148,11 @@ interface StealthConfig {
148
148
  interface XBBrowser {
149
149
  readonly disconnected: boolean;
150
150
  close(): Promise<void>;
151
+ /**
152
+ * Disconnect this WebSocket without closing pages or contexts. This is the
153
+ * safe cleanup path when a session attached to an existing user tab.
154
+ */
155
+ disconnect(): Promise<void>;
151
156
  newContext(opts?: XBContextOptions): Promise<XBContext>;
152
157
  contexts(): XBContext[];
153
158
  /**
@@ -322,6 +327,37 @@ interface XBPage {
322
327
  * 绕过页面同源策略(CDP 是调试通道)——跨域嵌入内容读写的唯一路径。
323
328
  */
324
329
  evaluateInFrame<R = unknown>(urlIncludes: string, expression: string): Promise<R>;
330
+ /** 浏览器级 iframe target 列表(OOPIF 只在这里可见,Page.getFrameTree 看不到) */
331
+ listFrameTargets(): Promise<Array<{
332
+ url: string;
333
+ targetId: string;
334
+ }>>;
335
+ /**
336
+ * 指定 OOPIF 的鼠标——Input 域事件派发到 iframe 自己的 session 才进得去
337
+ * (主页面 session 的输入被进程隔离挡在外面)。坐标 = iframe 局部坐标。
338
+ */
339
+ frameMouse(urlIncludes: string, opts?: {
340
+ fresh?: boolean;
341
+ }): Promise<XBMouse>;
342
+ /**
343
+ * 带重试的 frame 鼠标操作:session 失效(OOPIF 被 Chrome 异步销毁/
344
+ * 验证码 iframe 重建)时强制重 attach 再做一次。fn 内不要缓存 mouse
345
+ * 跨调用使用——重试时实例会换新(鼠标位置重置)。
346
+ */
347
+ runFrameMouse<T>(urlIncludes: string, fn: (mouse: XBMouse) => Promise<T>): Promise<T>;
348
+ /** 在 OOPIF 内点击选择器命中的元素(轮询等待 + stealth 落点) */
349
+ clickInFrame(urlIncludes: string, selector: string, opts?: {
350
+ timeoutMs?: number;
351
+ }): Promise<{
352
+ x: number;
353
+ y: number;
354
+ }>;
355
+ /** 在 OOPIF 内填输入框(点击聚焦 + insertText + 回读) */
356
+ fillInFrame(urlIncludes: string, selector: string, text: string, opts?: {
357
+ timeoutMs?: number;
358
+ }): Promise<{
359
+ value: string;
360
+ }>;
325
361
  bringToFront(): Promise<void>;
326
362
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>;
327
363
  setOfflineMode(offline: boolean): Promise<void>;
@@ -441,7 +477,9 @@ interface XBMouse {
441
477
  button?: 'left' | 'right' | 'middle';
442
478
  clickCount?: number;
443
479
  delay?: number;
444
- stealth?: boolean;
480
+ stealth?: boolean; /** 元素宽高——stealth 落点偏移用(XBMouseImpl 已支持) */
481
+ elementWidth?: number;
482
+ elementHeight?: number;
445
483
  }): Promise<void>;
446
484
  dblclick(x: number, y: number, opts?: {
447
485
  button?: 'left' | 'right' | 'middle';
@@ -456,6 +494,8 @@ interface XBMouse {
456
494
  steps?: number;
457
495
  }): Promise<void>;
458
496
  wheel(deltaX: number, deltaY: number): Promise<void>;
497
+ /** 先移动到 (x,y) 再派发滚轮(trusted mouseWheel) */
498
+ wheelAt(x: number, y: number, deltaX: number, deltaY: number): Promise<void>;
459
499
  /** Drag from current position to (x,y) — drives the real HTML5 DnD pipeline */
460
500
  drag(x: number, y: number, opts?: {
461
501
  steps?: number;
@@ -519,6 +559,7 @@ interface XBScreenshotOptions {
519
559
  y: number;
520
560
  width: number;
521
561
  height: number;
562
+ scale?: number;
522
563
  };
523
564
  omitBackground?: boolean;
524
565
  timeout?: number;
@@ -740,6 +781,8 @@ interface ManagedSession {
740
781
  lastActivityAt: number;
741
782
  isCDP?: boolean;
742
783
  cdpEndpoint?: string;
784
+ /** True when CDP attach reused an existing user tab; close must only disconnect. */
785
+ reusedExistingPage?: boolean;
743
786
  }
744
787
  interface BrowserLaunchOptions {
745
788
  headless?: boolean;
@@ -878,6 +921,8 @@ type WSMessage = {
878
921
  interface ViewInfo {
879
922
  id: string;
880
923
  label: string;
924
+ kind: 'view' | 'image' | 'qr';
925
+ src?: string;
881
926
  rect: {
882
927
  x: number;
883
928
  y: number;
@@ -914,6 +959,13 @@ type WSInboundMessage = {
914
959
  type: 'snapshot_request';
915
960
  format?: string;
916
961
  quality?: number;
962
+ clip?: {
963
+ x: number;
964
+ y: number;
965
+ width: number;
966
+ height: number;
967
+ };
968
+ scale?: number;
917
969
  } | {
918
970
  type: 'bind';
919
971
  sessionId: string;
@@ -1146,6 +1198,8 @@ interface BrowserCommandContext extends Omit<CommandContext, 'waitForHuman' | 'd
1146
1198
  browserContext: XBContext;
1147
1199
  sessionId?: string;
1148
1200
  cdpEndpoint?: string;
1201
+ /** 全局 --frame <url-substring>:命令级 --frame 优先于此默认值(OOPIF 路由) */
1202
+ frame?: string;
1149
1203
  waitForHuman?: (options?: WaitForHumanOptions) => Promise<WaitForHumanResult>;
1150
1204
  detectAntiBot?: (page: XBPage, config?: DetectionConfig) => Promise<DetectionResult>;
1151
1205
  }
@@ -1279,6 +1333,7 @@ declare function executeChain(input: string, options?: {
1279
1333
  cdpEndpoint?: string;
1280
1334
  sessionName?: string;
1281
1335
  fileMode?: boolean;
1336
+ frame?: string;
1282
1337
  }): Promise<ChainExecutionResult>;
1283
1338
  /**
1284
1339
  * Check whether the given input string contains chain operators.
@@ -1329,6 +1384,14 @@ interface BrowserCommandDefinition<P extends ZodType<unknown, ZodTypeDef, unknow
1329
1384
  * The executor will resolve `eN` ref values to real selectors before calling the handler.
1330
1385
  */
1331
1386
  selectorParams?: string[];
1387
+ /**
1388
+ * Usage examples shown in `--help` output. Rendered by xcli-core's helpGenerator.
1389
+ */
1390
+ examples?: Array<{
1391
+ cmd: string;
1392
+ description?: string;
1393
+ output?: string;
1394
+ }>;
1332
1395
  handler: (params: z.infer<P>, ctx: BrowserCommandContext) => Promise<unknown>;
1333
1396
  }
1334
1397
  /**
@@ -1341,6 +1404,11 @@ interface RegisteredCommand {
1341
1404
  readonly parameters?: ZodType<unknown>;
1342
1405
  readonly result?: ZodType<unknown>;
1343
1406
  readonly selectorParams?: string[];
1407
+ readonly examples?: Array<{
1408
+ cmd: string;
1409
+ description?: string;
1410
+ output?: string;
1411
+ }>;
1344
1412
  readonly handler: (params: Record<string, unknown>, ctx: BrowserCommandContext) => Promise<unknown>;
1345
1413
  }
1346
1414
  /**
@@ -2083,6 +2151,28 @@ interface RecordingSummary {
2083
2151
  elements: Record<string, ElementRef>;
2084
2152
  checkpoints: CheckpointEntry[];
2085
2153
  }
2154
+ interface CompactSummaryFlowItem {
2155
+ step: number;
2156
+ action: string;
2157
+ }
2158
+ interface CompactSummaryApi {
2159
+ method: string;
2160
+ url: string;
2161
+ path: string;
2162
+ status: number;
2163
+ contentType: string;
2164
+ responseSize: number;
2165
+ requestBody?: unknown;
2166
+ }
2167
+ interface RecordingCompactSummary {
2168
+ startUrl: string;
2169
+ recordedAt: string;
2170
+ durationMs: number;
2171
+ totalActions: number;
2172
+ totalNetworkRequests: number;
2173
+ flow: CompactSummaryFlowItem[];
2174
+ keyApis: CompactSummaryApi[];
2175
+ }
2086
2176
  type CheckpointType = 'dialog' | 'captcha' | 'login' | 'iframe' | 'slider' | 'custom';
2087
2177
  interface CheckpointEntry {
2088
2178
  id: number;
@@ -2671,31 +2761,35 @@ declare function parseCommandChain(input: string, options?: ParseOptions): Parse
2671
2761
 
2672
2762
  declare function normalizeSelector(input: string): string;
2673
2763
 
2674
- type AgentTargetAction = 'click' | 'fill' | 'type' | 'press' | 'select' | 'check' | 'hover';
2764
+ /**
2765
+ * 交互元素快照目标。
2766
+ *
2767
+ * 字段精简原则:只保留对 AI 决策和实际操作有意义的字段。
2768
+ * 已移除的零副作用字段(实测无消费方,详见 docs/snapshot-benchmark.md):
2769
+ * - `box`(坐标):AI 用 ref 操作,坐标无用;viewer 截图裁剪用另一套 box
2770
+ * - `actions`(动作数组):可由 role/tag 推导,actOnPage 不读取
2771
+ * - `visible`:默认只采集可见元素,全为 true,零信息量
2772
+ */
2675
2773
  interface AgentTarget {
2676
2774
  ref: string;
2677
2775
  selector: string;
2678
2776
  role: string;
2679
2777
  name: string;
2680
2778
  tag: string;
2681
- visible: boolean;
2779
+ /** 是否可用;false 时 compact 文本输出 disabled 标签 */
2682
2780
  enabled: boolean;
2781
+ /** 是否可编辑(input/textarea/select/contenteditable);compact 输出 editable 标签 */
2683
2782
  editable: boolean;
2783
+ /** checkbox/radio 的选中态;compact 输出 checked/unchecked 标签 */
2684
2784
  checked?: boolean;
2785
+ /** 可编辑元素的当前值(截断 120 字符) */
2685
2786
  value?: string;
2686
- box?: {
2687
- x: number;
2688
- y: number;
2689
- width: number;
2690
- height: number;
2691
- };
2692
- actions: AgentTargetAction[];
2693
2787
  }
2694
2788
  interface AgentObservation {
2695
2789
  url: string;
2696
2790
  title: string;
2791
+ /** 页面状态哈希;actOnPage 用它做 ref staleness(过期)检测 */
2697
2792
  screenHash: string;
2698
- timestamp: string;
2699
2793
  targets: AgentTarget[];
2700
2794
  compact?: string;
2701
2795
  selectors?: Record<string, string>;
@@ -3156,4 +3250,4 @@ declare function advise(decision: DecisionResult, originalMethod: string): Advis
3156
3250
  /** Convenience factory: create and start a CDP interceptor proxy with defaults. */
3157
3251
  declare function createCDPInterceptor(config: CDPInterceptorConfig): Promise<CDPInterceptorProxy>;
3158
3252
 
3159
- export { type APIRequest, type APIResponse, type AdvisoryResult, type AgentActionInput, type AgentActionResult, type AgentObservation, type AgentTarget, type AgentWaitInput, type AgentWaitResult, type AnalysisResult, BROWSER_SCOPE, type BatchCollectResult, type BrowserCommandContext, type BrowserCommandDefinition, type BrowserLaunchOptions, type BuiltinCommand, type BuiltinContext, type CDPError, type CDPInterceptorConfig, CDPInterceptorProxy, type CDPInterceptorRule, type CDPInterceptorStats, type CDPLogEntry, type CDPMessage, type CDPRequest, type CDPResponse, type CaptchaDetectionResult, CaptchaDetector, type ChainExecutionResult, type ChainRequest, type ChainStepResult, type CollectResult, type CollectorConfig, type CommandMessage, type CompanyInfo, type ContextChange, type DaemonInfo, DataCollector, DataStorage, type DecisionAction, type DecisionResult, type DomainStat, type ElementRef, type ExecRequest, type ExecutionResult, HTTPServer, type HTTPServerConfig, type HTTPServerError, HumanInteractionManager, type InstallOptions, type InstalledPlugin, type ManagedSession, type MessageDirection, type NetworkEntry, type ParsedPipeline, PlaybackEngine, type PlaybackOptions, type PlaybackResult, PluginInstaller, type PluginLoaderOptions, type RecordedEvent, RecorderController, type RecorderStatus, type Recording, type RecordingControlFile, type RecordingData, type RecordingEvent, type RecordingSession, type RecordingStep, type RecordingSummary, type RegisteredCommand, ResultAnalyzer, type RuleContext, type RuleEngine, type ScopeDefinition, type ScopeLevel, ScreencastCapturer, type ScreencastFrame, type ScreencastMessage, type ScreencastOptions, type SearchResult, type ManagedSession as SessionInfo, SessionRecorder, type StatusMessage, type StorageConfig, type UserAction, type ViolationSeverity, type WSInboundMessage, type WSMessage, WSServer, type WSServerConfig, type WaitForHumanOptions, type WaitForHumanResult, WebhookNotifier, type WebhookPayload, XBrowserPluginLoader, actOnPage, advise, allBuiltins, assertPageScope, attachWaitForHuman, automationSignalsRule, checkBrowserScope, routeCommand as cliRoute, closeAllSessions as closeAllBrowserSessions, closeAllSessions, closeSession, closeSessionByName, createCDPInterceptor, createRuleEngine, createSession, destroyBrowser, destroyBrowser as destroySessionManager, domMutationRule, emulationOverrideRule, eventSimulationRule, executeChain, executeCommand, extractAndSave, extractRecording, filterRecording, findSession, findSession as findSessionInfo, fingerprintingRule, generateBashScript, generateJSScript, generatePythonScript, getAllSessions as getAllBrowserSessions, getAllCommands, getBrowser, getBuiltin, getCaptchaConfig, getCommand, getCommandNames, getCompanyType, getDaemonProcessStatus, getPageScreenHash, getPlatformName, getSessionPage, getWSServerFromCache, inputKeystrokeRule, isChainInput, getAllSessions as listAllBrowserSessions, listSessions, mouseTrajectoryRule, networkAnomalyRule, normalizeSelector, observePage, openSession, pageLifecycleRule, parseCommandChain, parseExcludeTypes, printExtractSummary, registerCommand, resetForTesting, setWSServer, setWSServerCache, startDaemonProcess, stopDaemonProcess, version, waitForPage };
3253
+ export { type APIRequest, type APIResponse, type AdvisoryResult, type AgentActionInput, type AgentActionResult, type AgentObservation, type AgentTarget, type AgentWaitInput, type AgentWaitResult, type AnalysisResult, BROWSER_SCOPE, type BatchCollectResult, type BrowserCommandContext, type BrowserCommandDefinition, type BrowserLaunchOptions, type BuiltinCommand, type BuiltinContext, type CDPError, type CDPInterceptorConfig, CDPInterceptorProxy, type CDPInterceptorRule, type CDPInterceptorStats, type CDPLogEntry, type CDPMessage, type CDPRequest, type CDPResponse, type CaptchaDetectionResult, CaptchaDetector, type ChainExecutionResult, type ChainRequest, type ChainStepResult, type CollectResult, type CollectorConfig, type CommandMessage, type CompanyInfo, type ContextChange, type DaemonInfo, DataCollector, DataStorage, type DecisionAction, type DecisionResult, type DomainStat, type ElementRef, type ExecRequest, type ExecutionResult, HTTPServer, type HTTPServerConfig, type HTTPServerError, HumanInteractionManager, type InstallOptions, type InstalledPlugin, type ManagedSession, type MessageDirection, type NetworkEntry, type ParsedPipeline, PlaybackEngine, type PlaybackOptions, type PlaybackResult, PluginInstaller, type PluginLoaderOptions, type RecordedEvent, RecorderController, type RecorderStatus, type Recording, type RecordingCompactSummary, type RecordingControlFile, type RecordingData, type RecordingEvent, type RecordingSession, type RecordingStep, type RecordingSummary, type RegisteredCommand, ResultAnalyzer, type RuleContext, type RuleEngine, type ScopeDefinition, type ScopeLevel, ScreencastCapturer, type ScreencastFrame, type ScreencastMessage, type ScreencastOptions, type SearchResult, type ManagedSession as SessionInfo, SessionRecorder, type StatusMessage, type StorageConfig, type UserAction, type ViolationSeverity, type WSInboundMessage, type WSMessage, WSServer, type WSServerConfig, type WaitForHumanOptions, type WaitForHumanResult, WebhookNotifier, type WebhookPayload, XBrowserPluginLoader, actOnPage, advise, allBuiltins, assertPageScope, attachWaitForHuman, automationSignalsRule, checkBrowserScope, routeCommand as cliRoute, closeAllSessions as closeAllBrowserSessions, closeAllSessions, closeSession, closeSessionByName, createCDPInterceptor, createRuleEngine, createSession, destroyBrowser, destroyBrowser as destroySessionManager, domMutationRule, emulationOverrideRule, eventSimulationRule, executeChain, executeCommand, extractAndSave, extractRecording, filterRecording, findSession, findSession as findSessionInfo, fingerprintingRule, generateBashScript, generateJSScript, generatePythonScript, getAllSessions as getAllBrowserSessions, getAllCommands, getBrowser, getBuiltin, getCaptchaConfig, getCommand, getCommandNames, getCompanyType, getDaemonProcessStatus, getPageScreenHash, getPlatformName, getSessionPage, getWSServerFromCache, inputKeystrokeRule, isChainInput, getAllSessions as listAllBrowserSessions, listSessions, mouseTrajectoryRule, networkAnomalyRule, normalizeSelector, observePage, openSession, pageLifecycleRule, parseCommandChain, parseExcludeTypes, printExtractSummary, registerCommand, resetForTesting, setWSServer, setWSServerCache, startDaemonProcess, stopDaemonProcess, version, waitForPage };