@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.
- 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 +263 -15
- 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 +38 -10
- 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,474 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* openDetailViewport.ts
|
|
3
|
+
*
|
|
4
|
+
* 视口与 DOM 相关的辅助工具:
|
|
5
|
+
* - 视口指标获取
|
|
6
|
+
* - 滚动容器推断
|
|
7
|
+
* - 滚动操作
|
|
8
|
+
* - 元素在视口内的确保(highlight + scroll 循环)
|
|
9
|
+
* - 封面 Rect 计算(by index / by noteId)
|
|
10
|
+
* - 点在封面内验证
|
|
11
|
+
* - Rect 高亮
|
|
12
|
+
* - 视口诊断信息 dump
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* 创建 OpenDetail 专用的视口工具集合
|
|
16
|
+
*/
|
|
17
|
+
export function createOpenDetailViewportTools(config) {
|
|
18
|
+
const { controllerAction, profile, serviceUrl } = config;
|
|
19
|
+
async function getViewportMetrics() {
|
|
20
|
+
try {
|
|
21
|
+
const result = await controllerAction('browser:execute', {
|
|
22
|
+
profile,
|
|
23
|
+
script: '({ innerHeight: window.innerHeight || 0, innerWidth: window.innerWidth || 0 })',
|
|
24
|
+
});
|
|
25
|
+
const payload = result?.result ?? result?.data?.result ?? result;
|
|
26
|
+
return {
|
|
27
|
+
innerHeight: Number(payload?.innerHeight ?? 0),
|
|
28
|
+
innerWidth: Number(payload?.innerWidth ?? 0),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { innerHeight: 0, innerWidth: 0 };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function inferScrollContainerId(itemContainerId) {
|
|
36
|
+
if (itemContainerId.includes('xiaohongshu_search.search_result_item')) {
|
|
37
|
+
return 'xiaohongshu_search.search_result_list';
|
|
38
|
+
}
|
|
39
|
+
if (itemContainerId.includes('xiaohongshu_home.feed_item')) {
|
|
40
|
+
return 'xiaohongshu_home.feed_list';
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
async function scrollTowardVisibility(direction, amount, containerId) {
|
|
45
|
+
const scrollContainerId = inferScrollContainerId(containerId);
|
|
46
|
+
const scrollAmount = Math.min(800, Math.max(120, Math.floor(Math.abs(amount))));
|
|
47
|
+
// 首选:列表容器滚动(系统滚轮/键盘),避免页面级 JS 滚动
|
|
48
|
+
if (scrollContainerId) {
|
|
49
|
+
try {
|
|
50
|
+
const op = await controllerAction('container:operation', {
|
|
51
|
+
containerId: scrollContainerId,
|
|
52
|
+
operationId: 'scroll',
|
|
53
|
+
sessionId: profile,
|
|
54
|
+
config: { direction, amount: scrollAmount },
|
|
55
|
+
});
|
|
56
|
+
const payload = op?.data ?? op;
|
|
57
|
+
const ok = Boolean(payload?.success ?? payload?.data?.success ?? op?.success);
|
|
58
|
+
if (ok) {
|
|
59
|
+
await new Promise((r) => setTimeout(r, 900));
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// fall through
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// 兜底:PageUp/PageDown(系统级)
|
|
68
|
+
try {
|
|
69
|
+
await controllerAction('keyboard:press', {
|
|
70
|
+
profileId: profile,
|
|
71
|
+
key: direction === 'up' ? 'PageUp' : 'PageDown',
|
|
72
|
+
});
|
|
73
|
+
await new Promise((r) => setTimeout(r, 900));
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 通过 container:operation highlight + rect 提取
|
|
82
|
+
*/
|
|
83
|
+
async function highlightByIndex(containerId, index, duration = 1200) {
|
|
84
|
+
const highlightResp = await controllerAction('container:operation', {
|
|
85
|
+
containerId,
|
|
86
|
+
operationId: 'highlight',
|
|
87
|
+
sessionId: profile,
|
|
88
|
+
config: { index, duration },
|
|
89
|
+
});
|
|
90
|
+
return rectFromOperationResponse(highlightResp);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 通过 selector highlight + rect 提取
|
|
94
|
+
*/
|
|
95
|
+
async function highlightBySelector(containerId, selector, duration = 1200) {
|
|
96
|
+
const highlightResp = await controllerAction('container:operation', {
|
|
97
|
+
containerId,
|
|
98
|
+
operationId: 'highlight',
|
|
99
|
+
sessionId: profile,
|
|
100
|
+
config: { selector, index: 0, target: 'self', duration },
|
|
101
|
+
});
|
|
102
|
+
return rectFromOperationResponse(highlightResp);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 确保 selector 对应的元素完全在视口内(通过 highlight + scroll 循环)
|
|
106
|
+
*/
|
|
107
|
+
async function ensureSelectorFullyInViewport(containerId, selector) {
|
|
108
|
+
const viewport = await getViewportMetrics();
|
|
109
|
+
const innerHeight = viewport.innerHeight || 0;
|
|
110
|
+
let rect = await highlightBySelector(containerId, selector, 800);
|
|
111
|
+
if (!rect)
|
|
112
|
+
return undefined;
|
|
113
|
+
if (!innerHeight)
|
|
114
|
+
return rect;
|
|
115
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
116
|
+
const top = rect.y;
|
|
117
|
+
const bottom = rect.y + rect.height;
|
|
118
|
+
const fullyVisible = rect.width > 0 && rect.height > 0 && top >= 0 && bottom <= innerHeight;
|
|
119
|
+
if (fullyVisible)
|
|
120
|
+
return rect;
|
|
121
|
+
const direction = top < 0 ? 'up' : 'down';
|
|
122
|
+
const delta = top < 0 ? Math.abs(top) : Math.max(0, bottom - innerHeight);
|
|
123
|
+
const ok = await scrollTowardVisibility(direction, Math.min(800, delta + 160), containerId);
|
|
124
|
+
if (!ok)
|
|
125
|
+
break;
|
|
126
|
+
rect = await highlightBySelector(containerId, selector, 800);
|
|
127
|
+
if (!rect)
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
return rect;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 确保 domIndex 对应的元素完全在视口内
|
|
134
|
+
*/
|
|
135
|
+
async function ensureDomIndexFullyInViewport(containerId, index) {
|
|
136
|
+
const viewport = await getViewportMetrics();
|
|
137
|
+
const innerHeight = viewport.innerHeight || 0;
|
|
138
|
+
let rect = await highlightByIndex(containerId, index, 800);
|
|
139
|
+
if (!rect)
|
|
140
|
+
return undefined;
|
|
141
|
+
if (!innerHeight)
|
|
142
|
+
return rect;
|
|
143
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
144
|
+
const top = rect.y;
|
|
145
|
+
const bottom = rect.y + rect.height;
|
|
146
|
+
const fullyVisible = rect.width > 0 && rect.height > 0 && top >= 0 && bottom <= innerHeight;
|
|
147
|
+
if (fullyVisible)
|
|
148
|
+
return rect;
|
|
149
|
+
const direction = top < 0 ? 'up' : 'down';
|
|
150
|
+
const delta = top < 0 ? Math.abs(top) : Math.max(0, bottom - innerHeight);
|
|
151
|
+
const ok = await scrollTowardVisibility(direction, Math.min(800, delta + 160), containerId);
|
|
152
|
+
if (!ok)
|
|
153
|
+
break;
|
|
154
|
+
rect = await highlightByIndex(containerId, index, 800);
|
|
155
|
+
if (!rect)
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
return rect;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 通过 domIndex 计算封面(a.cover)的 Rect
|
|
162
|
+
*/
|
|
163
|
+
async function computeCoverRectByIndex(index) {
|
|
164
|
+
try {
|
|
165
|
+
const res = await controllerAction('browser:execute', {
|
|
166
|
+
profile,
|
|
167
|
+
script: `(() => {
|
|
168
|
+
const cards = Array.from(document.querySelectorAll('.note-item'));
|
|
169
|
+
const card = cards[${index}];
|
|
170
|
+
if (!card) return null;
|
|
171
|
+
const cover = card.querySelector('a.cover');
|
|
172
|
+
if (!cover) return null;
|
|
173
|
+
const media = cover.querySelector('img,video');
|
|
174
|
+
const target = media || cover;
|
|
175
|
+
const r = target.getBoundingClientRect();
|
|
176
|
+
if (!r || !r.width || !r.height) return null;
|
|
177
|
+
const innerH = window.innerHeight || 0;
|
|
178
|
+
const inViewport = innerH ? (r.bottom > 0 && r.top < innerH) : true;
|
|
179
|
+
return { x: r.x, y: r.y, width: r.width, height: r.height, inViewport };
|
|
180
|
+
})()`,
|
|
181
|
+
});
|
|
182
|
+
const payload = res?.result ?? res?.data?.result ?? res;
|
|
183
|
+
if (payload &&
|
|
184
|
+
typeof payload.x === 'number' &&
|
|
185
|
+
typeof payload.y === 'number' &&
|
|
186
|
+
typeof payload.width === 'number' &&
|
|
187
|
+
typeof payload.height === 'number') {
|
|
188
|
+
return { x: payload.x, y: payload.y, width: payload.width, height: payload.height };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// ignore
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 通过 domIndex 计算卡片(.note-item)的 Rect
|
|
198
|
+
* 用于“禁止点击显示不全的 note item”场景:必须确保整个卡片完全在视口安全区内。
|
|
199
|
+
*/
|
|
200
|
+
async function computeCardRectByIndex(index) {
|
|
201
|
+
try {
|
|
202
|
+
const res = await controllerAction('browser:execute', {
|
|
203
|
+
profile,
|
|
204
|
+
script: `(() => {
|
|
205
|
+
const cards = Array.from(document.querySelectorAll('.note-item'));
|
|
206
|
+
const card = cards[${index}];
|
|
207
|
+
if (!card) return null;
|
|
208
|
+
const r = card.getBoundingClientRect();
|
|
209
|
+
if (!r || !r.width || !r.height) return null;
|
|
210
|
+
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
|
211
|
+
})()`,
|
|
212
|
+
});
|
|
213
|
+
const payload = res?.result ?? res?.data?.result ?? res;
|
|
214
|
+
if (payload &&
|
|
215
|
+
typeof payload.x === 'number' &&
|
|
216
|
+
typeof payload.y === 'number' &&
|
|
217
|
+
typeof payload.width === 'number' &&
|
|
218
|
+
typeof payload.height === 'number') {
|
|
219
|
+
return { x: payload.x, y: payload.y, width: payload.width, height: payload.height };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// ignore
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* 通过 noteId 精确查找封面(a.cover)的 Rect
|
|
229
|
+
*/
|
|
230
|
+
async function computeCoverRectByNoteId(noteId) {
|
|
231
|
+
const nid = String(noteId || '').trim();
|
|
232
|
+
if (!nid)
|
|
233
|
+
return undefined;
|
|
234
|
+
try {
|
|
235
|
+
const res = await controllerAction('browser:execute', {
|
|
236
|
+
profile,
|
|
237
|
+
script: `(() => {
|
|
238
|
+
const noteId = ${JSON.stringify(nid)};
|
|
239
|
+
const cards = Array.from(document.querySelectorAll('.note-item'));
|
|
240
|
+
for (const card of cards) {
|
|
241
|
+
try {
|
|
242
|
+
const cover = card.querySelector('a.cover');
|
|
243
|
+
if (!cover) continue;
|
|
244
|
+
const href = cover.getAttribute('href') || cover.href || '';
|
|
245
|
+
if (!href || href.indexOf(noteId) === -1) continue;
|
|
246
|
+
const media = cover.querySelector('img,video');
|
|
247
|
+
const target = media || cover;
|
|
248
|
+
const r = target.getBoundingClientRect();
|
|
249
|
+
if (!r || !r.width || !r.height) continue;
|
|
250
|
+
const innerH = window.innerHeight || 0;
|
|
251
|
+
const inViewport = innerH ? (r.bottom > 0 && r.top < innerH) : true;
|
|
252
|
+
return { x: r.x, y: r.y, width: r.width, height: r.height, inViewport };
|
|
253
|
+
} catch (_) {}
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
})()`,
|
|
257
|
+
});
|
|
258
|
+
const payload = res?.result ?? res?.data?.result ?? res;
|
|
259
|
+
if (payload &&
|
|
260
|
+
typeof payload.x === 'number' &&
|
|
261
|
+
typeof payload.y === 'number' &&
|
|
262
|
+
typeof payload.width === 'number' &&
|
|
263
|
+
typeof payload.height === 'number') {
|
|
264
|
+
return { x: payload.x, y: payload.y, width: payload.width, height: payload.height };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
// ignore
|
|
269
|
+
}
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 通过 noteId 精确查找卡片(.note-item)的 Rect
|
|
274
|
+
*/
|
|
275
|
+
async function computeCardRectByNoteId(noteId) {
|
|
276
|
+
const nid = String(noteId || '').trim();
|
|
277
|
+
if (!nid)
|
|
278
|
+
return undefined;
|
|
279
|
+
try {
|
|
280
|
+
const res = await controllerAction('browser:execute', {
|
|
281
|
+
profile,
|
|
282
|
+
script: `(() => {
|
|
283
|
+
const noteId = ${JSON.stringify(nid)};
|
|
284
|
+
const cards = Array.from(document.querySelectorAll('.note-item'));
|
|
285
|
+
for (const card of cards) {
|
|
286
|
+
try {
|
|
287
|
+
const cover = card.querySelector('a.cover');
|
|
288
|
+
if (!cover) continue;
|
|
289
|
+
const href = cover.getAttribute('href') || cover.href || '';
|
|
290
|
+
if (!href || href.indexOf(noteId) === -1) continue;
|
|
291
|
+
const r = card.getBoundingClientRect();
|
|
292
|
+
if (!r || !r.width || !r.height) continue;
|
|
293
|
+
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
|
294
|
+
} catch (_) {}
|
|
295
|
+
}
|
|
296
|
+
return null;
|
|
297
|
+
})()`,
|
|
298
|
+
});
|
|
299
|
+
const payload = res?.result ?? res?.data?.result ?? res;
|
|
300
|
+
if (payload &&
|
|
301
|
+
typeof payload.x === 'number' &&
|
|
302
|
+
typeof payload.y === 'number' &&
|
|
303
|
+
typeof payload.width === 'number' &&
|
|
304
|
+
typeof payload.height === 'number') {
|
|
305
|
+
return { x: payload.x, y: payload.y, width: payload.width, height: payload.height };
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// ignore
|
|
310
|
+
}
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* 验证某个坐标点是否在封面(a.cover)内
|
|
315
|
+
*/
|
|
316
|
+
async function isPointInsideCover(point) {
|
|
317
|
+
try {
|
|
318
|
+
const res = await controllerAction('browser:execute', {
|
|
319
|
+
profile,
|
|
320
|
+
script: `(() => {
|
|
321
|
+
const p = ${JSON.stringify(point)};
|
|
322
|
+
const el = document.elementFromPoint(p.x, p.y);
|
|
323
|
+
if (!el) return false;
|
|
324
|
+
const a = el.closest && el.closest('a.cover');
|
|
325
|
+
if (!a) return false;
|
|
326
|
+
const media = a.querySelector && a.querySelector('img,video');
|
|
327
|
+
const target = media || a;
|
|
328
|
+
const r = target.getBoundingClientRect();
|
|
329
|
+
if (!r || !r.width || !r.height) return false;
|
|
330
|
+
return p.x >= r.left && p.x <= r.right && p.y >= r.top && p.y <= r.bottom;
|
|
331
|
+
})()`,
|
|
332
|
+
});
|
|
333
|
+
const payload = res?.result ?? res?.data?.result ?? res;
|
|
334
|
+
return Boolean(payload);
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* 在页面上绘制高亮 Rect(用于视觉确认)
|
|
342
|
+
*/
|
|
343
|
+
async function highlightRect(rect, durationMs = 1200, color = '#00ff00') {
|
|
344
|
+
try {
|
|
345
|
+
await controllerAction('browser:execute', {
|
|
346
|
+
profile,
|
|
347
|
+
script: `(() => {
|
|
348
|
+
const r = ${JSON.stringify(rect)};
|
|
349
|
+
let overlay = document.getElementById('webauto-click-rect');
|
|
350
|
+
if (!overlay) {
|
|
351
|
+
overlay = document.createElement('div');
|
|
352
|
+
overlay.id = 'webauto-click-rect';
|
|
353
|
+
overlay.style.position = 'fixed';
|
|
354
|
+
overlay.style.pointerEvents = 'none';
|
|
355
|
+
overlay.style.zIndex = '2147483647';
|
|
356
|
+
document.body.appendChild(overlay);
|
|
357
|
+
}
|
|
358
|
+
overlay.style.left = r.x + 'px';
|
|
359
|
+
overlay.style.top = r.y + 'px';
|
|
360
|
+
overlay.style.width = r.width + 'px';
|
|
361
|
+
overlay.style.height = r.height + 'px';
|
|
362
|
+
overlay.style.border = '3px solid ${color}';
|
|
363
|
+
overlay.style.boxSizing = 'border-box';
|
|
364
|
+
setTimeout(() => overlay && overlay.parentElement && overlay.parentElement.removeChild(overlay), ${durationMs});
|
|
365
|
+
return true;
|
|
366
|
+
})()`,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
// ignore
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* 诊断:dump 当前视口内所有 .note-item 的 rect / title / href
|
|
375
|
+
*/
|
|
376
|
+
async function dumpViewportDiagnostics() {
|
|
377
|
+
try {
|
|
378
|
+
const result = await controllerAction('browser:execute', {
|
|
379
|
+
profile,
|
|
380
|
+
script: `(() => {
|
|
381
|
+
const scrollY = window.scrollY || document.documentElement.scrollTop || 0;
|
|
382
|
+
const innerHeight = window.innerHeight || 0;
|
|
383
|
+
const items = Array.from(document.querySelectorAll('.note-item'));
|
|
384
|
+
const summary = items.map((el, idx) => {
|
|
385
|
+
const rect = el.getBoundingClientRect();
|
|
386
|
+
const titleEl = el.querySelector('.note-title, .title, [data-role="note-title"]');
|
|
387
|
+
const titleText = titleEl ? (titleEl.textContent || '').trim() : '';
|
|
388
|
+
let href = '';
|
|
389
|
+
const link = el.querySelector('a[href*="/explore/"], a[href*="/search_result/"]');
|
|
390
|
+
if (link instanceof HTMLAnchorElement) {
|
|
391
|
+
href = link.href || link.getAttribute('href') || '';
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
index: idx,
|
|
395
|
+
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
396
|
+
title: titleText,
|
|
397
|
+
href,
|
|
398
|
+
inViewport: rect.top >= 0 && rect.top < innerHeight,
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
return {
|
|
402
|
+
scrollY,
|
|
403
|
+
innerHeight,
|
|
404
|
+
totalItems: items.length,
|
|
405
|
+
visibleItems: summary.filter(i => i.inViewport).length,
|
|
406
|
+
items: summary.slice(0, 40),
|
|
407
|
+
};
|
|
408
|
+
})()`,
|
|
409
|
+
});
|
|
410
|
+
const diag = result.result || result.data?.result || result;
|
|
411
|
+
console.log('[OpenDetail][diagnostic] viewport summary:', JSON.stringify(diag));
|
|
412
|
+
}
|
|
413
|
+
catch (e) {
|
|
414
|
+
console.warn('[OpenDetail][diagnostic] dump viewport failed:', e.message || String(e));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
getViewportMetrics,
|
|
419
|
+
inferScrollContainerId,
|
|
420
|
+
scrollTowardVisibility,
|
|
421
|
+
highlightByIndex,
|
|
422
|
+
highlightBySelector,
|
|
423
|
+
ensureSelectorFullyInViewport,
|
|
424
|
+
ensureDomIndexFullyInViewport,
|
|
425
|
+
computeCoverRectByIndex,
|
|
426
|
+
computeCoverRectByNoteId,
|
|
427
|
+
computeCardRectByIndex,
|
|
428
|
+
computeCardRectByNoteId,
|
|
429
|
+
isPointInsideCover,
|
|
430
|
+
highlightRect,
|
|
431
|
+
dumpViewportDiagnostics,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* 从 container:operation 响应中提取 Rect
|
|
436
|
+
*/
|
|
437
|
+
function rectFromOperationResponse(raw) {
|
|
438
|
+
if (!raw || typeof raw !== 'object')
|
|
439
|
+
return undefined;
|
|
440
|
+
const payload = raw?.data ?? raw;
|
|
441
|
+
const rectData = payload?.rect ?? payload?.data?.rect;
|
|
442
|
+
if (!rectData || typeof rectData !== 'object')
|
|
443
|
+
return undefined;
|
|
444
|
+
if (typeof rectData.x === 'number' &&
|
|
445
|
+
typeof rectData.y === 'number' &&
|
|
446
|
+
typeof rectData.width === 'number' &&
|
|
447
|
+
typeof rectData.height === 'number') {
|
|
448
|
+
return { x: rectData.x, y: rectData.y, width: rectData.width, height: rectData.height };
|
|
449
|
+
}
|
|
450
|
+
if (typeof rectData.x1 === 'number' &&
|
|
451
|
+
typeof rectData.y1 === 'number' &&
|
|
452
|
+
typeof rectData.x2 === 'number' &&
|
|
453
|
+
typeof rectData.y2 === 'number') {
|
|
454
|
+
return {
|
|
455
|
+
x: rectData.x1,
|
|
456
|
+
y: rectData.y1,
|
|
457
|
+
width: rectData.x2 - rectData.x1,
|
|
458
|
+
height: rectData.y2 - rectData.y1,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
if (typeof rectData.left === 'number' &&
|
|
462
|
+
typeof rectData.top === 'number' &&
|
|
463
|
+
typeof rectData.right === 'number' &&
|
|
464
|
+
typeof rectData.bottom === 'number') {
|
|
465
|
+
return {
|
|
466
|
+
x: rectData.left,
|
|
467
|
+
y: rectData.top,
|
|
468
|
+
width: rectData.right - rectData.left,
|
|
469
|
+
height: rectData.bottom - rectData.top,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return undefined;
|
|
473
|
+
}
|
|
474
|
+
//# sourceMappingURL=openDetailViewport.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* openDetailWaiter.ts
|
|
3
|
+
*
|
|
4
|
+
* 详情页就绪检测与"误点/回退"策略
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 等待详情页就绪
|
|
8
|
+
*/
|
|
9
|
+
export async function waitForDetail(deps, maxRetries = 10) {
|
|
10
|
+
const { getCurrentUrl, controllerAction, profile } = deps;
|
|
11
|
+
let safeUrl;
|
|
12
|
+
let noteId;
|
|
13
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
14
|
+
const currentUrl = await getCurrentUrl();
|
|
15
|
+
// 个人主页/用户页:判定为误点(常见原因:点到作者头像/昵称)
|
|
16
|
+
if (currentUrl.includes('/user/profile')) {
|
|
17
|
+
return { ready: false };
|
|
18
|
+
}
|
|
19
|
+
// 0. 404 / 当前笔记暂时无法浏览 → 立即判定为失败
|
|
20
|
+
if (currentUrl.includes('/404') && currentUrl.includes('error_code=300031')) {
|
|
21
|
+
console.warn('[OpenDetail] Detected 404 note page, aborting detail wait');
|
|
22
|
+
return { ready: false };
|
|
23
|
+
}
|
|
24
|
+
// 1. 先用 URL 做一次快速检测:
|
|
25
|
+
// - /explore/{noteId}?...xsec_token=...
|
|
26
|
+
// - /search_result/{noteId}?...xsec_token=...
|
|
27
|
+
// 两者均视为详情已经就绪
|
|
28
|
+
if (currentUrl &&
|
|
29
|
+
(/\/explore\/[0-9a-z]+/i.test(currentUrl) || /\/search_result\/[0-9a-z]+/i.test(currentUrl)) &&
|
|
30
|
+
/[?&]xsec_token=/.test(currentUrl)) {
|
|
31
|
+
safeUrl = currentUrl;
|
|
32
|
+
const m = currentUrl.match(/\/(?:explore|search_result)\/([0-9a-z]+)/i);
|
|
33
|
+
noteId = m ? m[1] : undefined;
|
|
34
|
+
console.log('[OpenDetail] Detail URL ready (route + xsec_token)');
|
|
35
|
+
return { ready: true, safeUrl, noteId };
|
|
36
|
+
}
|
|
37
|
+
// 2. 再用 DOM 结构做一次检查(模态或评论区命中任意一个即可)
|
|
38
|
+
try {
|
|
39
|
+
const domResult = await controllerAction('browser:execute', {
|
|
40
|
+
profile,
|
|
41
|
+
script: `(() => {
|
|
42
|
+
const hasModal =
|
|
43
|
+
document.querySelector('.note-detail-mask') ||
|
|
44
|
+
document.querySelector('.note-detail-page') ||
|
|
45
|
+
document.querySelector('.note-detail-dialog') ||
|
|
46
|
+
document.querySelector('.note-detail') ||
|
|
47
|
+
document.querySelector('.detail-container') ||
|
|
48
|
+
document.querySelector('.media-container');
|
|
49
|
+
const hasComments =
|
|
50
|
+
document.querySelector('.comments-el') ||
|
|
51
|
+
document.querySelector('.comment-list') ||
|
|
52
|
+
document.querySelector('.comments-container');
|
|
53
|
+
return { hasModal: !!hasModal, hasComments: !!hasComments };
|
|
54
|
+
})()`,
|
|
55
|
+
});
|
|
56
|
+
const payload = domResult.result || domResult.data?.result || domResult;
|
|
57
|
+
if (payload?.hasModal || payload?.hasComments) {
|
|
58
|
+
const url = currentUrl || (await getCurrentUrl());
|
|
59
|
+
safeUrl = url && /[?&]xsec_token=/.test(url) ? url : undefined;
|
|
60
|
+
const m = url?.match(/\/(?:explore|search_result)\/([0-9a-z]+)/i);
|
|
61
|
+
noteId = m ? m[1] : undefined;
|
|
62
|
+
console.log('[OpenDetail] Detail DOM ready (hasModal/hasComments)');
|
|
63
|
+
return { ready: true, safeUrl, noteId };
|
|
64
|
+
}
|
|
65
|
+
console.log(`[OpenDetail] Detail not ready yet (iter=${i}, url=${currentUrl || 'unknown'})`);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
console.warn(`[OpenDetail] DOM readiness check failed (retry ${i}): ${e.message}`);
|
|
69
|
+
}
|
|
70
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
71
|
+
}
|
|
72
|
+
return { ready: false };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 误点后返回搜索列表
|
|
76
|
+
*/
|
|
77
|
+
export async function backToSearchList(deps, maxWaitMs = 8000) {
|
|
78
|
+
const { controllerAction, profile, serviceUrl } = deps;
|
|
79
|
+
const { verifyAnchorByContainerId } = await import('./containerAnchors.js');
|
|
80
|
+
const listId = 'xiaohongshu_search.search_result_list';
|
|
81
|
+
const start = Date.now();
|
|
82
|
+
while (Date.now() - start < maxWaitMs) {
|
|
83
|
+
// 尝试系统级返回:优先 ESC,其次浏览器后退
|
|
84
|
+
for (const key of ['Escape', 'Meta+[', 'Alt+ArrowLeft']) {
|
|
85
|
+
try {
|
|
86
|
+
await controllerAction('keyboard:press', { profileId: profile, key });
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// ignore
|
|
90
|
+
}
|
|
91
|
+
await new Promise((r) => setTimeout(r, 900));
|
|
92
|
+
try {
|
|
93
|
+
const anchor = await verifyAnchorByContainerId(listId, profile, serviceUrl, '2px solid #00bbff', 800);
|
|
94
|
+
if (anchor.found)
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// ignore
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=openDetailWaiter.js.map
|