@web-auto/webauto 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/desktop-console/default-settings.json +1 -0
- package/apps/desktop-console/dist/main/index.mjs +1618 -0
- package/apps/desktop-console/{src → dist}/main/preload.mjs +10 -0
- package/apps/desktop-console/dist/renderer/index.js +3063 -0
- package/apps/desktop-console/entry/ui-console.mjs +299 -0
- package/apps/webauto/entry/account.mjs +356 -0
- package/apps/webauto/entry/lib/account-detect.mjs +160 -0
- package/apps/webauto/entry/lib/account-store.mjs +587 -0
- package/apps/webauto/entry/lib/profilepool.mjs +1 -1
- package/apps/webauto/entry/xhs-install.mjs +27 -3
- package/apps/webauto/entry/xhs-status.mjs +152 -0
- package/apps/webauto/entry/xhs-unified.mjs +595 -17
- package/bin/webauto.mjs +247 -12
- package/dist/apps/webauto/server.js +66 -0
- package/dist/modules/camo-backend/src/index.js +575 -0
- package/dist/modules/camo-backend/src/internal/BrowserSession.js +817 -0
- package/dist/modules/camo-backend/src/internal/ElementRegistry.js +61 -0
- package/dist/modules/camo-backend/src/internal/ProfileLock.js +85 -0
- package/dist/modules/camo-backend/src/internal/SessionManager.js +172 -0
- package/dist/modules/camo-backend/src/internal/container-matcher.js +852 -0
- package/dist/modules/camo-backend/src/internal/engine-manager.js +258 -0
- package/dist/modules/camo-backend/src/internal/fingerprint.js +203 -0
- package/dist/modules/camo-backend/src/internal/pageRuntime.js +29 -0
- package/dist/modules/camo-backend/src/internal/runtimeInjector.js +30 -0
- package/dist/modules/camo-backend/src/internal/state-bus.js +46 -0
- package/dist/modules/camo-backend/src/internal/storage-paths.js +36 -0
- package/dist/modules/camo-backend/src/internal/ws-server.js +1202 -0
- package/dist/modules/camo-runtime/src/utils/browser-service.mjs +423 -0
- package/dist/modules/camo-runtime/src/utils/config.mjs +77 -0
- package/dist/modules/container-registry/src/index.js +184 -0
- package/dist/modules/logging/src/index.js +92 -0
- package/dist/modules/operations/src/builtin.js +27 -0
- package/dist/modules/operations/src/container-binding.js +75 -0
- package/dist/modules/operations/src/executor.js +146 -0
- package/dist/modules/operations/src/operations/click.js +167 -0
- package/dist/modules/operations/src/operations/extract.js +204 -0
- package/dist/modules/operations/src/operations/find-child.js +17 -0
- package/dist/modules/operations/src/operations/highlight.js +138 -0
- package/dist/modules/operations/src/operations/key.js +61 -0
- package/dist/modules/operations/src/operations/navigate.js +148 -0
- package/dist/modules/operations/src/operations/scroll.js +126 -0
- package/dist/modules/operations/src/operations/type.js +190 -0
- package/dist/modules/operations/src/queue.js +100 -0
- package/dist/modules/operations/src/registry.js +11 -0
- package/dist/modules/operations/src/system/mouse.js +33 -0
- package/dist/modules/state/src/atomic-json.js +33 -0
- package/dist/modules/workflow/blocks/AnchorVerificationBlock.js +71 -0
- package/dist/modules/workflow/blocks/BehaviorRandomizer.js +26 -0
- package/dist/modules/workflow/blocks/CallWorkflowBlock.js +38 -0
- package/dist/modules/workflow/blocks/CloseDetailBlock.js +209 -0
- package/dist/modules/workflow/blocks/CollectBatch.js +137 -0
- package/dist/modules/workflow/blocks/CollectCommentsBlock.js +415 -0
- package/dist/modules/workflow/blocks/CollectSearchListBlock.js +599 -0
- package/dist/modules/workflow/blocks/CollectWeiboPosts.js +229 -0
- package/dist/modules/workflow/blocks/DetectPageStateBlock.js +259 -0
- package/dist/modules/workflow/blocks/EnsureLoginBlock.js +162 -0
- package/dist/modules/workflow/blocks/EnsureSession.js +426 -0
- package/dist/modules/workflow/blocks/ErrorClassifier.js +164 -0
- package/dist/modules/workflow/blocks/ErrorRecoveryBlock.js +319 -0
- package/dist/modules/workflow/blocks/ExpandCommentsBlock.js +1032 -0
- package/dist/modules/workflow/blocks/ExtractDetailBlock.js +310 -0
- package/dist/modules/workflow/blocks/ExtractPostFields.js +88 -0
- package/dist/modules/workflow/blocks/GenerateSmartReplyBlock.js +68 -0
- package/dist/modules/workflow/blocks/GoToSearchBlock.js +497 -0
- package/dist/modules/workflow/blocks/GracefulFallbackBlock.js +104 -0
- package/dist/modules/workflow/blocks/HighlightBlock.js +66 -0
- package/dist/modules/workflow/blocks/InitAutoScroll.js +65 -0
- package/dist/modules/workflow/blocks/LoadContainerDefinition.js +50 -0
- package/dist/modules/workflow/blocks/LoadContainerIndex.js +43 -0
- package/dist/modules/workflow/blocks/LocateAndGuardBlock.js +176 -0
- package/dist/modules/workflow/blocks/LoginRecoveryBlock.js +242 -0
- package/dist/modules/workflow/blocks/MatchContainers.js +64 -0
- package/dist/modules/workflow/blocks/MonitoringBlock.js +190 -0
- package/dist/modules/workflow/blocks/OpenDetailBlock.js +1240 -0
- package/dist/modules/workflow/blocks/OrganizeXhsNotesBlock.js +117 -0
- package/dist/modules/workflow/blocks/PersistXhsNoteBlock.js +270 -0
- package/dist/modules/workflow/blocks/PickSinglePost.js +69 -0
- package/dist/modules/workflow/blocks/ProgressTracker.js +125 -0
- package/dist/modules/workflow/blocks/RecordFixtureBlock.js +44 -0
- package/dist/modules/workflow/blocks/RenderMarkdown.js +48 -0
- package/dist/modules/workflow/blocks/SaveFile.js +54 -0
- package/dist/modules/workflow/blocks/ScrollNextBatch.js +72 -0
- package/dist/modules/workflow/blocks/SessionHealthBlock.js +73 -0
- package/dist/modules/workflow/blocks/StartBrowserService.js +45 -0
- package/dist/modules/workflow/blocks/ValidateContainerDefinition.js +67 -0
- package/dist/modules/workflow/blocks/ValidateExtract.js +35 -0
- package/dist/modules/workflow/blocks/WaitSearchPermitBlock.js +162 -0
- package/dist/modules/workflow/blocks/WaitStable.js +74 -0
- package/dist/modules/workflow/blocks/WarmupCommentsBlock.js +120 -0
- package/dist/modules/workflow/blocks/WorkflowExecutor.js +156 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectFromLinksBlock.js +1004 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectLinksBlock.js +1049 -0
- package/dist/modules/workflow/blocks/XiaohongshuFullCollectBlock.js +782 -0
- package/dist/modules/workflow/blocks/helpers/anchorVerify.js +198 -0
- package/dist/modules/workflow/blocks/helpers/asyncWorkQueue.js +53 -0
- package/dist/modules/workflow/blocks/helpers/commentScroller.js +334 -0
- package/dist/modules/workflow/blocks/helpers/commentSectionLocator.js +126 -0
- package/dist/modules/workflow/blocks/helpers/containerAnchors.js +301 -0
- package/dist/modules/workflow/blocks/helpers/debugArtifacts.js +6 -0
- package/dist/modules/workflow/blocks/helpers/downloadPaths.js +29 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsController.js +53 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsExtractor.js +129 -0
- package/dist/modules/workflow/blocks/helpers/macosVisionOcrPlugin.js +116 -0
- package/dist/modules/workflow/blocks/helpers/mergeXhsMarkdown.js +109 -0
- package/dist/modules/workflow/blocks/helpers/openDetailController.js +56 -0
- package/dist/modules/workflow/blocks/helpers/openDetailTypes.js +7 -0
- package/dist/modules/workflow/blocks/helpers/openDetailViewport.js +474 -0
- package/dist/modules/workflow/blocks/helpers/openDetailWaiter.js +104 -0
- package/dist/modules/workflow/blocks/helpers/operationLogger.js +195 -0
- package/dist/modules/workflow/blocks/helpers/persistedNotes.js +107 -0
- package/dist/modules/workflow/blocks/helpers/replyExpander.js +260 -0
- package/dist/modules/workflow/blocks/helpers/scrollIntoView.js +138 -0
- package/dist/modules/workflow/blocks/helpers/searchExecutor.js +328 -0
- package/dist/modules/workflow/blocks/helpers/searchGate.js +46 -0
- package/dist/modules/workflow/blocks/helpers/searchPageState.js +164 -0
- package/dist/modules/workflow/blocks/helpers/searchResultWaiter.js +64 -0
- package/dist/modules/workflow/blocks/helpers/simpleAnchor.js +134 -0
- package/dist/modules/workflow/blocks/helpers/smartReply.js +40 -0
- package/dist/modules/workflow/blocks/helpers/systemInput.js +635 -0
- package/dist/modules/workflow/blocks/helpers/targetCountMode.js +9 -0
- package/dist/modules/workflow/blocks/helpers/xhsCliArgs.js +80 -0
- package/dist/modules/workflow/blocks/helpers/xhsCommentDom.js +805 -0
- package/dist/modules/workflow/blocks/helpers/xhsNoteOrganizer.js +140 -0
- package/dist/modules/workflow/blocks/restore/RestorePhaseBlock.js +204 -0
- package/dist/modules/workflow/config/workflowRegistry.js +32 -0
- package/dist/modules/workflow/definitions/batch-collect-workflow.js +63 -0
- package/dist/modules/workflow/definitions/scroll-extract-workflow.js +74 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow-v2.js +81 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow.js +57 -0
- package/dist/modules/workflow/definitions/xiaohongshu-full-collect-workflow-v3.js +68 -0
- package/dist/modules/workflow/definitions/xiaohongshu-note-collect.js +49 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase1-workflow-v3.js +30 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase2-links-workflow-v3.js +40 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase3-collect-workflow-v1.js +54 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase34-from-links-workflow-v3.js +25 -0
- package/dist/modules/workflow/src/WeiboEventDrivenWorkflowRunner.js +308 -0
- package/dist/modules/workflow/src/context.js +70 -0
- package/dist/modules/workflow/src/index.js +5 -0
- package/dist/modules/workflow/src/orchestrator.js +230 -0
- package/dist/modules/workflow/src/runner.js +55 -0
- package/dist/modules/workflow/src/runtime.js +70 -0
- package/dist/modules/workflow/workflows/WeiboFeedExtractionWorkflow.js +359 -0
- package/dist/modules/workflow/workflows/XiaohongshuLoginWorkflow.js +110 -0
- package/dist/modules/xiaohongshu/app/src/blocks/MatchCommentsBlock.js +139 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1EnsureServicesBlock.js +36 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1MonitorCookieBlock.js +213 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1StartProfileBlock.js +121 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2CollectLinksBlock.js +1249 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2SearchBlock.js +703 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseDetailBlock.js +41 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseTabsBlock.js +44 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CollectCommentsBlock.js +150 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ExtractDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenDetailBlock.js +102 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenTabsBlock.js +109 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34PersistDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ProcessSingleNoteBlock.js +114 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ValidateLinksBlock.js +90 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase3InteractBlock.js +1009 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase4MultiTabHarvestBlock.js +233 -0
- package/dist/modules/xiaohongshu/app/src/blocks/ReplyInteractBlock.js +291 -0
- package/dist/modules/xiaohongshu/app/src/blocks/XhsDiscoverFallbackBlock.js +240 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatchDsl.js +126 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatcher.js +99 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/evidence.js +27 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/sharding.js +42 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/xhsComments.js +270 -0
- package/dist/modules/xiaohongshu/app/src/index.js +9 -0
- package/dist/modules/xiaohongshu/app/src/utils/checkpoints.js +222 -0
- package/dist/modules/xiaohongshu/app/src/utils/controllerAction.js +43 -0
- package/dist/services/controller/src/controller.js +1476 -0
- package/dist/services/controller/src/index.js +2 -0
- package/dist/services/controller/src/payload-normalizer.js +129 -0
- package/dist/services/shared/heartbeat.js +120 -0
- package/dist/services/shared/lib/errorHandler.js +2 -0
- package/dist/services/shared/serviceProcessLogger.js +139 -0
- package/dist/services/unified-api/RemoteBrowserSession.js +176 -0
- package/dist/services/unified-api/RemoteSessionManager.js +148 -0
- package/dist/services/unified-api/container-operations-handler.js +115 -0
- package/dist/services/unified-api/server.js +652 -0
- package/dist/services/unified-api/state-registry.js +274 -0
- package/dist/services/unified-api/task-persistence.js +66 -0
- package/dist/services/unified-api/task-state.js +130 -0
- package/modules/camo-runtime/src/autoscript/action-providers/xhs/search.mjs +12 -5
- package/modules/xiaohongshu/app/pnpm-lock.yaml +24 -0
- package/package.json +37 -9
- package/.beads/README.md +0 -81
- package/.beads/config.yaml +0 -67
- package/.beads/interactions.jsonl +0 -0
- package/.beads/issues.jsonl +0 -180
- package/.beads/metadata.json +0 -4
- package/.claude/settings.local.json +0 -10
- package/.github/workflows/ci.yml +0 -55
- package/AGENTS.md +0 -253
- package/apps/desktop-console/README.md +0 -27
- package/apps/desktop-console/package-lock.json +0 -897
- package/apps/desktop-console/package.json +0 -20
- package/apps/desktop-console/scripts/build-and-install.mjs +0 -19
- package/apps/desktop-console/scripts/build.mjs +0 -45
- package/apps/desktop-console/scripts/test-preload.mjs +0 -13
- package/apps/desktop-console/src/main/config.mts +0 -26
- package/apps/desktop-console/src/main/core-daemon-manager.mts +0 -131
- package/apps/desktop-console/src/main/desktop-settings.mts +0 -267
- package/apps/desktop-console/src/main/heartbeat-watchdog.mts +0 -50
- package/apps/desktop-console/src/main/heartbeat-watchdog.test.mts +0 -68
- package/apps/desktop-console/src/main/index-streaming.test.mts +0 -20
- package/apps/desktop-console/src/main/index.mts +0 -980
- package/apps/desktop-console/src/main/profile-store.mts +0 -239
- package/apps/desktop-console/src/main/profile-store.test.mts +0 -54
- package/apps/desktop-console/src/main/state-bridge.mts +0 -114
- package/apps/desktop-console/src/main/task-state-types.ts +0 -32
- package/apps/desktop-console/src/renderer/hooks/use-task-state.mts +0 -120
- package/apps/desktop-console/src/renderer/index.mts +0 -133
- package/apps/desktop-console/src/renderer/index.test.mts +0 -34
- package/apps/desktop-console/src/renderer/path-helpers.mts +0 -46
- package/apps/desktop-console/src/renderer/path-helpers.test.mts +0 -14
- package/apps/desktop-console/src/renderer/tabs/debug.mts +0 -48
- package/apps/desktop-console/src/renderer/tabs/debug.test.mts +0 -22
- package/apps/desktop-console/src/renderer/tabs/logs.mts +0 -421
- package/apps/desktop-console/src/renderer/tabs/logs.test.mts +0 -27
- package/apps/desktop-console/src/renderer/tabs/preflight.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/preflight.test.mts +0 -33
- package/apps/desktop-console/src/renderer/tabs/profile-pool.mts +0 -213
- package/apps/desktop-console/src/renderer/tabs/results.mts +0 -171
- package/apps/desktop-console/src/renderer/tabs/run.test.mts +0 -63
- package/apps/desktop-console/src/renderer/tabs/runtime.mts +0 -151
- package/apps/desktop-console/src/renderer/tabs/settings.mts +0 -146
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/account-flow.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/guide-browser-check.mts +0 -56
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/helpers.mts +0 -262
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/layout-block.mts +0 -430
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/live-stats.mts +0 -847
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/run-flow.mts +0 -443
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu-state.mts +0 -425
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.mts +0 -497
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.test.mts +0 -291
- package/apps/desktop-console/src/renderer/ui-components.mts +0 -31
- package/docs/README_camoufox_chinese.md +0 -141
- package/docs/USAGE_V3.md +0 -163
- package/docs/arch/OCR_MACOS_PLUGIN.md +0 -39
- package/docs/arch/PORTS.md +0 -40
- package/docs/arch/REGRESSION_CHECKLIST.md +0 -121
- package/docs/arch/SEARCH_GATE.md +0 -224
- package/docs/arch/VIEWPORT_SAFETY.md +0 -182
- package/docs/arch/XIAOHONGSHU_OFFLINE_MOCK_DESIGN.md +0 -267
- package/docs/xiaohongshu-container-driven-summary.md +0 -221
- package/docs/xiaohongshu-full-collect-runbook.md +0 -134
- package/docs/xiaohongshu-next-steps.md +0 -228
- package/docs/xiaohongshu-quickstart.md +0 -73
- package/docs/xiaohongshu-workflow-summary.md +0 -227
- package/modules/container-registry/tests/container-registry.test.ts +0 -16
- package/modules/logging/tests/logging.test.ts +0 -38
- package/modules/operations/tests/operations.test.ts +0 -22
- package/modules/operations/tests/viewport-filter.test.ts +0 -161
- package/modules/operations/tests/visible-only.test.ts +0 -250
- package/modules/session-manager/tests/session-manager.test.ts +0 -23
- package/modules/state/src/atomic-json.test.ts +0 -30
- package/modules/state/src/paths.test.ts +0 -59
- package/modules/state/src/xiaohongshu-collect-state.test.ts +0 -259
- package/modules/workflow/blocks/AnchorVerificationBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/AnchorVerificationBlock.js.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.js.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.js.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.js.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.js.map +0 -1
- package/modules/workflow/blocks/helpers/downloadPaths.test.ts +0 -62
- package/modules/workflow/blocks/helpers/mergeXhsMarkdown.test.ts +0 -121
- package/modules/workflow/blocks/helpers/operationLogger.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/operationLogger.js.map +0 -1
- package/modules/workflow/blocks/helpers/persistedNotes.test.ts +0 -268
- package/modules/workflow/blocks/helpers/searchPageState.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/searchPageState.js.map +0 -1
- package/modules/workflow/blocks/helpers/targetCountMode.test.ts +0 -29
- package/modules/workflow/blocks/helpers/xhsCliArgs.test.ts +0 -75
- package/modules/workflow/tests/smartReply.test.ts +0 -32
- package/modules/xiaohongshu/app/src/blocks/Phase3Interact.matcher.test.ts +0 -33
- package/modules/xiaohongshu/app/src/utils/__tests__/checkpoints.test.ts +0 -141
- package/modules/xiaohongshu/app/tests/commentMatchDsl.test.ts +0 -50
- package/modules/xiaohongshu/app/tests/commentMatcher.test.ts +0 -46
- package/modules/xiaohongshu/app/tests/sharding.test.ts +0 -31
- package/package-scripts.json +0 -8
- package/runtime/infra/utils/README.md +0 -13
- package/runtime/infra/utils/scripts/README.md +0 -0
- package/runtime/infra/utils/scripts/development/eval-in-session.mjs +0 -40
- package/runtime/infra/utils/scripts/development/highlight-search-containers.mjs +0 -35
- package/runtime/infra/utils/scripts/service/kill-port.mjs +0 -24
- package/runtime/infra/utils/scripts/service/start-api.mjs +0 -39
- package/runtime/infra/utils/scripts/service/start-browser-service.mjs +0 -106
- package/runtime/infra/utils/scripts/service/stop-api.mjs +0 -18
- package/runtime/infra/utils/scripts/service/stop-browser-service.mjs +0 -104
- package/runtime/infra/utils/scripts/test-services.mjs +0 -94
- package/services/shared/heartbeat.test.ts +0 -102
- package/services/unified-api/__tests__/task-state.test.ts +0 -95
- package/sitecustomize.py +0 -19
- package/tests/README.md +0 -194
- package/tests/e2e/workflows/weibo-feed-extraction.test.ts +0 -171
- package/tests/fixtures/data/container-definitions.json +0 -67
- package/tests/fixtures/pages/simple-page.html +0 -69
- package/tests/integration/01-test-container-match.mjs +0 -188
- package/tests/integration/02-test-dom-branch.mjs +0 -161
- package/tests/integration/03-test-container-operation-system.mjs +0 -91
- package/tests/integration/05-test-container-lifecycle-events.mjs +0 -224
- package/tests/integration/05-test-container-lifecycle-with-events.mjs +0 -250
- package/tests/integration/06-test-container-dom-tree-drawing.mjs +0 -256
- package/tests/integration/07-test-weibo-container-lifecycle.mjs +0 -355
- package/tests/integration/08-test-weibo-feed-workflow.test.mjs +0 -164
- package/tests/integration/10-test-visual-analyzer.mjs +0 -312
- package/tests/integration/11-test-visual-loop.mjs +0 -284
- package/tests/integration/12-test-simple-visual-loop.mjs +0 -242
- package/tests/integration/13-test-visual-robust.mjs +0 -185
- package/tests/integration/14-test-visual-highlight-loop.mjs +0 -271
- package/tests/integration/inspect-page.mjs +0 -50
- package/tests/integration/run-all-tests.mjs +0 -95
- package/tests/patch_verification/CODEX_PATCH_TEST.md +0 -103
- package/tests/patch_verification/PHASE2_ANALYSIS.md +0 -179
- package/tests/patch_verification/PHASE2_OPTIMIZATION_REPORT.md +0 -55
- package/tests/patch_verification/PHASE2_TO_PHASE4_SUMMARY.md +0 -126
- package/tests/patch_verification/QUICK_TEST_SEQUENCE.md +0 -262
- package/tests/patch_verification/README.md +0 -143
- package/tests/patch_verification/RUN_TESTS.md +0 -60
- package/tests/patch_verification/TEST_EXECUTION.md +0 -99
- package/tests/patch_verification/TEST_PLAN.md +0 -328
- package/tests/patch_verification/TEST_RESULTS.md +0 -34
- package/tests/patch_verification/TOOL_TEST_PLAN.md +0 -48
- package/tests/patch_verification/run-tool-test.mjs +0 -121
- package/tests/patch_verification/temp_test_files/test01.txt +0 -1
- package/tests/patch_verification/temp_test_files/test02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test02_gnu.txt +0 -3
- package/tests/patch_verification/temp_test_files/test03.txt +0 -1
- package/tests/patch_verification/temp_test_files/test03_multiline.txt +0 -5
- package/tests/patch_verification/temp_test_files/test04_function.ts +0 -5
- package/tests/patch_verification/temp_test_files/test05_import.ts +0 -4
- package/tests/patch_verification/temp_test_files/test06_special_chars.txt +0 -4
- package/tests/patch_verification/temp_test_files/test07_indentation.ts +0 -5
- package/tests/patch_verification/temp_test_files/test08_mismatch.txt +0 -1
- package/tests/patch_verification/temp_test_files/test_add_02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test_simple.txt +0 -1
- package/tests/runner/TestReporter.mjs +0 -57
- package/tests/runner/TestRunner.mjs +0 -244
- package/tests/unit/commands/profile.test.mjs +0 -10
- package/tests/unit/container/change-notifier.test.mjs +0 -181
- package/tests/unit/lifecycle/session-registry.test.mjs +0 -135
- package/tests/unit/operations/registry.test.ts +0 -73
- package/tests/unit/utils/browser-service.test.mjs +0 -153
- package/tests/unit/utils/config.test.mjs +0 -166
- package/tests/unit/utils/fingerprint.test.mjs +0 -166
- package/tsconfig.json +0 -31
- package/tsconfig.services.json +0 -26
- /package/apps/desktop-console/{src → dist}/renderer/index.html +0 -0
- /package/apps/desktop-console/{src/renderer/tabs → dist/renderer}/run.mts +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
const HOME_LOG_ROOT = path.join(os.homedir(), '.webauto', 'logs');
|
|
5
|
+
export const DEBUG_LOG_FILE = path.join(HOME_LOG_ROOT, 'debug.jsonl');
|
|
6
|
+
const DEFAULT_SOURCES = {
|
|
7
|
+
browser: path.join(HOME_LOG_ROOT, 'browser.log'),
|
|
8
|
+
service: path.join(HOME_LOG_ROOT, 'service.log'),
|
|
9
|
+
orchestrator: path.join(HOME_LOG_ROOT, 'orchestrator.log'),
|
|
10
|
+
debug: DEBUG_LOG_FILE,
|
|
11
|
+
};
|
|
12
|
+
let debugReady = false;
|
|
13
|
+
function isDebugEnabled() {
|
|
14
|
+
return process.env.DEBUG === '1' || process.env.debug === '1';
|
|
15
|
+
}
|
|
16
|
+
function ensureDebugLogDir() {
|
|
17
|
+
if (debugReady)
|
|
18
|
+
return;
|
|
19
|
+
try {
|
|
20
|
+
fs.mkdirSync(path.dirname(DEBUG_LOG_FILE), { recursive: true });
|
|
21
|
+
debugReady = true;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// ignore
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function logDebug(module, event, data = {}) {
|
|
28
|
+
if (!isDebugEnabled())
|
|
29
|
+
return;
|
|
30
|
+
ensureDebugLogDir();
|
|
31
|
+
const entry = {
|
|
32
|
+
ts: Date.now(),
|
|
33
|
+
level: 'debug',
|
|
34
|
+
module,
|
|
35
|
+
event,
|
|
36
|
+
data,
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
fs.appendFileSync(DEBUG_LOG_FILE, `${JSON.stringify(entry)}\n`);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// ignore
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function logWorkflowEvent(event) {
|
|
46
|
+
logDebug('workflow', event.status, event);
|
|
47
|
+
}
|
|
48
|
+
export function resolveLogFile(options) {
|
|
49
|
+
if (options.file) {
|
|
50
|
+
return path.resolve(options.file);
|
|
51
|
+
}
|
|
52
|
+
if (options.session) {
|
|
53
|
+
return path.join(HOME_LOG_ROOT, `session-${options.session}.log`);
|
|
54
|
+
}
|
|
55
|
+
if (options.source && DEFAULT_SOURCES[options.source]) {
|
|
56
|
+
return DEFAULT_SOURCES[options.source];
|
|
57
|
+
}
|
|
58
|
+
return DEFAULT_SOURCES.browser;
|
|
59
|
+
}
|
|
60
|
+
export async function streamLog(options = {}) {
|
|
61
|
+
const file = resolveLogFile(options);
|
|
62
|
+
const maxLines = options.maxLines ?? 200;
|
|
63
|
+
const lines = await readTailLines(file, maxLines);
|
|
64
|
+
return { file, lines };
|
|
65
|
+
}
|
|
66
|
+
export async function flushLog(options = {}, truncate = false) {
|
|
67
|
+
const file = resolveLogFile(options);
|
|
68
|
+
const lines = await readTailLines(file, Number.MAX_SAFE_INTEGER);
|
|
69
|
+
if (truncate) {
|
|
70
|
+
await fs.promises
|
|
71
|
+
.truncate(file, 0)
|
|
72
|
+
.catch(() => Promise.resolve());
|
|
73
|
+
}
|
|
74
|
+
return { file, lines };
|
|
75
|
+
}
|
|
76
|
+
async function readTailLines(file, maxLines) {
|
|
77
|
+
try {
|
|
78
|
+
const content = await fs.promises.readFile(file, 'utf-8');
|
|
79
|
+
const lines = content.split(/\r?\n/).filter((line) => line.length > 0);
|
|
80
|
+
if (lines.length <= maxLines) {
|
|
81
|
+
return lines;
|
|
82
|
+
}
|
|
83
|
+
return lines.slice(-maxLines);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { registerOperation } from './registry.js';
|
|
2
|
+
import { highlightOperation } from './operations/highlight.js';
|
|
3
|
+
import { scrollOperation } from './operations/scroll.js';
|
|
4
|
+
import { mouseMoveOperation, mouseClickOperation } from './system/mouse.js';
|
|
5
|
+
import { extractOperation } from './operations/extract.js';
|
|
6
|
+
import { clickOperation } from './operations/click.js';
|
|
7
|
+
import { typeOperation } from './operations/type.js';
|
|
8
|
+
import { findChildOperation } from './operations/find-child.js';
|
|
9
|
+
import { navigateOperation } from './operations/navigate.js';
|
|
10
|
+
import { keyOperation } from './operations/key.js';
|
|
11
|
+
let initialized = false;
|
|
12
|
+
export function ensureBuiltinOperations() {
|
|
13
|
+
if (initialized)
|
|
14
|
+
return;
|
|
15
|
+
registerOperation(highlightOperation);
|
|
16
|
+
registerOperation(scrollOperation);
|
|
17
|
+
registerOperation(mouseMoveOperation);
|
|
18
|
+
registerOperation(mouseClickOperation);
|
|
19
|
+
registerOperation(extractOperation);
|
|
20
|
+
registerOperation(clickOperation);
|
|
21
|
+
registerOperation(typeOperation);
|
|
22
|
+
registerOperation(keyOperation);
|
|
23
|
+
registerOperation(findChildOperation);
|
|
24
|
+
registerOperation(navigateOperation);
|
|
25
|
+
initialized = true;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=builtin.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { getOperation } from './registry.js';
|
|
2
|
+
function hasCapability(container, required) {
|
|
3
|
+
if (!required || !required.length) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
const capabilitySet = new Set((container.capabilities || []).map((c) => c.toLowerCase()));
|
|
7
|
+
return required.every((cap) => capabilitySet.has(cap.toLowerCase()));
|
|
8
|
+
}
|
|
9
|
+
function isOperationListed(container, operationId) {
|
|
10
|
+
const declared = container.operations || [];
|
|
11
|
+
return declared.some((item) => (item?.type || item?.id) === operationId);
|
|
12
|
+
}
|
|
13
|
+
export function validateContainerOperations(container) {
|
|
14
|
+
const issues = [];
|
|
15
|
+
const operations = container.operations || [];
|
|
16
|
+
if (!operations.length) {
|
|
17
|
+
return issues;
|
|
18
|
+
}
|
|
19
|
+
for (const entry of operations) {
|
|
20
|
+
const operationId = entry?.type || entry?.id;
|
|
21
|
+
if (!operationId) {
|
|
22
|
+
issues.push({
|
|
23
|
+
containerId: container.id,
|
|
24
|
+
operationId: 'unknown',
|
|
25
|
+
level: 'error',
|
|
26
|
+
reason: 'operation entry missing type/id',
|
|
27
|
+
});
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const operation = getOperation(operationId);
|
|
31
|
+
if (!operation) {
|
|
32
|
+
issues.push({
|
|
33
|
+
containerId: container.id,
|
|
34
|
+
operationId,
|
|
35
|
+
level: 'error',
|
|
36
|
+
reason: 'operation is not registered in OperationRegistry',
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const required = operation.requiredCapabilities;
|
|
41
|
+
if (!hasCapability(container, required)) {
|
|
42
|
+
issues.push({
|
|
43
|
+
containerId: container.id,
|
|
44
|
+
operationId,
|
|
45
|
+
level: 'error',
|
|
46
|
+
reason: `missing capabilities: ${required?.join(', ') || ''}`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return issues;
|
|
51
|
+
}
|
|
52
|
+
export function assertContainerOperations(container) {
|
|
53
|
+
const issues = validateContainerOperations(container);
|
|
54
|
+
if (issues.length) {
|
|
55
|
+
const summary = issues
|
|
56
|
+
.map((issue) => `${issue.containerId}:${issue.operationId} -> ${issue.reason}`)
|
|
57
|
+
.join('\n');
|
|
58
|
+
const error = new Error(`Container operation validation failed:\n${summary}`);
|
|
59
|
+
error.issues = issues;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function containerAllowsOperation(container, operationId) {
|
|
64
|
+
const operation = getOperation(operationId);
|
|
65
|
+
if (!operation) {
|
|
66
|
+
throw new Error(`Unknown operation: ${operationId}`);
|
|
67
|
+
}
|
|
68
|
+
if (!hasCapability(container, operation.requiredCapabilities)) {
|
|
69
|
+
throw new Error(`Operation ${operationId} requires capabilities ${operation.requiredCapabilities?.join(', ') || ''}`);
|
|
70
|
+
}
|
|
71
|
+
if (container.operations && container.operations.length && !isOperationListed(container, operationId)) {
|
|
72
|
+
throw new Error(`Operation ${operationId} is not declared in container ${container.id}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=container-binding.js.map
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { highlightOperation } from './operations/highlight.js';
|
|
2
|
+
import { scrollOperation } from './operations/scroll.js';
|
|
3
|
+
import { mouseMoveOperation, mouseClickOperation } from './system/mouse.js';
|
|
4
|
+
import { extractOperation } from './operations/extract.js';
|
|
5
|
+
import { clickOperation } from './operations/click.js';
|
|
6
|
+
import { findChildOperation } from './operations/find-child.js';
|
|
7
|
+
import { typeOperation } from './operations/type.js';
|
|
8
|
+
import { navigateOperation } from './operations/navigate.js';
|
|
9
|
+
import { keyOperation } from './operations/key.js';
|
|
10
|
+
import { ContainerRegistry } from '../../container-registry/src/index.js';
|
|
11
|
+
function resolveInputMode() {
|
|
12
|
+
const raw = String(process.env.WEBAUTO_INPUT_MODE || 'system').trim().toLowerCase();
|
|
13
|
+
return raw === 'protocol' ? 'protocol' : 'system';
|
|
14
|
+
}
|
|
15
|
+
export class ContainerExecutor {
|
|
16
|
+
operations = new Map();
|
|
17
|
+
registry = new ContainerRegistry();
|
|
18
|
+
constructor() {
|
|
19
|
+
this.initializeBuiltinOperations();
|
|
20
|
+
}
|
|
21
|
+
initializeBuiltinOperations() {
|
|
22
|
+
this.registerOperation(highlightOperation);
|
|
23
|
+
this.registerOperation(scrollOperation);
|
|
24
|
+
this.registerOperation(mouseMoveOperation);
|
|
25
|
+
this.registerOperation(mouseClickOperation);
|
|
26
|
+
this.registerOperation(extractOperation);
|
|
27
|
+
this.registerOperation(clickOperation);
|
|
28
|
+
this.registerOperation(findChildOperation);
|
|
29
|
+
this.registerOperation(typeOperation);
|
|
30
|
+
this.registerOperation(keyOperation);
|
|
31
|
+
this.registerOperation(navigateOperation);
|
|
32
|
+
}
|
|
33
|
+
registerOperation(config) {
|
|
34
|
+
this.operations.set(config.id, config);
|
|
35
|
+
}
|
|
36
|
+
async execute(containerId, operationId, config, context) {
|
|
37
|
+
const operation = this.operations.get(operationId);
|
|
38
|
+
if (!operation) {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: `Unknown operation: ${operationId}`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// 合并容器定义中的默认 operation config(调用方 config 优先)
|
|
45
|
+
config = await this.mergeContainerOperationConfig(containerId, operationId, config, context);
|
|
46
|
+
const inputMode = resolveInputMode();
|
|
47
|
+
const modeControlledOps = new Set(['click', 'type', 'key', 'scroll']);
|
|
48
|
+
if (modeControlledOps.has(operationId)) {
|
|
49
|
+
if (inputMode === 'protocol') {
|
|
50
|
+
// Protocol mode bypasses OS-level input so actions can run without window focus.
|
|
51
|
+
config = { ...config, useSystemMouse: false };
|
|
52
|
+
}
|
|
53
|
+
else if (typeof config.useSystemMouse !== 'boolean') {
|
|
54
|
+
config = { ...config, useSystemMouse: true };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// click:如果调用方明确给了坐标/bbox,则优先走坐标点击,避免被容器默认 selector 覆盖
|
|
58
|
+
if (operationId === 'click' &&
|
|
59
|
+
config &&
|
|
60
|
+
typeof config === 'object' &&
|
|
61
|
+
(Boolean(config.bbox) ||
|
|
62
|
+
(typeof config.x === 'number' && typeof config.y === 'number'))) {
|
|
63
|
+
const next = { ...config };
|
|
64
|
+
delete next.selector;
|
|
65
|
+
config = next;
|
|
66
|
+
}
|
|
67
|
+
// extract:注入容器 extractors(兼容 container-library 的 extract operation fields: string[])
|
|
68
|
+
if (operationId === 'extract' && config && typeof config === 'object' && !('extractors' in config)) {
|
|
69
|
+
try {
|
|
70
|
+
const { container } = await this.getContainerForContext(containerId, context);
|
|
71
|
+
const extractors = container?.extractors;
|
|
72
|
+
if (extractors && typeof extractors === 'object' && !Array.isArray(extractors)) {
|
|
73
|
+
config = { ...config, extractors };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// ignore
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// 如果操作需要 selector,则从容器定义中补齐
|
|
81
|
+
const isClickWithCoordinates = operationId === 'click' &&
|
|
82
|
+
config &&
|
|
83
|
+
typeof config === 'object' &&
|
|
84
|
+
(Boolean(config.bbox) ||
|
|
85
|
+
(typeof config.x === 'number' && typeof config.y === 'number'));
|
|
86
|
+
if (this.requiresSelector(operation) && !config.selector && !isClickWithCoordinates) {
|
|
87
|
+
const selector = await this.getSelectorForContainer(containerId, context);
|
|
88
|
+
if (!selector) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: `Cannot find selector for container: ${containerId}`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
config = { ...config, selector };
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
return await operation.run(context, config);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
error: error.message || String(error)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
requiresSelector(operation) {
|
|
107
|
+
return ['highlight', 'click', 'extract', 'type', 'input', 'scroll', 'key'].includes(operation.id);
|
|
108
|
+
}
|
|
109
|
+
async mergeContainerOperationConfig(containerId, operationId, config, context) {
|
|
110
|
+
const { url, container } = await this.getContainerForContext(containerId, context);
|
|
111
|
+
if (!url || !container)
|
|
112
|
+
return config;
|
|
113
|
+
const ops = Array.isArray(container.operations) ? container.operations : [];
|
|
114
|
+
const defaultOp = ops.find((op) => (op?.type || op?.id) === operationId);
|
|
115
|
+
const baseConfig = defaultOp?.config && typeof defaultOp.config === 'object' ? defaultOp.config : null;
|
|
116
|
+
if (!baseConfig)
|
|
117
|
+
return config;
|
|
118
|
+
return { ...baseConfig, ...config };
|
|
119
|
+
}
|
|
120
|
+
async getSelectorForContainer(containerId, context) {
|
|
121
|
+
const { container } = await this.getContainerForContext(containerId, context);
|
|
122
|
+
if (!container || !container.selectors || !container.selectors.length) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const primary = container.selectors.find((s) => s.variant === 'primary') || container.selectors[0];
|
|
126
|
+
return primary?.css || null;
|
|
127
|
+
}
|
|
128
|
+
async getContainerForContext(containerId, context) {
|
|
129
|
+
const url = await context.page.evaluate(() => window.location.href);
|
|
130
|
+
if (!url) {
|
|
131
|
+
return { url: null, container: null };
|
|
132
|
+
}
|
|
133
|
+
await this.registry.load();
|
|
134
|
+
const containers = this.registry.getContainersForUrl(url);
|
|
135
|
+
return { url, container: containers[containerId] || null };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Singleton instance
|
|
139
|
+
let executorInstance = null;
|
|
140
|
+
export function getContainerExecutor() {
|
|
141
|
+
if (!executorInstance) {
|
|
142
|
+
executorInstance = new ContainerExecutor();
|
|
143
|
+
}
|
|
144
|
+
return executorInstance;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
async function runClick(ctx, config) {
|
|
2
|
+
const waitFor = config.waitFor || 0;
|
|
3
|
+
if (waitFor > 0) {
|
|
4
|
+
await new Promise((r) => setTimeout(r, waitFor));
|
|
5
|
+
}
|
|
6
|
+
if (config.selector) {
|
|
7
|
+
// 方案 A: 通过 selector + index 点击(强制系统级点击,避免 DOM click)
|
|
8
|
+
const index = Number.isFinite(config.index) ? Math.max(0, Math.floor(config.index)) : 0;
|
|
9
|
+
const useSystemMouse = config.useSystemMouse !== false;
|
|
10
|
+
const visibleOnly = config.visibleOnly === true;
|
|
11
|
+
const fullyVisible = config.fullyVisible === true;
|
|
12
|
+
const anchor = config.anchor ?? null;
|
|
13
|
+
const protocolMouse = ctx.page?.mouse;
|
|
14
|
+
if (!useSystemMouse && (!protocolMouse || typeof protocolMouse.click !== 'function')) {
|
|
15
|
+
return { success: false, error: 'protocol mouse not available' };
|
|
16
|
+
}
|
|
17
|
+
const target = typeof config.target === 'string' ? config.target.trim() : '';
|
|
18
|
+
const info = await ctx.page.evaluate(({ sel, idx, tgt, visibleOnly: vOnly, fullyVisible: fOnly, anchor: anchorPoint }) => {
|
|
19
|
+
const isVisible = (el) => {
|
|
20
|
+
const r = el.getBoundingClientRect();
|
|
21
|
+
return (r.width > 0 &&
|
|
22
|
+
r.height > 0 &&
|
|
23
|
+
r.bottom > 0 &&
|
|
24
|
+
r.top < window.innerHeight &&
|
|
25
|
+
r.right > 0 &&
|
|
26
|
+
r.left < window.innerWidth);
|
|
27
|
+
};
|
|
28
|
+
const isFullyVisible = (el) => {
|
|
29
|
+
const r = el.getBoundingClientRect();
|
|
30
|
+
return (r.width > 0 &&
|
|
31
|
+
r.height > 0 &&
|
|
32
|
+
r.top >= 0 &&
|
|
33
|
+
r.left >= 0 &&
|
|
34
|
+
r.bottom <= window.innerHeight &&
|
|
35
|
+
r.right <= window.innerWidth);
|
|
36
|
+
};
|
|
37
|
+
const allNodes = Array.from(document.querySelectorAll(sel));
|
|
38
|
+
const nodes = vOnly || fOnly ? allNodes.filter((n) => isVisible(n)) : allNodes;
|
|
39
|
+
const root = nodes[idx];
|
|
40
|
+
if (!root)
|
|
41
|
+
return null;
|
|
42
|
+
let el = root;
|
|
43
|
+
if (tgt) {
|
|
44
|
+
if (tgt === 'self') {
|
|
45
|
+
el = root;
|
|
46
|
+
}
|
|
47
|
+
else if (tgt === 'img') {
|
|
48
|
+
el = root.querySelector('img') || root;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
el = root.querySelector(tgt) || root;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const r = el.getBoundingClientRect();
|
|
55
|
+
const visible = r.width > 0 && r.height > 0 && r.y < window.innerHeight && r.y + r.height > 0;
|
|
56
|
+
if (!visible)
|
|
57
|
+
return { visible: false, clickPoints: [], anchorMatch: false };
|
|
58
|
+
if (fOnly && !isFullyVisible(el)) {
|
|
59
|
+
return { visible: false, clickPoints: [], anchorMatch: false };
|
|
60
|
+
}
|
|
61
|
+
if (anchorPoint) {
|
|
62
|
+
const hit = document.elementFromPoint(anchorPoint.x, anchorPoint.y);
|
|
63
|
+
if (!hit || (hit !== el && !el.contains(hit))) {
|
|
64
|
+
return { visible: false, clickPoints: [], anchorMatch: false };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const x1 = Math.max(0, r.left);
|
|
68
|
+
const y1 = Math.max(0, r.top);
|
|
69
|
+
const x2 = Math.min(window.innerWidth, r.right);
|
|
70
|
+
const y2 = Math.min(window.innerHeight, r.bottom);
|
|
71
|
+
const mx = Math.round((x1 + x2) / 2);
|
|
72
|
+
const my = Math.round((y1 + y2) / 2);
|
|
73
|
+
const pad = 10;
|
|
74
|
+
const points = [
|
|
75
|
+
{ x: mx, y: my },
|
|
76
|
+
{ x: Math.round(x1 + pad), y: my },
|
|
77
|
+
{ x: Math.round(x2 - pad), y: my },
|
|
78
|
+
{ x: mx, y: Math.round(y1 + pad) },
|
|
79
|
+
{ x: mx, y: Math.round(y2 - pad) },
|
|
80
|
+
];
|
|
81
|
+
const clickPoints = [];
|
|
82
|
+
for (const p of points) {
|
|
83
|
+
if (!Number.isFinite(p.x) || !Number.isFinite(p.y))
|
|
84
|
+
continue;
|
|
85
|
+
if (p.x < 0 || p.y < 0 || p.x > window.innerWidth || p.y > window.innerHeight)
|
|
86
|
+
continue;
|
|
87
|
+
const hit = document.elementFromPoint(p.x, p.y);
|
|
88
|
+
if (hit && (hit === el || el.contains(hit))) {
|
|
89
|
+
clickPoints.push(p);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!clickPoints.length) {
|
|
93
|
+
// 兜底:至少点一次可见交集的中心
|
|
94
|
+
clickPoints.push({ x: mx, y: my });
|
|
95
|
+
}
|
|
96
|
+
return { visible: true, clickPoints, anchorMatch: Boolean(anchorPoint) };
|
|
97
|
+
}, { sel: config.selector, idx: index, tgt: target, visibleOnly, fullyVisible, anchor });
|
|
98
|
+
if (!info || !info.visible || !Array.isArray(info.clickPoints) || info.clickPoints.length === 0) {
|
|
99
|
+
return { success: false, error: 'element not visible' };
|
|
100
|
+
}
|
|
101
|
+
if (useSystemMouse && !ctx.systemInput?.mouseClick) {
|
|
102
|
+
return { success: false, error: 'system mouse not available' };
|
|
103
|
+
}
|
|
104
|
+
const clickPoints = info.clickPoints;
|
|
105
|
+
// 优先点击视口内且命中目标元素的点,避免“元素部分可见但中心离屏”导致点错
|
|
106
|
+
for (const p of clickPoints) {
|
|
107
|
+
const x = Math.round(p.x);
|
|
108
|
+
const y = Math.round(p.y);
|
|
109
|
+
if (useSystemMouse) {
|
|
110
|
+
await ctx.systemInput.mouseClick(x, y);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
await protocolMouse.click(x, y);
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
return { success: true, inputMode: useSystemMouse ? 'system' : 'protocol' };
|
|
118
|
+
}
|
|
119
|
+
else if (config.bbox) {
|
|
120
|
+
// 方案 B: 通过 bbox 点击(使用系统鼠标)
|
|
121
|
+
const cx = Math.round((config.bbox.x1 + config.bbox.x2) / 2);
|
|
122
|
+
const cy = Math.round((config.bbox.y1 + config.bbox.y2) / 2);
|
|
123
|
+
const useSystemMouse = config.useSystemMouse !== false;
|
|
124
|
+
const protocolMouse = ctx.page?.mouse;
|
|
125
|
+
if (useSystemMouse) {
|
|
126
|
+
if (!ctx.systemInput?.mouseClick) {
|
|
127
|
+
return { success: false, error: 'system mouse not available' };
|
|
128
|
+
}
|
|
129
|
+
await ctx.systemInput.mouseClick(cx, cy);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (!protocolMouse || typeof protocolMouse.click !== 'function') {
|
|
133
|
+
return { success: false, error: 'protocol mouse not available' };
|
|
134
|
+
}
|
|
135
|
+
await protocolMouse.click(cx, cy);
|
|
136
|
+
}
|
|
137
|
+
return { success: true, inputMode: useSystemMouse ? 'system' : 'protocol' };
|
|
138
|
+
}
|
|
139
|
+
else if (typeof config.x === 'number' && typeof config.y === 'number') {
|
|
140
|
+
// 方案 C: 直接通过坐标点击
|
|
141
|
+
const useSystemMouse = config.useSystemMouse !== false;
|
|
142
|
+
const protocolMouse = ctx.page?.mouse;
|
|
143
|
+
if (useSystemMouse) {
|
|
144
|
+
if (!ctx.systemInput?.mouseClick) {
|
|
145
|
+
return { success: false, error: 'system mouse not available' };
|
|
146
|
+
}
|
|
147
|
+
await ctx.systemInput.mouseClick(config.x, config.y);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
if (!protocolMouse || typeof protocolMouse.click !== 'function') {
|
|
151
|
+
return { success: false, error: 'protocol mouse not available' };
|
|
152
|
+
}
|
|
153
|
+
await protocolMouse.click(config.x, config.y);
|
|
154
|
+
}
|
|
155
|
+
return { success: true, inputMode: useSystemMouse ? 'system' : 'protocol' };
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return { success: false, error: 'selector or bbox required' };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export const clickOperation = {
|
|
162
|
+
id: 'click',
|
|
163
|
+
description: 'Click element by selector or bbox',
|
|
164
|
+
requiredCapabilities: ['click'],
|
|
165
|
+
run: runClick,
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=click.js.map
|