@web-auto/webauto 0.1.1 → 0.1.3

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 (354) hide show
  1. package/apps/desktop-console/default-settings.json +1 -0
  2. package/apps/desktop-console/dist/main/index.mjs +1618 -0
  3. package/apps/desktop-console/{src → dist}/main/preload.mjs +10 -0
  4. package/apps/desktop-console/dist/renderer/index.js +3063 -0
  5. package/apps/desktop-console/entry/ui-console.mjs +299 -0
  6. package/apps/webauto/entry/account.mjs +356 -0
  7. package/apps/webauto/entry/lib/account-detect.mjs +160 -0
  8. package/apps/webauto/entry/lib/account-store.mjs +587 -0
  9. package/apps/webauto/entry/lib/profilepool.mjs +1 -1
  10. package/apps/webauto/entry/xhs-install.mjs +27 -3
  11. package/apps/webauto/entry/xhs-status.mjs +152 -0
  12. package/apps/webauto/entry/xhs-unified.mjs +595 -17
  13. package/bin/webauto.mjs +263 -15
  14. package/dist/apps/webauto/server.js +66 -0
  15. package/dist/modules/camo-backend/src/index.js +575 -0
  16. package/dist/modules/camo-backend/src/internal/BrowserSession.js +817 -0
  17. package/dist/modules/camo-backend/src/internal/ElementRegistry.js +61 -0
  18. package/dist/modules/camo-backend/src/internal/ProfileLock.js +85 -0
  19. package/dist/modules/camo-backend/src/internal/SessionManager.js +172 -0
  20. package/dist/modules/camo-backend/src/internal/container-matcher.js +852 -0
  21. package/dist/modules/camo-backend/src/internal/engine-manager.js +258 -0
  22. package/dist/modules/camo-backend/src/internal/fingerprint.js +203 -0
  23. package/dist/modules/camo-backend/src/internal/pageRuntime.js +29 -0
  24. package/dist/modules/camo-backend/src/internal/runtimeInjector.js +30 -0
  25. package/dist/modules/camo-backend/src/internal/state-bus.js +46 -0
  26. package/dist/modules/camo-backend/src/internal/storage-paths.js +36 -0
  27. package/dist/modules/camo-backend/src/internal/ws-server.js +1202 -0
  28. package/dist/modules/camo-runtime/src/utils/browser-service.mjs +423 -0
  29. package/dist/modules/camo-runtime/src/utils/config.mjs +77 -0
  30. package/dist/modules/container-registry/src/index.js +184 -0
  31. package/dist/modules/logging/src/index.js +92 -0
  32. package/dist/modules/operations/src/builtin.js +27 -0
  33. package/dist/modules/operations/src/container-binding.js +75 -0
  34. package/dist/modules/operations/src/executor.js +146 -0
  35. package/dist/modules/operations/src/operations/click.js +167 -0
  36. package/dist/modules/operations/src/operations/extract.js +204 -0
  37. package/dist/modules/operations/src/operations/find-child.js +17 -0
  38. package/dist/modules/operations/src/operations/highlight.js +138 -0
  39. package/dist/modules/operations/src/operations/key.js +61 -0
  40. package/dist/modules/operations/src/operations/navigate.js +148 -0
  41. package/dist/modules/operations/src/operations/scroll.js +126 -0
  42. package/dist/modules/operations/src/operations/type.js +190 -0
  43. package/dist/modules/operations/src/queue.js +100 -0
  44. package/dist/modules/operations/src/registry.js +11 -0
  45. package/dist/modules/operations/src/system/mouse.js +33 -0
  46. package/dist/modules/state/src/atomic-json.js +33 -0
  47. package/dist/modules/workflow/blocks/AnchorVerificationBlock.js +71 -0
  48. package/dist/modules/workflow/blocks/BehaviorRandomizer.js +26 -0
  49. package/dist/modules/workflow/blocks/CallWorkflowBlock.js +38 -0
  50. package/dist/modules/workflow/blocks/CloseDetailBlock.js +209 -0
  51. package/dist/modules/workflow/blocks/CollectBatch.js +137 -0
  52. package/dist/modules/workflow/blocks/CollectCommentsBlock.js +415 -0
  53. package/dist/modules/workflow/blocks/CollectSearchListBlock.js +599 -0
  54. package/dist/modules/workflow/blocks/CollectWeiboPosts.js +229 -0
  55. package/dist/modules/workflow/blocks/DetectPageStateBlock.js +259 -0
  56. package/dist/modules/workflow/blocks/EnsureLoginBlock.js +162 -0
  57. package/dist/modules/workflow/blocks/EnsureSession.js +426 -0
  58. package/dist/modules/workflow/blocks/ErrorClassifier.js +164 -0
  59. package/dist/modules/workflow/blocks/ErrorRecoveryBlock.js +319 -0
  60. package/dist/modules/workflow/blocks/ExpandCommentsBlock.js +1032 -0
  61. package/dist/modules/workflow/blocks/ExtractDetailBlock.js +310 -0
  62. package/dist/modules/workflow/blocks/ExtractPostFields.js +88 -0
  63. package/dist/modules/workflow/blocks/GenerateSmartReplyBlock.js +68 -0
  64. package/dist/modules/workflow/blocks/GoToSearchBlock.js +497 -0
  65. package/dist/modules/workflow/blocks/GracefulFallbackBlock.js +104 -0
  66. package/dist/modules/workflow/blocks/HighlightBlock.js +66 -0
  67. package/dist/modules/workflow/blocks/InitAutoScroll.js +65 -0
  68. package/dist/modules/workflow/blocks/LoadContainerDefinition.js +50 -0
  69. package/dist/modules/workflow/blocks/LoadContainerIndex.js +43 -0
  70. package/dist/modules/workflow/blocks/LocateAndGuardBlock.js +176 -0
  71. package/dist/modules/workflow/blocks/LoginRecoveryBlock.js +242 -0
  72. package/dist/modules/workflow/blocks/MatchContainers.js +64 -0
  73. package/dist/modules/workflow/blocks/MonitoringBlock.js +190 -0
  74. package/dist/modules/workflow/blocks/OpenDetailBlock.js +1240 -0
  75. package/dist/modules/workflow/blocks/OrganizeXhsNotesBlock.js +117 -0
  76. package/dist/modules/workflow/blocks/PersistXhsNoteBlock.js +270 -0
  77. package/dist/modules/workflow/blocks/PickSinglePost.js +69 -0
  78. package/dist/modules/workflow/blocks/ProgressTracker.js +125 -0
  79. package/dist/modules/workflow/blocks/RecordFixtureBlock.js +44 -0
  80. package/dist/modules/workflow/blocks/RenderMarkdown.js +48 -0
  81. package/dist/modules/workflow/blocks/SaveFile.js +54 -0
  82. package/dist/modules/workflow/blocks/ScrollNextBatch.js +72 -0
  83. package/dist/modules/workflow/blocks/SessionHealthBlock.js +73 -0
  84. package/dist/modules/workflow/blocks/StartBrowserService.js +45 -0
  85. package/dist/modules/workflow/blocks/ValidateContainerDefinition.js +67 -0
  86. package/dist/modules/workflow/blocks/ValidateExtract.js +35 -0
  87. package/dist/modules/workflow/blocks/WaitSearchPermitBlock.js +162 -0
  88. package/dist/modules/workflow/blocks/WaitStable.js +74 -0
  89. package/dist/modules/workflow/blocks/WarmupCommentsBlock.js +120 -0
  90. package/dist/modules/workflow/blocks/WorkflowExecutor.js +156 -0
  91. package/dist/modules/workflow/blocks/XiaohongshuCollectFromLinksBlock.js +1004 -0
  92. package/dist/modules/workflow/blocks/XiaohongshuCollectLinksBlock.js +1049 -0
  93. package/dist/modules/workflow/blocks/XiaohongshuFullCollectBlock.js +782 -0
  94. package/dist/modules/workflow/blocks/helpers/anchorVerify.js +198 -0
  95. package/dist/modules/workflow/blocks/helpers/asyncWorkQueue.js +53 -0
  96. package/dist/modules/workflow/blocks/helpers/commentScroller.js +334 -0
  97. package/dist/modules/workflow/blocks/helpers/commentSectionLocator.js +126 -0
  98. package/dist/modules/workflow/blocks/helpers/containerAnchors.js +301 -0
  99. package/dist/modules/workflow/blocks/helpers/debugArtifacts.js +6 -0
  100. package/dist/modules/workflow/blocks/helpers/downloadPaths.js +29 -0
  101. package/dist/modules/workflow/blocks/helpers/expandCommentsController.js +53 -0
  102. package/dist/modules/workflow/blocks/helpers/expandCommentsExtractor.js +129 -0
  103. package/dist/modules/workflow/blocks/helpers/macosVisionOcrPlugin.js +116 -0
  104. package/dist/modules/workflow/blocks/helpers/mergeXhsMarkdown.js +109 -0
  105. package/dist/modules/workflow/blocks/helpers/openDetailController.js +56 -0
  106. package/dist/modules/workflow/blocks/helpers/openDetailTypes.js +7 -0
  107. package/dist/modules/workflow/blocks/helpers/openDetailViewport.js +474 -0
  108. package/dist/modules/workflow/blocks/helpers/openDetailWaiter.js +104 -0
  109. package/dist/modules/workflow/blocks/helpers/operationLogger.js +195 -0
  110. package/dist/modules/workflow/blocks/helpers/persistedNotes.js +107 -0
  111. package/dist/modules/workflow/blocks/helpers/replyExpander.js +260 -0
  112. package/dist/modules/workflow/blocks/helpers/scrollIntoView.js +138 -0
  113. package/dist/modules/workflow/blocks/helpers/searchExecutor.js +328 -0
  114. package/dist/modules/workflow/blocks/helpers/searchGate.js +46 -0
  115. package/dist/modules/workflow/blocks/helpers/searchPageState.js +164 -0
  116. package/dist/modules/workflow/blocks/helpers/searchResultWaiter.js +64 -0
  117. package/dist/modules/workflow/blocks/helpers/simpleAnchor.js +134 -0
  118. package/dist/modules/workflow/blocks/helpers/smartReply.js +40 -0
  119. package/dist/modules/workflow/blocks/helpers/systemInput.js +635 -0
  120. package/dist/modules/workflow/blocks/helpers/targetCountMode.js +9 -0
  121. package/dist/modules/workflow/blocks/helpers/xhsCliArgs.js +80 -0
  122. package/dist/modules/workflow/blocks/helpers/xhsCommentDom.js +805 -0
  123. package/dist/modules/workflow/blocks/helpers/xhsNoteOrganizer.js +140 -0
  124. package/dist/modules/workflow/blocks/restore/RestorePhaseBlock.js +204 -0
  125. package/dist/modules/workflow/config/workflowRegistry.js +32 -0
  126. package/dist/modules/workflow/definitions/batch-collect-workflow.js +63 -0
  127. package/dist/modules/workflow/definitions/scroll-extract-workflow.js +74 -0
  128. package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow-v2.js +81 -0
  129. package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow.js +57 -0
  130. package/dist/modules/workflow/definitions/xiaohongshu-full-collect-workflow-v3.js +68 -0
  131. package/dist/modules/workflow/definitions/xiaohongshu-note-collect.js +49 -0
  132. package/dist/modules/workflow/definitions/xiaohongshu-phase1-workflow-v3.js +30 -0
  133. package/dist/modules/workflow/definitions/xiaohongshu-phase2-links-workflow-v3.js +40 -0
  134. package/dist/modules/workflow/definitions/xiaohongshu-phase3-collect-workflow-v1.js +54 -0
  135. package/dist/modules/workflow/definitions/xiaohongshu-phase34-from-links-workflow-v3.js +25 -0
  136. package/dist/modules/workflow/src/WeiboEventDrivenWorkflowRunner.js +308 -0
  137. package/dist/modules/workflow/src/context.js +70 -0
  138. package/dist/modules/workflow/src/index.js +5 -0
  139. package/dist/modules/workflow/src/orchestrator.js +230 -0
  140. package/dist/modules/workflow/src/runner.js +55 -0
  141. package/dist/modules/workflow/src/runtime.js +70 -0
  142. package/dist/modules/workflow/workflows/WeiboFeedExtractionWorkflow.js +359 -0
  143. package/dist/modules/workflow/workflows/XiaohongshuLoginWorkflow.js +110 -0
  144. package/dist/modules/xiaohongshu/app/src/blocks/MatchCommentsBlock.js +139 -0
  145. package/dist/modules/xiaohongshu/app/src/blocks/Phase1EnsureServicesBlock.js +36 -0
  146. package/dist/modules/xiaohongshu/app/src/blocks/Phase1MonitorCookieBlock.js +213 -0
  147. package/dist/modules/xiaohongshu/app/src/blocks/Phase1StartProfileBlock.js +121 -0
  148. package/dist/modules/xiaohongshu/app/src/blocks/Phase2CollectLinksBlock.js +1249 -0
  149. package/dist/modules/xiaohongshu/app/src/blocks/Phase2SearchBlock.js +703 -0
  150. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseDetailBlock.js +41 -0
  151. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseTabsBlock.js +44 -0
  152. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CollectCommentsBlock.js +150 -0
  153. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ExtractDetailBlock.js +117 -0
  154. package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenDetailBlock.js +102 -0
  155. package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenTabsBlock.js +109 -0
  156. package/dist/modules/xiaohongshu/app/src/blocks/Phase34PersistDetailBlock.js +117 -0
  157. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ProcessSingleNoteBlock.js +114 -0
  158. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ValidateLinksBlock.js +90 -0
  159. package/dist/modules/xiaohongshu/app/src/blocks/Phase3InteractBlock.js +1009 -0
  160. package/dist/modules/xiaohongshu/app/src/blocks/Phase4MultiTabHarvestBlock.js +233 -0
  161. package/dist/modules/xiaohongshu/app/src/blocks/ReplyInteractBlock.js +291 -0
  162. package/dist/modules/xiaohongshu/app/src/blocks/XhsDiscoverFallbackBlock.js +240 -0
  163. package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatchDsl.js +126 -0
  164. package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatcher.js +99 -0
  165. package/dist/modules/xiaohongshu/app/src/blocks/helpers/evidence.js +27 -0
  166. package/dist/modules/xiaohongshu/app/src/blocks/helpers/sharding.js +42 -0
  167. package/dist/modules/xiaohongshu/app/src/blocks/helpers/xhsComments.js +270 -0
  168. package/dist/modules/xiaohongshu/app/src/index.js +9 -0
  169. package/dist/modules/xiaohongshu/app/src/utils/checkpoints.js +222 -0
  170. package/dist/modules/xiaohongshu/app/src/utils/controllerAction.js +43 -0
  171. package/dist/services/controller/src/controller.js +1476 -0
  172. package/dist/services/controller/src/index.js +2 -0
  173. package/dist/services/controller/src/payload-normalizer.js +129 -0
  174. package/dist/services/shared/heartbeat.js +120 -0
  175. package/dist/services/shared/lib/errorHandler.js +2 -0
  176. package/dist/services/shared/serviceProcessLogger.js +139 -0
  177. package/dist/services/unified-api/RemoteBrowserSession.js +176 -0
  178. package/dist/services/unified-api/RemoteSessionManager.js +148 -0
  179. package/dist/services/unified-api/container-operations-handler.js +115 -0
  180. package/dist/services/unified-api/server.js +652 -0
  181. package/dist/services/unified-api/state-registry.js +274 -0
  182. package/dist/services/unified-api/task-persistence.js +66 -0
  183. package/dist/services/unified-api/task-state.js +130 -0
  184. package/modules/camo-runtime/src/autoscript/action-providers/xhs/search.mjs +12 -5
  185. package/modules/xiaohongshu/app/pnpm-lock.yaml +24 -0
  186. package/package.json +38 -10
  187. package/.beads/README.md +0 -81
  188. package/.beads/config.yaml +0 -67
  189. package/.beads/interactions.jsonl +0 -0
  190. package/.beads/issues.jsonl +0 -180
  191. package/.beads/metadata.json +0 -4
  192. package/.claude/settings.local.json +0 -10
  193. package/.github/workflows/ci.yml +0 -55
  194. package/AGENTS.md +0 -253
  195. package/apps/desktop-console/README.md +0 -27
  196. package/apps/desktop-console/package-lock.json +0 -897
  197. package/apps/desktop-console/package.json +0 -20
  198. package/apps/desktop-console/scripts/build-and-install.mjs +0 -19
  199. package/apps/desktop-console/scripts/build.mjs +0 -45
  200. package/apps/desktop-console/scripts/test-preload.mjs +0 -13
  201. package/apps/desktop-console/src/main/config.mts +0 -26
  202. package/apps/desktop-console/src/main/core-daemon-manager.mts +0 -131
  203. package/apps/desktop-console/src/main/desktop-settings.mts +0 -267
  204. package/apps/desktop-console/src/main/heartbeat-watchdog.mts +0 -50
  205. package/apps/desktop-console/src/main/heartbeat-watchdog.test.mts +0 -68
  206. package/apps/desktop-console/src/main/index-streaming.test.mts +0 -20
  207. package/apps/desktop-console/src/main/index.mts +0 -980
  208. package/apps/desktop-console/src/main/profile-store.mts +0 -239
  209. package/apps/desktop-console/src/main/profile-store.test.mts +0 -54
  210. package/apps/desktop-console/src/main/state-bridge.mts +0 -114
  211. package/apps/desktop-console/src/main/task-state-types.ts +0 -32
  212. package/apps/desktop-console/src/renderer/hooks/use-task-state.mts +0 -120
  213. package/apps/desktop-console/src/renderer/index.mts +0 -133
  214. package/apps/desktop-console/src/renderer/index.test.mts +0 -34
  215. package/apps/desktop-console/src/renderer/path-helpers.mts +0 -46
  216. package/apps/desktop-console/src/renderer/path-helpers.test.mts +0 -14
  217. package/apps/desktop-console/src/renderer/tabs/debug.mts +0 -48
  218. package/apps/desktop-console/src/renderer/tabs/debug.test.mts +0 -22
  219. package/apps/desktop-console/src/renderer/tabs/logs.mts +0 -421
  220. package/apps/desktop-console/src/renderer/tabs/logs.test.mts +0 -27
  221. package/apps/desktop-console/src/renderer/tabs/preflight.mts +0 -486
  222. package/apps/desktop-console/src/renderer/tabs/preflight.test.mts +0 -33
  223. package/apps/desktop-console/src/renderer/tabs/profile-pool.mts +0 -213
  224. package/apps/desktop-console/src/renderer/tabs/results.mts +0 -171
  225. package/apps/desktop-console/src/renderer/tabs/run.test.mts +0 -63
  226. package/apps/desktop-console/src/renderer/tabs/runtime.mts +0 -151
  227. package/apps/desktop-console/src/renderer/tabs/settings.mts +0 -146
  228. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/account-flow.mts +0 -486
  229. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/guide-browser-check.mts +0 -56
  230. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/helpers.mts +0 -262
  231. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/layout-block.mts +0 -430
  232. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/live-stats.mts +0 -847
  233. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/run-flow.mts +0 -443
  234. package/apps/desktop-console/src/renderer/tabs/xiaohongshu-state.mts +0 -425
  235. package/apps/desktop-console/src/renderer/tabs/xiaohongshu.mts +0 -497
  236. package/apps/desktop-console/src/renderer/tabs/xiaohongshu.test.mts +0 -291
  237. package/apps/desktop-console/src/renderer/ui-components.mts +0 -31
  238. package/docs/README_camoufox_chinese.md +0 -141
  239. package/docs/USAGE_V3.md +0 -163
  240. package/docs/arch/OCR_MACOS_PLUGIN.md +0 -39
  241. package/docs/arch/PORTS.md +0 -40
  242. package/docs/arch/REGRESSION_CHECKLIST.md +0 -121
  243. package/docs/arch/SEARCH_GATE.md +0 -224
  244. package/docs/arch/VIEWPORT_SAFETY.md +0 -182
  245. package/docs/arch/XIAOHONGSHU_OFFLINE_MOCK_DESIGN.md +0 -267
  246. package/docs/xiaohongshu-container-driven-summary.md +0 -221
  247. package/docs/xiaohongshu-full-collect-runbook.md +0 -134
  248. package/docs/xiaohongshu-next-steps.md +0 -228
  249. package/docs/xiaohongshu-quickstart.md +0 -73
  250. package/docs/xiaohongshu-workflow-summary.md +0 -227
  251. package/modules/container-registry/tests/container-registry.test.ts +0 -16
  252. package/modules/logging/tests/logging.test.ts +0 -38
  253. package/modules/operations/tests/operations.test.ts +0 -22
  254. package/modules/operations/tests/viewport-filter.test.ts +0 -161
  255. package/modules/operations/tests/visible-only.test.ts +0 -250
  256. package/modules/session-manager/tests/session-manager.test.ts +0 -23
  257. package/modules/state/src/atomic-json.test.ts +0 -30
  258. package/modules/state/src/paths.test.ts +0 -59
  259. package/modules/state/src/xiaohongshu-collect-state.test.ts +0 -259
  260. package/modules/workflow/blocks/AnchorVerificationBlock.d.ts.map +0 -1
  261. package/modules/workflow/blocks/AnchorVerificationBlock.js.map +0 -1
  262. package/modules/workflow/blocks/DetectPageStateBlock.d.ts.map +0 -1
  263. package/modules/workflow/blocks/DetectPageStateBlock.js.map +0 -1
  264. package/modules/workflow/blocks/ErrorRecoveryBlock.d.ts.map +0 -1
  265. package/modules/workflow/blocks/ErrorRecoveryBlock.js.map +0 -1
  266. package/modules/workflow/blocks/WaitSearchPermitBlock.d.ts.map +0 -1
  267. package/modules/workflow/blocks/WaitSearchPermitBlock.js.map +0 -1
  268. package/modules/workflow/blocks/helpers/containerAnchors.d.ts.map +0 -1
  269. package/modules/workflow/blocks/helpers/containerAnchors.js.map +0 -1
  270. package/modules/workflow/blocks/helpers/downloadPaths.test.ts +0 -62
  271. package/modules/workflow/blocks/helpers/mergeXhsMarkdown.test.ts +0 -121
  272. package/modules/workflow/blocks/helpers/operationLogger.d.ts.map +0 -1
  273. package/modules/workflow/blocks/helpers/operationLogger.js.map +0 -1
  274. package/modules/workflow/blocks/helpers/persistedNotes.test.ts +0 -268
  275. package/modules/workflow/blocks/helpers/searchPageState.d.ts.map +0 -1
  276. package/modules/workflow/blocks/helpers/searchPageState.js.map +0 -1
  277. package/modules/workflow/blocks/helpers/targetCountMode.test.ts +0 -29
  278. package/modules/workflow/blocks/helpers/xhsCliArgs.test.ts +0 -75
  279. package/modules/workflow/tests/smartReply.test.ts +0 -32
  280. package/modules/xiaohongshu/app/src/blocks/Phase3Interact.matcher.test.ts +0 -33
  281. package/modules/xiaohongshu/app/src/utils/__tests__/checkpoints.test.ts +0 -141
  282. package/modules/xiaohongshu/app/tests/commentMatchDsl.test.ts +0 -50
  283. package/modules/xiaohongshu/app/tests/commentMatcher.test.ts +0 -46
  284. package/modules/xiaohongshu/app/tests/sharding.test.ts +0 -31
  285. package/package-scripts.json +0 -8
  286. package/runtime/infra/utils/README.md +0 -13
  287. package/runtime/infra/utils/scripts/README.md +0 -0
  288. package/runtime/infra/utils/scripts/development/eval-in-session.mjs +0 -40
  289. package/runtime/infra/utils/scripts/development/highlight-search-containers.mjs +0 -35
  290. package/runtime/infra/utils/scripts/service/kill-port.mjs +0 -24
  291. package/runtime/infra/utils/scripts/service/start-api.mjs +0 -39
  292. package/runtime/infra/utils/scripts/service/start-browser-service.mjs +0 -106
  293. package/runtime/infra/utils/scripts/service/stop-api.mjs +0 -18
  294. package/runtime/infra/utils/scripts/service/stop-browser-service.mjs +0 -104
  295. package/runtime/infra/utils/scripts/test-services.mjs +0 -94
  296. package/services/shared/heartbeat.test.ts +0 -102
  297. package/services/unified-api/__tests__/task-state.test.ts +0 -95
  298. package/sitecustomize.py +0 -19
  299. package/tests/README.md +0 -194
  300. package/tests/e2e/workflows/weibo-feed-extraction.test.ts +0 -171
  301. package/tests/fixtures/data/container-definitions.json +0 -67
  302. package/tests/fixtures/pages/simple-page.html +0 -69
  303. package/tests/integration/01-test-container-match.mjs +0 -188
  304. package/tests/integration/02-test-dom-branch.mjs +0 -161
  305. package/tests/integration/03-test-container-operation-system.mjs +0 -91
  306. package/tests/integration/05-test-container-lifecycle-events.mjs +0 -224
  307. package/tests/integration/05-test-container-lifecycle-with-events.mjs +0 -250
  308. package/tests/integration/06-test-container-dom-tree-drawing.mjs +0 -256
  309. package/tests/integration/07-test-weibo-container-lifecycle.mjs +0 -355
  310. package/tests/integration/08-test-weibo-feed-workflow.test.mjs +0 -164
  311. package/tests/integration/10-test-visual-analyzer.mjs +0 -312
  312. package/tests/integration/11-test-visual-loop.mjs +0 -284
  313. package/tests/integration/12-test-simple-visual-loop.mjs +0 -242
  314. package/tests/integration/13-test-visual-robust.mjs +0 -185
  315. package/tests/integration/14-test-visual-highlight-loop.mjs +0 -271
  316. package/tests/integration/inspect-page.mjs +0 -50
  317. package/tests/integration/run-all-tests.mjs +0 -95
  318. package/tests/patch_verification/CODEX_PATCH_TEST.md +0 -103
  319. package/tests/patch_verification/PHASE2_ANALYSIS.md +0 -179
  320. package/tests/patch_verification/PHASE2_OPTIMIZATION_REPORT.md +0 -55
  321. package/tests/patch_verification/PHASE2_TO_PHASE4_SUMMARY.md +0 -126
  322. package/tests/patch_verification/QUICK_TEST_SEQUENCE.md +0 -262
  323. package/tests/patch_verification/README.md +0 -143
  324. package/tests/patch_verification/RUN_TESTS.md +0 -60
  325. package/tests/patch_verification/TEST_EXECUTION.md +0 -99
  326. package/tests/patch_verification/TEST_PLAN.md +0 -328
  327. package/tests/patch_verification/TEST_RESULTS.md +0 -34
  328. package/tests/patch_verification/TOOL_TEST_PLAN.md +0 -48
  329. package/tests/patch_verification/run-tool-test.mjs +0 -121
  330. package/tests/patch_verification/temp_test_files/test01.txt +0 -1
  331. package/tests/patch_verification/temp_test_files/test02.txt +0 -3
  332. package/tests/patch_verification/temp_test_files/test02_gnu.txt +0 -3
  333. package/tests/patch_verification/temp_test_files/test03.txt +0 -1
  334. package/tests/patch_verification/temp_test_files/test03_multiline.txt +0 -5
  335. package/tests/patch_verification/temp_test_files/test04_function.ts +0 -5
  336. package/tests/patch_verification/temp_test_files/test05_import.ts +0 -4
  337. package/tests/patch_verification/temp_test_files/test06_special_chars.txt +0 -4
  338. package/tests/patch_verification/temp_test_files/test07_indentation.ts +0 -5
  339. package/tests/patch_verification/temp_test_files/test08_mismatch.txt +0 -1
  340. package/tests/patch_verification/temp_test_files/test_add_02.txt +0 -3
  341. package/tests/patch_verification/temp_test_files/test_simple.txt +0 -1
  342. package/tests/runner/TestReporter.mjs +0 -57
  343. package/tests/runner/TestRunner.mjs +0 -244
  344. package/tests/unit/commands/profile.test.mjs +0 -10
  345. package/tests/unit/container/change-notifier.test.mjs +0 -181
  346. package/tests/unit/lifecycle/session-registry.test.mjs +0 -135
  347. package/tests/unit/operations/registry.test.ts +0 -73
  348. package/tests/unit/utils/browser-service.test.mjs +0 -153
  349. package/tests/unit/utils/config.test.mjs +0 -166
  350. package/tests/unit/utils/fingerprint.test.mjs +0 -166
  351. package/tsconfig.json +0 -31
  352. package/tsconfig.services.json +0 -26
  353. /package/apps/desktop-console/{src → dist}/renderer/index.html +0 -0
  354. /package/apps/desktop-console/{src/renderer/tabs → dist/renderer}/run.mts +0 -0
@@ -0,0 +1,2 @@
1
+ export { UiController } from './controller.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Payload 统一解析层
3
+ *
4
+ * 职责:
5
+ * - 将各种变体字段(profile/profileId/profile_id, sessionId/session_id)统一为标准格式
6
+ * - 验证必需字段并提供清晰错误信息
7
+ * - 支持从 payload 内部提取字段(如 config, options)
8
+ *
9
+ * 设计原则:
10
+ * - 优先使用标准字段名(profile)
11
+ * - 兼容历史变体(profileId, profile_id, sessionId, session_id)
12
+ * - config/options 内的字段提升到顶层(便于访问)
13
+ * - 提供清晰的错误信息
14
+ */
15
+ /**
16
+ * 统一 payload 解析
17
+ *
18
+ * @example
19
+ * const normalized = normalizePayload(payload, {
20
+ * required: ['profile'],
21
+ * allowTopLevel: true
22
+ * });
23
+ */
24
+ export function normalizePayload(payload = {}, options = {}) {
25
+ const { required = [], allowTopLevel = true, strict = false, defaultProfile } = options;
26
+ const normalized = {};
27
+ const errors = [];
28
+ // 1. 处理 profile 字段变体(优先级:profile > profileId > profile_id > sessionId)
29
+ const profile = payload.profile ||
30
+ payload.profileId ||
31
+ payload.profile_id ||
32
+ payload.sessionId ||
33
+ payload.session_id ||
34
+ defaultProfile;
35
+ if (profile) {
36
+ normalized.profile = profile;
37
+ }
38
+ // 2. 处理其他常见字段(直接从 payload 顶层提取)
39
+ const commonFields = [
40
+ 'url',
41
+ 'containerId',
42
+ 'operationId',
43
+ 'script',
44
+ 'selector',
45
+ 'path',
46
+ 'style',
47
+ 'duration',
48
+ 'timeout',
49
+ 'maxDepth',
50
+ 'maxChildren',
51
+ 'rootSelector',
52
+ 'channel',
53
+ 'sticky',
54
+ 'maxMatches'
55
+ ];
56
+ for (const field of commonFields) {
57
+ if (field in payload && payload[field] !== undefined) {
58
+ normalized[field] = payload[field];
59
+ }
60
+ }
61
+ // 3. 提取内部字段(config/options)并提升到顶层
62
+ // 优先使用 config,其次 options
63
+ const internalConfig = payload.config || payload.options;
64
+ if (internalConfig && typeof internalConfig === 'object') {
65
+ // 将内部字段提升到顶层(便于访问)
66
+ Object.assign(normalized, internalConfig);
67
+ // 同时保留原始引用(便于调试)
68
+ normalized.config = internalConfig;
69
+ }
70
+ // 4. 处理其他顶层字段(根据 allowTopLevel 决定)
71
+ if (allowTopLevel) {
72
+ const reservedFields = new Set([
73
+ 'profile',
74
+ 'profileId',
75
+ 'profile_id',
76
+ 'sessionId',
77
+ 'session_id',
78
+ 'config',
79
+ 'options'
80
+ ]);
81
+ for (const [key, value] of Object.entries(payload)) {
82
+ if (!reservedFields.has(key) && !(key in normalized)) {
83
+ if (strict) {
84
+ errors.push(`Unexpected field in payload: ${key}`);
85
+ }
86
+ else {
87
+ normalized[key] = value;
88
+ }
89
+ }
90
+ }
91
+ }
92
+ // 5. 验证必需字段
93
+ for (const field of required) {
94
+ if (!(field in normalized) || normalized[field] === undefined || normalized[field] === null) {
95
+ errors.push(`Missing required field: ${field}`);
96
+ }
97
+ }
98
+ if (errors.length > 0) {
99
+ throw new Error(`Payload validation failed:\n - ${errors.join('\n - ')}`);
100
+ }
101
+ return normalized;
102
+ }
103
+ /**
104
+ * 创建带验证的 payload 解析器(闭包形式,便于复用配置)
105
+ */
106
+ export function createPayloadParser(options) {
107
+ return (payload) => normalizePayload(payload, options);
108
+ }
109
+ /**
110
+ * 验证 payload 是否包含指定字段
111
+ */
112
+ export function hasRequiredFields(payload, fields) {
113
+ return fields.every((field) => {
114
+ const value = payload[field];
115
+ return value !== undefined && value !== null && value !== '';
116
+ });
117
+ }
118
+ /**
119
+ * 提取 profile(兼容多种写法)
120
+ */
121
+ export function extractProfile(payload) {
122
+ return (payload.profile ||
123
+ payload.profileId ||
124
+ payload.profile_id ||
125
+ payload.sessionId ||
126
+ payload.session_id);
127
+ }
128
+ export default normalizePayload;
129
+ //# sourceMappingURL=payload-normalizer.js.map
@@ -0,0 +1,120 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ function resolveNumber(value, fallback) {
5
+ const parsed = Number(value);
6
+ if (!Number.isFinite(parsed))
7
+ return fallback;
8
+ return parsed;
9
+ }
10
+ function resolveHeartbeatFile(filePath) {
11
+ if (filePath && String(filePath).trim())
12
+ return String(filePath).trim();
13
+ if (process.env.WEBAUTO_HEARTBEAT_FILE)
14
+ return String(process.env.WEBAUTO_HEARTBEAT_FILE).trim();
15
+ return path.join(os.homedir(), '.webauto', 'run', 'xhs-heartbeat.json');
16
+ }
17
+ function readHeartbeat(filePath) {
18
+ try {
19
+ const raw = fs.readFileSync(filePath, 'utf-8');
20
+ const data = JSON.parse(raw);
21
+ if (!data || typeof data !== 'object')
22
+ return null;
23
+ return {
24
+ ts: typeof data.ts === 'string' ? data.ts : undefined,
25
+ status: typeof data.status === 'string' ? data.status : undefined,
26
+ };
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ export function startHeartbeatWatcher(options) {
33
+ const filePath = options.filePath || process.env.WEBAUTO_HEARTBEAT_FILE;
34
+ if (!filePath)
35
+ return () => { };
36
+ const staleMs = resolveNumber(options.staleMs ?? process.env.WEBAUTO_HEARTBEAT_STALE_MS, 45_000);
37
+ const intervalMs = resolveNumber(options.intervalMs ?? process.env.WEBAUTO_HEARTBEAT_INTERVAL_MS, Math.max(2000, Math.floor(staleMs / 3)));
38
+ const serviceName = options.serviceName || 'service';
39
+ const startAt = Date.now();
40
+ const timer = setInterval(() => {
41
+ let ts = 0;
42
+ let status = '';
43
+ const payload = readHeartbeat(filePath);
44
+ if (payload) {
45
+ status = String(payload.status || '');
46
+ ts = payload.ts ? Date.parse(payload.ts) : 0;
47
+ }
48
+ if (!ts) {
49
+ try {
50
+ const stat = fs.statSync(filePath);
51
+ ts = Number(stat.mtimeMs || 0);
52
+ }
53
+ catch (err) {
54
+ if (err?.code === 'ENOENT') {
55
+ if (Date.now() - startAt > staleMs) {
56
+ console.warn(`[heartbeat] ${serviceName} exit: heartbeat file missing (${filePath})`);
57
+ process.exit(0);
58
+ }
59
+ }
60
+ return;
61
+ }
62
+ }
63
+ if (status === 'stopped') {
64
+ console.warn(`[heartbeat] ${serviceName} exit: main process stopped`);
65
+ process.exit(0);
66
+ }
67
+ const age = Date.now() - ts;
68
+ if (age > staleMs) {
69
+ console.warn(`[heartbeat] ${serviceName} exit: heartbeat stale ${age}ms > ${staleMs}ms`);
70
+ process.exit(0);
71
+ }
72
+ }, intervalMs);
73
+ timer.unref();
74
+ return () => clearInterval(timer);
75
+ }
76
+ export function startHeartbeatWriter(options = {}) {
77
+ const filePath = resolveHeartbeatFile(options.filePath);
78
+ const intervalMs = resolveNumber(options.intervalMs ?? process.env.WEBAUTO_HEARTBEAT_INTERVAL_MS, 5000);
79
+ const staleMs = resolveNumber(options.staleMs ?? process.env.WEBAUTO_HEARTBEAT_STALE_MS, 45_000);
80
+ let status = String(options.initialStatus || 'running');
81
+ process.env.WEBAUTO_HEARTBEAT_FILE = filePath;
82
+ process.env.WEBAUTO_HEARTBEAT_INTERVAL_MS = String(intervalMs);
83
+ process.env.WEBAUTO_HEARTBEAT_STALE_MS = String(staleMs);
84
+ try {
85
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
86
+ }
87
+ catch {
88
+ // ignore dir creation failure
89
+ }
90
+ const write = (nextStatus) => {
91
+ if (nextStatus)
92
+ status = String(nextStatus);
93
+ const payload = {
94
+ pid: process.pid,
95
+ ts: new Date().toISOString(),
96
+ status,
97
+ };
98
+ try {
99
+ fs.writeFileSync(filePath, JSON.stringify(payload));
100
+ }
101
+ catch {
102
+ // ignore heartbeat write failures
103
+ }
104
+ };
105
+ write(status);
106
+ const timer = setInterval(() => write(), intervalMs);
107
+ timer.unref();
108
+ const stop = () => {
109
+ write('stopped');
110
+ clearInterval(timer);
111
+ };
112
+ process.on('exit', stop);
113
+ process.on('SIGINT', stop);
114
+ process.on('SIGTERM', stop);
115
+ const setStatus = (nextStatus) => {
116
+ write(nextStatus || 'running');
117
+ };
118
+ return { stop, filePath, intervalMs, staleMs, setStatus };
119
+ }
120
+ //# sourceMappingURL=heartbeat.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=errorHandler.js.map
@@ -0,0 +1,139 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ const INSTALLED = new Set();
5
+ function ensureLogDir() {
6
+ const dir = path.join(os.homedir(), '.webauto', 'logs');
7
+ try {
8
+ fs.mkdirSync(dir, { recursive: true });
9
+ }
10
+ catch {
11
+ // ignore
12
+ }
13
+ return dir;
14
+ }
15
+ function safeAppend(filePath, line) {
16
+ try {
17
+ fs.appendFileSync(filePath, line);
18
+ }
19
+ catch {
20
+ // ignore
21
+ }
22
+ }
23
+ function formatError(err) {
24
+ if (!err || typeof err !== 'object')
25
+ return { message: String(err) };
26
+ const anyErr = err;
27
+ return {
28
+ name: typeof anyErr.name === 'string' ? anyErr.name : undefined,
29
+ message: typeof anyErr.message === 'string' ? anyErr.message : String(err),
30
+ stack: typeof anyErr.stack === 'string' ? anyErr.stack : undefined,
31
+ code: typeof anyErr.code === 'string' ? anyErr.code : undefined,
32
+ };
33
+ }
34
+ function createConsoleTee(logFile) {
35
+ const kWrapped = Symbol.for('webauto.consoleTeeWrapped');
36
+ const g = globalThis;
37
+ if (g[kWrapped])
38
+ return;
39
+ g[kWrapped] = true;
40
+ const originals = {
41
+ log: console.log.bind(console),
42
+ info: console.info.bind(console),
43
+ warn: console.warn.bind(console),
44
+ error: console.error.bind(console),
45
+ };
46
+ const wrap = (level) => {
47
+ return (...args) => {
48
+ const ts = new Date().toISOString();
49
+ const msg = args
50
+ .map((a) => {
51
+ if (typeof a === 'string')
52
+ return a;
53
+ try {
54
+ return JSON.stringify(a);
55
+ }
56
+ catch {
57
+ return String(a);
58
+ }
59
+ })
60
+ .join(' ');
61
+ safeAppend(logFile, `[${ts}] [${level.toUpperCase()}] ${msg}\n`);
62
+ originals[level](...args);
63
+ };
64
+ };
65
+ console.log = wrap('log');
66
+ console.info = wrap('info');
67
+ console.warn = wrap('warn');
68
+ console.error = wrap('error');
69
+ }
70
+ export function installServiceProcessLogger(opts) {
71
+ const serviceName = String(opts.serviceName || '').trim();
72
+ const id = `service:${serviceName}`;
73
+ if (!serviceName)
74
+ return { logEvent: () => { } };
75
+ if (INSTALLED.has(id))
76
+ return { logEvent: () => { } };
77
+ INSTALLED.add(id);
78
+ const logDir = ensureLogDir();
79
+ const crashFile = path.join(logDir, `${serviceName}.crash.jsonl`);
80
+ const consoleLogFile = path.join(logDir, `${serviceName}.log`);
81
+ const tee = typeof opts.teeConsoleToFile === 'boolean'
82
+ ? opts.teeConsoleToFile
83
+ : !!(process.stdout.isTTY || process.stderr.isTTY);
84
+ if (tee)
85
+ createConsoleTee(consoleLogFile);
86
+ const base = {
87
+ service: serviceName,
88
+ pid: process.pid,
89
+ node: process.version,
90
+ };
91
+ const logEvent = (event, data = {}) => {
92
+ safeAppend(crashFile, `${JSON.stringify({
93
+ ts: new Date().toISOString(),
94
+ ...base,
95
+ event,
96
+ ...data,
97
+ })}\n`);
98
+ };
99
+ logEvent('process_start', {
100
+ argv: process.argv,
101
+ cwd: process.cwd(),
102
+ ppid: process.ppid,
103
+ stdoutIsTTY: !!process.stdout.isTTY,
104
+ stderrIsTTY: !!process.stderr.isTTY,
105
+ });
106
+ process.on('uncaughtException', (err) => {
107
+ logEvent('uncaughtException', { error: formatError(err) });
108
+ // Keep the process alive for post-mortem visibility, but mark non-zero.
109
+ process.exitCode = 1;
110
+ });
111
+ process.on('unhandledRejection', (reason) => {
112
+ logEvent('unhandledRejection', { reason: formatError(reason) });
113
+ process.exitCode = 1;
114
+ });
115
+ const tapSignal = (signal) => {
116
+ const hadExisting = process.listenerCount(signal) > 0;
117
+ const handler = () => {
118
+ logEvent('signal', { signal });
119
+ process.off(signal, handler);
120
+ // If we were the only listener, re-send the signal so Node's default behavior applies.
121
+ if (!hadExisting) {
122
+ try {
123
+ process.kill(process.pid, signal);
124
+ }
125
+ catch {
126
+ // ignore
127
+ }
128
+ }
129
+ };
130
+ process.on(signal, handler);
131
+ };
132
+ tapSignal('SIGINT');
133
+ tapSignal('SIGTERM');
134
+ tapSignal('SIGHUP');
135
+ process.on('beforeExit', (code) => logEvent('beforeExit', { code }));
136
+ process.on('exit', (code) => logEvent('exit', { code }));
137
+ return { logEvent };
138
+ }
139
+ //# sourceMappingURL=serviceProcessLogger.js.map
@@ -0,0 +1,176 @@
1
+ /**
2
+ * RemoteBrowserSession - 远程浏览器会话适配器
3
+ *
4
+ * 作用:让 Unified API (7701) 能够代理对 Browser Service (7704) 的调用
5
+ * 核心职责:通过 HTTP 与 Browser Service 通信,模拟本地 BrowserSession 接口
6
+ */
7
+ import { fetch } from 'undici';
8
+ /**
9
+ * 远程浏览器会话代理
10
+ *
11
+ * 实现与 BrowserSession 兼容的接口,但所有操作都通过 HTTP 转发到 Browser Service
12
+ */
13
+ export class RemoteBrowserSession {
14
+ sessionId;
15
+ baseUrl;
16
+ lastKnownUrl = null;
17
+ constructor(options) {
18
+ this.sessionId = options.sessionId;
19
+ this.baseUrl = options.browserServiceUrl;
20
+ }
21
+ get id() {
22
+ return this.sessionId;
23
+ }
24
+ get currentPage() {
25
+ return this.createPageProxy();
26
+ }
27
+ createPageProxy() {
28
+ return {
29
+ evaluate: async (fn, ...args) => {
30
+ return this.evaluate(fn, ...args);
31
+ },
32
+ url: () => this.getCurrentUrl() || '',
33
+ mouse: {
34
+ move: async (x, y, options) => {
35
+ return this.sendCommand('mouse:move', { x, y, steps: options?.steps || 3 });
36
+ },
37
+ click: async (x, y, options) => {
38
+ // 注意:options可能包含button、clicks、delay
39
+ return this.sendCommand('mouse:click', { x, y,
40
+ button: options?.button || 'left',
41
+ clicks: options?.clickCount || 1,
42
+ delay: options?.delay || 50
43
+ });
44
+ },
45
+ wheel: async (deltaX, deltaY) => {
46
+ return this.sendCommand('mouse:wheel', { deltaX, deltaY });
47
+ },
48
+ },
49
+ keyboard: {
50
+ type: async (text, options) => {
51
+ return this.sendCommand('keyboard:type', {
52
+ text,
53
+ delay: options?.delay,
54
+ submit: options?.submit,
55
+ });
56
+ },
57
+ press: async (key, options) => {
58
+ return this.sendCommand('keyboard:press', {
59
+ key,
60
+ delay: options?.delay,
61
+ });
62
+ },
63
+ }
64
+ };
65
+ }
66
+ async ensurePage(url) {
67
+ if (url) {
68
+ await this.goto(url);
69
+ }
70
+ return this.createPageProxy();
71
+ }
72
+ async sendCommand(action, args) {
73
+ const url = `${this.baseUrl}/command`;
74
+ const payload = {
75
+ action,
76
+ args: {
77
+ profileId: this.sessionId,
78
+ ...args
79
+ }
80
+ };
81
+ const response = await fetch(url, {
82
+ method: 'POST',
83
+ headers: { 'Content-Type': 'application/json' },
84
+ body: JSON.stringify(payload)
85
+ });
86
+ if (!response.ok) {
87
+ const text = await response.text().catch(() => '');
88
+ const detail = text ? ` | ${text}` : '';
89
+ throw new Error(`Browser Service command failed: HTTP ${response.status} ${response.statusText}${detail}`);
90
+ }
91
+ const result = await response.json();
92
+ // Browser Service 使用 { ok: boolean, body?: any, error?: string } 结构,
93
+ // 旧代码使用 { success: boolean, data?: any, error?: string }。
94
+ const isError = result?.success === false ||
95
+ result?.ok === false;
96
+ if (isError) {
97
+ // 打印原始返回,便于定位协议不一致问题
98
+ // 注意:这里是 Unified API 侧日志,不会泄露页面内容
99
+ // eslint-disable-next-line no-console
100
+ console.error('[RemoteBrowserSession] sendCommand error payload', action, result);
101
+ throw new Error(result.error || 'Unknown error');
102
+ }
103
+ // 统一返回 data/body/result 中的有效字段
104
+ if (result.data !== undefined)
105
+ return result.data;
106
+ if (result.body !== undefined)
107
+ return result.body;
108
+ if (result.result !== undefined)
109
+ return result.result;
110
+ return result;
111
+ }
112
+ async goto(url) {
113
+ await this.sendCommand('goto', { url });
114
+ this.lastKnownUrl = url;
115
+ }
116
+ getCurrentUrl() {
117
+ return this.lastKnownUrl;
118
+ }
119
+ async evaluate(expression, arg) {
120
+ // 注意:tsx/esbuild 可能会在函数源码中注入 __name 等辅助方法;
121
+ // 直接 toString() 后在页面上下文执行会触发 ReferenceError。
122
+ // 这里注入一个 noop __name 以保证序列化函数可执行。
123
+ const script = typeof expression === 'function'
124
+ ? (() => {
125
+ const fnSource = expression.toString();
126
+ const argSource = typeof arg === 'undefined' ? 'undefined' : JSON.stringify(arg);
127
+ return `(function(){ const __name = (fn) => fn; return (${fnSource})(${argSource}); })()`;
128
+ })()
129
+ : expression;
130
+ return this.sendCommand('evaluate', { script });
131
+ }
132
+ async screenshot(fullPage = true) {
133
+ const result = await this.sendCommand('screenshot', { fullPage });
134
+ if (typeof result === 'string') {
135
+ return Buffer.from(result, 'base64');
136
+ }
137
+ return result;
138
+ }
139
+ async click(selector) {
140
+ await this.sendCommand('click', { selector });
141
+ }
142
+ async fill(selector, text) {
143
+ await this.sendCommand('fill', { selector, text });
144
+ }
145
+ async getCookies() {
146
+ return this.sendCommand('getCookies');
147
+ }
148
+ async saveCookiesToFile(filePath) {
149
+ return this.sendCommand('saveCookies', { path: filePath });
150
+ }
151
+ async saveCookiesIfStable(filePath, opts = {}) {
152
+ return this.sendCommand('saveCookiesIfStable', { path: filePath, ...opts });
153
+ }
154
+ async injectCookiesFromFile(filePath) {
155
+ return this.sendCommand('loadCookies', { path: filePath });
156
+ }
157
+ async getInfo() {
158
+ return this.sendCommand('getStatus');
159
+ }
160
+ async close() {
161
+ await this.sendCommand('stop');
162
+ }
163
+ setMode(mode) {
164
+ this.sendCommand('setMode', { mode }).catch(() => {
165
+ // ignore unsupported command
166
+ });
167
+ }
168
+ addRuntimeEventObserver(_observer) {
169
+ console.warn('[RemoteBrowserSession] addRuntimeEventObserver not implemented');
170
+ return () => { };
171
+ }
172
+ get modeName() {
173
+ return 'dev';
174
+ }
175
+ }
176
+ //# sourceMappingURL=RemoteBrowserSession.js.map