@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,258 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
function readNumber(v) {
|
|
4
|
+
const n = Number(v);
|
|
5
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
6
|
+
}
|
|
7
|
+
function getDisplayMetrics() {
|
|
8
|
+
const envWidth = readNumber(process.env.WEBAUTO_SCREEN_WIDTH);
|
|
9
|
+
const envHeight = readNumber(process.env.WEBAUTO_SCREEN_HEIGHT);
|
|
10
|
+
if (envWidth && envHeight) {
|
|
11
|
+
return { width: envWidth, height: envHeight, source: 'env' };
|
|
12
|
+
}
|
|
13
|
+
if (os.platform() === 'darwin') {
|
|
14
|
+
try {
|
|
15
|
+
const sp = spawnSync('system_profiler', ['SPDisplaysDataType', '-json'], { encoding: 'utf8' });
|
|
16
|
+
const spJson = sp.status === 0 && sp.stdout ? JSON.parse(sp.stdout) : null;
|
|
17
|
+
let width = null;
|
|
18
|
+
let height = null;
|
|
19
|
+
const displays = spJson?.SPDisplaysDataType;
|
|
20
|
+
if (Array.isArray(displays) && displays.length > 0) {
|
|
21
|
+
const first = displays[0];
|
|
22
|
+
const gpus = first?._items;
|
|
23
|
+
const maybe = Array.isArray(gpus) && gpus.length > 0 ? gpus[0] : first;
|
|
24
|
+
const resStr = maybe?.spdisplays_ndrvs?.[0]?._spdisplays_resolution || maybe?._spdisplays_resolution;
|
|
25
|
+
if (typeof resStr === 'string') {
|
|
26
|
+
const m = resStr.match(/(\d+)\s*x\s*(\d+)/i);
|
|
27
|
+
if (m) {
|
|
28
|
+
width = readNumber(m[1]);
|
|
29
|
+
height = readNumber(m[2]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const osascript = spawnSync('osascript', ['-l', 'JavaScript', '-e',
|
|
34
|
+
`ObjC.import('AppKit');
|
|
35
|
+
const s = $.NSScreen.mainScreen;
|
|
36
|
+
const f = s.frame;
|
|
37
|
+
const v = s.visibleFrame;
|
|
38
|
+
JSON.stringify({
|
|
39
|
+
width: Number(f.size.width),
|
|
40
|
+
height: Number(f.size.height),
|
|
41
|
+
workWidth: Number(v.size.width),
|
|
42
|
+
workHeight: Number(v.size.height)
|
|
43
|
+
});`
|
|
44
|
+
], { encoding: 'utf8' });
|
|
45
|
+
const vf = osascript.status === 0 && osascript.stdout ? JSON.parse(osascript.stdout.trim()) : null;
|
|
46
|
+
const finalW = readNumber(vf?.width) || width;
|
|
47
|
+
const finalH = readNumber(vf?.height) || height;
|
|
48
|
+
const workWidth = readNumber(vf?.workWidth);
|
|
49
|
+
const workHeight = readNumber(vf?.workHeight);
|
|
50
|
+
if (!finalW || !finalH)
|
|
51
|
+
return null;
|
|
52
|
+
return {
|
|
53
|
+
width: finalW,
|
|
54
|
+
height: finalH,
|
|
55
|
+
...(workWidth ? { workWidth } : {}),
|
|
56
|
+
...(workHeight ? { workHeight } : {}),
|
|
57
|
+
source: 'darwin',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (os.platform() !== 'win32')
|
|
65
|
+
return null;
|
|
66
|
+
try {
|
|
67
|
+
const script = [
|
|
68
|
+
'Add-Type -AssemblyName System.Windows.Forms;',
|
|
69
|
+
'$screen=[System.Windows.Forms.Screen]::PrimaryScreen;',
|
|
70
|
+
'$b=$screen.Bounds;',
|
|
71
|
+
'$w=$screen.WorkingArea;',
|
|
72
|
+
'$video=Get-CimInstance Win32_VideoController | Select-Object -First 1;',
|
|
73
|
+
'$nw=$null;$nh=$null;',
|
|
74
|
+
'if ($video) { $nw=$video.CurrentHorizontalResolution; $nh=$video.CurrentVerticalResolution }',
|
|
75
|
+
'$o=[pscustomobject]@{width=$b.Width;height=$b.Height;workWidth=$w.Width;workHeight=$w.Height;nativeWidth=$nw;nativeHeight=$nh};',
|
|
76
|
+
'$o | ConvertTo-Json -Compress',
|
|
77
|
+
].join(' ');
|
|
78
|
+
const res = spawnSync('powershell', ['-NoProfile', '-Command', script], {
|
|
79
|
+
encoding: 'utf8',
|
|
80
|
+
windowsHide: true,
|
|
81
|
+
});
|
|
82
|
+
if (res.status !== 0 || !res.stdout)
|
|
83
|
+
return null;
|
|
84
|
+
const payload = JSON.parse(res.stdout.trim());
|
|
85
|
+
const nativeWidth = readNumber(payload?.nativeWidth);
|
|
86
|
+
const nativeHeight = readNumber(payload?.nativeHeight);
|
|
87
|
+
const width = readNumber(payload?.width) || nativeWidth || null;
|
|
88
|
+
const height = readNumber(payload?.height) || nativeHeight || null;
|
|
89
|
+
const workWidth = readNumber(payload?.workWidth);
|
|
90
|
+
const workHeight = readNumber(payload?.workHeight);
|
|
91
|
+
if (!width || !height)
|
|
92
|
+
return null;
|
|
93
|
+
return {
|
|
94
|
+
width,
|
|
95
|
+
height,
|
|
96
|
+
...(workWidth ? { workWidth } : {}),
|
|
97
|
+
...(workHeight ? { workHeight } : {}),
|
|
98
|
+
...(nativeWidth ? { nativeWidth } : {}),
|
|
99
|
+
...(nativeHeight ? { nativeHeight } : {}),
|
|
100
|
+
source: 'win32',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function getDisplayMetricsWithDPR() {
|
|
108
|
+
const dm = getDisplayMetrics();
|
|
109
|
+
const base = dm ? { ...dm } : {};
|
|
110
|
+
const width = Number(base.width) || 0;
|
|
111
|
+
const height = Number(base.height) || 0;
|
|
112
|
+
const workWidth = Number(base.workWidth) || width;
|
|
113
|
+
const workHeight = Number(base.workHeight) || height;
|
|
114
|
+
let dpr = 1;
|
|
115
|
+
if (os.platform() === 'darwin') {
|
|
116
|
+
try {
|
|
117
|
+
const sp = spawnSync('system_profiler', ['SPDisplaysDataType', '-json'], { encoding: 'utf8' });
|
|
118
|
+
const spJson = sp.status === 0 && sp.stdout ? JSON.parse(sp.stdout) : null;
|
|
119
|
+
const displays = spJson?.SPDisplaysDataType;
|
|
120
|
+
if (Array.isArray(displays) && displays.length > 0) {
|
|
121
|
+
const first = displays[0];
|
|
122
|
+
const gpus = first?._items;
|
|
123
|
+
const maybe = Array.isArray(gpus) && gpus.length > 0 ? gpus[0] : first;
|
|
124
|
+
const isRetina = maybe?.spdisplays_retina === 'spdisplays_yes' || maybe?.spdisplays_retina === true;
|
|
125
|
+
if (isRetina)
|
|
126
|
+
dpr = 2;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
if (width >= 2560 && height >= 1440)
|
|
131
|
+
dpr = 2;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { width, height, workWidth, workHeight, source: base.source || 'unknown', dpr };
|
|
135
|
+
}
|
|
136
|
+
async function loadCamoufox() {
|
|
137
|
+
// Prefer dynamic import; fall back to require for NodeNext interop edge cases.
|
|
138
|
+
try {
|
|
139
|
+
return await import('camoufox');
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
const mod = await import('node:module');
|
|
143
|
+
const require = mod.createRequire(import.meta.url);
|
|
144
|
+
return require('camoufox');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export async function launchEngineContext(opts) {
|
|
148
|
+
if (opts.engine === 'camoufox') {
|
|
149
|
+
// Camoufox/Firefox is sensitive to non-integer window placement/size values.
|
|
150
|
+
// In practice, when the underlying launch path attempts to derive screenY/screenX from floats,
|
|
151
|
+
// Firefox can crash with: "Invalid type for property window.screenY. Expected int, got number".
|
|
152
|
+
// Also, we want the window size to reflect the *real* OS work area so later system clicks
|
|
153
|
+
// have enough usable viewport.
|
|
154
|
+
// Prefer OS work area (real screen resolution) for window size; fall back to viewport.
|
|
155
|
+
const dm = getDisplayMetricsWithDPR();
|
|
156
|
+
// Physical display size from OS
|
|
157
|
+
const physicalW = Number(dm?.width || 4096);
|
|
158
|
+
const physicalH = Number(dm?.height || 2304);
|
|
159
|
+
const workW = Number(dm?.workWidth || physicalW || 4096);
|
|
160
|
+
const workH = Number(dm?.workHeight || physicalH || 2190);
|
|
161
|
+
// Use provided viewport as MAXIMUM (e.g., from fingerprint or explicit opt), default to full work area
|
|
162
|
+
const maxViewportW = Number(opts.viewport?.width || workW);
|
|
163
|
+
const maxViewportH = Number(opts.viewport?.height || workH);
|
|
164
|
+
// Target: fill work area, but don't exceed explicit viewport caps if provided
|
|
165
|
+
const targetW = maxViewportW > 0 ? Math.min(maxViewportW, workW) : workW;
|
|
166
|
+
const targetH = maxViewportH > 0 ? Math.min(maxViewportH, workH) : workH;
|
|
167
|
+
// Use targetW/targetH as viewport (even in headless) to match headful size
|
|
168
|
+
const viewportW = Math.max(1440, Math.floor(Number(targetW) || 4096));
|
|
169
|
+
const viewportH = Math.max(900, Math.floor(Number(targetH) || 2190));
|
|
170
|
+
const envHeadlessW = Number(process.env.WEBAUTO_HEADLESS_WIDTH || 0);
|
|
171
|
+
const envHeadlessH = Number(process.env.WEBAUTO_HEADLESS_HEIGHT || 0);
|
|
172
|
+
const headlessW = envHeadlessW > 0 ? envHeadlessW : viewportW;
|
|
173
|
+
const headlessH = envHeadlessH > 0 ? envHeadlessH : viewportH;
|
|
174
|
+
if (!Number.isFinite(headlessW) || !Number.isFinite(headlessH)) {
|
|
175
|
+
throw new Error('headless viewport invalid');
|
|
176
|
+
}
|
|
177
|
+
const headless = Boolean(opts.headless);
|
|
178
|
+
// Final window size: maximize to fill work area (leave small margin for chrome/window decorations)
|
|
179
|
+
const winW = headless ? headlessW : Math.max(1440, Math.floor(workW * 0.95));
|
|
180
|
+
const winH = headless ? headlessH : Math.max(900, Math.floor(workH - 80));
|
|
181
|
+
// Ensure integer types for Camoufox
|
|
182
|
+
const screenW = Math.floor(physicalW) | 0;
|
|
183
|
+
const screenH = Math.floor(physicalH) | 0;
|
|
184
|
+
const intWinW = Math.floor(winW) | 0;
|
|
185
|
+
const intWinH = Math.floor(winH) | 0;
|
|
186
|
+
// Firefox/Camoufox requires screenX/screenY to be integers; default to 0 to avoid float errors.
|
|
187
|
+
const camoufox = await loadCamoufox();
|
|
188
|
+
const Camoufox = camoufox.Camoufox;
|
|
189
|
+
if (!Camoufox)
|
|
190
|
+
throw new Error('camoufox_invalid_api');
|
|
191
|
+
const targetOS = process.platform === 'win32'
|
|
192
|
+
? 'windows'
|
|
193
|
+
: process.platform === 'darwin'
|
|
194
|
+
? 'macos'
|
|
195
|
+
: 'linux';
|
|
196
|
+
// Build config to force actual display dimensions (without screen constraints to avoid position calc issues)
|
|
197
|
+
const config = {
|
|
198
|
+
'screen.width': Math.floor(physicalW),
|
|
199
|
+
'screen.height': Math.floor(physicalH),
|
|
200
|
+
'screen.availWidth': Math.floor(workW),
|
|
201
|
+
'screen.availHeight': Math.floor(workH),
|
|
202
|
+
'window.screenX': 0,
|
|
203
|
+
'window.screenY': 0,
|
|
204
|
+
};
|
|
205
|
+
// Force tabs to open in same window (not new windows)
|
|
206
|
+
const firefox_user_prefs = {
|
|
207
|
+
// Force all new windows (including script popups) to open as tabs
|
|
208
|
+
'browser.link.open_newwindow': 3,
|
|
209
|
+
'browser.link.open_newwindow.restriction': 0,
|
|
210
|
+
'browser.link.open_newwindow.override.external': -1,
|
|
211
|
+
// Make sure tab strip is visible and no single-window mode
|
|
212
|
+
'browser.tabs.loadInBackground': false,
|
|
213
|
+
'browser.tabs.loadDivertedInBackground': false,
|
|
214
|
+
'browser.tabs.closeWindowWithLastTab': false,
|
|
215
|
+
'browser.tabs.warnOnClose': false,
|
|
216
|
+
'browser.tabs.tabMinWidth': 50,
|
|
217
|
+
};
|
|
218
|
+
const result = await Camoufox({
|
|
219
|
+
headless,
|
|
220
|
+
os: targetOS,
|
|
221
|
+
window: [intWinW, intWinH],
|
|
222
|
+
viewport: { width: headless ? headlessW : viewportW, height: headless ? headlessH : viewportH },
|
|
223
|
+
firefox_user_prefs,
|
|
224
|
+
config,
|
|
225
|
+
data_dir: opts.profileDir,
|
|
226
|
+
humanize: true,
|
|
227
|
+
iKnowWhatImDoing: true,
|
|
228
|
+
locale: 'zh-CN',
|
|
229
|
+
fonts: [
|
|
230
|
+
'PingFang SC',
|
|
231
|
+
'Hiragino Sans GB',
|
|
232
|
+
'STHeiti',
|
|
233
|
+
'Microsoft YaHei',
|
|
234
|
+
'SimHei',
|
|
235
|
+
'SimSun',
|
|
236
|
+
'Microsoft JhengHei',
|
|
237
|
+
'Noto Sans CJK SC',
|
|
238
|
+
'Source Han Sans SC',
|
|
239
|
+
'Arial Unicode MS',
|
|
240
|
+
'Helvetica',
|
|
241
|
+
'Arial',
|
|
242
|
+
'Sans-Serif',
|
|
243
|
+
],
|
|
244
|
+
custom_fonts_only: false,
|
|
245
|
+
});
|
|
246
|
+
if (result && typeof result.pages === 'function') {
|
|
247
|
+
// Already a BrowserContext
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
if (result && typeof result.newContext === 'function') {
|
|
251
|
+
// Browser -> create a new context
|
|
252
|
+
return (await result.newContext());
|
|
253
|
+
}
|
|
254
|
+
throw new Error('camoufox_invalid_response');
|
|
255
|
+
}
|
|
256
|
+
throw new Error('chromium_removed');
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=engine-manager.js.map
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 浏览器指纹管理器
|
|
3
|
+
* 提供稳定的指纹生成、应用和管理功能
|
|
4
|
+
*/
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
6
|
+
import { writeFile, readFile, mkdir } from 'fs/promises';
|
|
7
|
+
import { join, dirname } from 'path';
|
|
8
|
+
import { homedir } from 'os';
|
|
9
|
+
function resolveFingerprintDir() {
|
|
10
|
+
const envDir = String(process.env.WEBAUTO_PATHS_FINGERPRINTS || '').trim();
|
|
11
|
+
if (envDir)
|
|
12
|
+
return envDir;
|
|
13
|
+
const portableRoot = String(process.env.WEBAUTO_PORTABLE_ROOT || process.env.WEBAUTO_ROOT || '').trim();
|
|
14
|
+
if (portableRoot)
|
|
15
|
+
return join(portableRoot, '.webauto', 'fingerprints');
|
|
16
|
+
return join(homedir(), '.webauto', 'fingerprints');
|
|
17
|
+
}
|
|
18
|
+
const PLATFORM_FINGERPRINTS = {
|
|
19
|
+
windows: [
|
|
20
|
+
{
|
|
21
|
+
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
|
22
|
+
platform: 'Win32',
|
|
23
|
+
osVersion: '10.0',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
userAgent: 'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
|
27
|
+
platform: 'Win32',
|
|
28
|
+
osVersion: '11.0',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
macos: [
|
|
32
|
+
{
|
|
33
|
+
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
|
34
|
+
platform: 'MacIntel',
|
|
35
|
+
osVersion: '10.15.7',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_6_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
|
39
|
+
platform: 'MacIntel',
|
|
40
|
+
osVersion: '14.6.1',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
export function generateFingerprint(profileId = 'default', options = {}) {
|
|
45
|
+
const { platform = null, seed = null } = options;
|
|
46
|
+
const hash = randomBytes(16).toString('hex');
|
|
47
|
+
let base;
|
|
48
|
+
if (platform === 'windows') {
|
|
49
|
+
base = PLATFORM_FINGERPRINTS.windows[hash.charCodeAt(0) % PLATFORM_FINGERPRINTS.windows.length];
|
|
50
|
+
}
|
|
51
|
+
else if (platform === 'macos') {
|
|
52
|
+
base = PLATFORM_FINGERPRINTS.macos[hash.charCodeAt(0) % PLATFORM_FINGERPRINTS.macos.length];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const useWindows = hash.charCodeAt(0) % 2 === 0;
|
|
56
|
+
const pool = useWindows ? PLATFORM_FINGERPRINTS.windows : PLATFORM_FINGERPRINTS.macos;
|
|
57
|
+
base = pool[hash.charCodeAt(1) % pool.length];
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
profileId,
|
|
61
|
+
userAgent: base.userAgent,
|
|
62
|
+
platform: base.platform,
|
|
63
|
+
osVersion: base.osVersion,
|
|
64
|
+
languages: ['zh-CN', 'zh', 'en-US', 'en'],
|
|
65
|
+
language: 'zh-CN',
|
|
66
|
+
hardwareConcurrency: [4, 6, 8, 12, 16][hash.charCodeAt(1) % 5],
|
|
67
|
+
deviceMemory: [4, 8, 16, 32][hash.charCodeAt(2) % 4],
|
|
68
|
+
viewport: {
|
|
69
|
+
width: [1366, 1440, 1536, 1920][hash.charCodeAt(3) % 4],
|
|
70
|
+
height: [768, 900, 864, 1080][hash.charCodeAt(4) % 4],
|
|
71
|
+
},
|
|
72
|
+
timezoneId: 'Asia/Shanghai',
|
|
73
|
+
maxTouchPoints: 0,
|
|
74
|
+
vendor: 'Google Inc.',
|
|
75
|
+
renderer: 'ANGLE (NVIDIA, NVIDIA GeForce, D3D11)',
|
|
76
|
+
originalPlatform: platform || (base.platform === 'Win32' ? 'windows' : 'macos'),
|
|
77
|
+
// 增加一个随机噪声用于区分 profile
|
|
78
|
+
fingerprintSalt: hash.slice(0, 8),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export async function applyFingerprint(context, fingerprint) {
|
|
82
|
+
if (!context || !fingerprint)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
// 设置User-Agent
|
|
86
|
+
if (fingerprint.userAgent) {
|
|
87
|
+
await context.addInitScript(`
|
|
88
|
+
Object.defineProperty(navigator, 'userAgent', {
|
|
89
|
+
get: () => '${fingerprint.userAgent}',
|
|
90
|
+
configurable: true
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(navigator, 'platform', {
|
|
93
|
+
get: () => '${fingerprint.platform}',
|
|
94
|
+
configurable: true
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(navigator, 'osVersion', {
|
|
97
|
+
get: () => '${fingerprint.osVersion || ''}',
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
100
|
+
`);
|
|
101
|
+
}
|
|
102
|
+
if (fingerprint.vendor) {
|
|
103
|
+
await context.addInitScript(`
|
|
104
|
+
Object.defineProperty(navigator, 'vendor', {
|
|
105
|
+
get: () => '${fingerprint.vendor}',
|
|
106
|
+
configurable: true
|
|
107
|
+
});
|
|
108
|
+
`);
|
|
109
|
+
}
|
|
110
|
+
// 设置语言
|
|
111
|
+
if (fingerprint.languages && fingerprint.language) {
|
|
112
|
+
await context.addInitScript(`
|
|
113
|
+
Object.defineProperty(navigator, 'language', {
|
|
114
|
+
get: () => '${fingerprint.language}',
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
Object.defineProperty(navigator, 'languages', {
|
|
119
|
+
get: () => ${JSON.stringify(fingerprint.languages)},
|
|
120
|
+
configurable: true
|
|
121
|
+
});
|
|
122
|
+
`);
|
|
123
|
+
}
|
|
124
|
+
// 设置硬件信息
|
|
125
|
+
if (fingerprint.hardwareConcurrency) {
|
|
126
|
+
await context.addInitScript(`
|
|
127
|
+
Object.defineProperty(navigator, 'hardwareConcurrency', {
|
|
128
|
+
get: () => ${fingerprint.hardwareConcurrency},
|
|
129
|
+
configurable: true
|
|
130
|
+
});
|
|
131
|
+
`);
|
|
132
|
+
}
|
|
133
|
+
// 设置设备内存
|
|
134
|
+
if (fingerprint.deviceMemory) {
|
|
135
|
+
await context.addInitScript(`
|
|
136
|
+
Object.defineProperty(navigator, 'deviceMemory', {
|
|
137
|
+
get: () => ${fingerprint.deviceMemory},
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
140
|
+
`);
|
|
141
|
+
}
|
|
142
|
+
// 设置视口 (Camoufox 已在启动时应用,无需重新设置)
|
|
143
|
+
// if (fingerprint.viewport) {
|
|
144
|
+
// await context.setViewportSize?.(fingerprint.viewport);
|
|
145
|
+
// }
|
|
146
|
+
// 设置时区
|
|
147
|
+
if (fingerprint.timezoneId) {
|
|
148
|
+
context.timezoneId = fingerprint.timezoneId;
|
|
149
|
+
}
|
|
150
|
+
// 移除webdriver标识
|
|
151
|
+
await context.addInitScript(`
|
|
152
|
+
Object.defineProperty(navigator, 'webdriver', {
|
|
153
|
+
get: () => undefined,
|
|
154
|
+
configurable: true
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
delete navigator.__proto__.webdriver;
|
|
158
|
+
`);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
console.warn('Failed to apply some fingerprint properties:', error?.message || error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export async function loadFingerprint(fingerprintPath) {
|
|
165
|
+
try {
|
|
166
|
+
const data = await readFile(fingerprintPath, 'utf8');
|
|
167
|
+
return JSON.parse(data);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export async function saveFingerprint(fingerprintPath, fingerprint) {
|
|
174
|
+
try {
|
|
175
|
+
await mkdir(dirname(fingerprintPath), { recursive: true });
|
|
176
|
+
await writeFile(fingerprintPath, JSON.stringify(fingerprint, null, 2));
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error('Failed to save fingerprint:', error);
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export function getFingerprintPath(profileId) {
|
|
185
|
+
return join(resolveFingerprintDir(), `${profileId}.json`);
|
|
186
|
+
}
|
|
187
|
+
export async function generateAndSaveFingerprint(profileId, options = {}) {
|
|
188
|
+
const fingerprint = generateFingerprint(profileId, options);
|
|
189
|
+
const path = getFingerprintPath(profileId);
|
|
190
|
+
await saveFingerprint(path, fingerprint);
|
|
191
|
+
return { fingerprint, path };
|
|
192
|
+
}
|
|
193
|
+
export async function loadOrGenerateFingerprint(profileId, options = {}) {
|
|
194
|
+
const path = getFingerprintPath(profileId);
|
|
195
|
+
let fingerprint = await loadFingerprint(path);
|
|
196
|
+
if (!fingerprint) {
|
|
197
|
+
fingerprint = generateFingerprint(profileId, options);
|
|
198
|
+
await saveFingerprint(path, fingerprint);
|
|
199
|
+
}
|
|
200
|
+
return fingerprint;
|
|
201
|
+
}
|
|
202
|
+
export const FINGERPRINT_DIR = resolveFingerprintDir();
|
|
203
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { injectRuntimeBundle } from './runtimeInjector.js';
|
|
2
|
+
const injectedPages = new WeakSet();
|
|
3
|
+
export async function ensurePageRuntime(page, forceReinject = false) {
|
|
4
|
+
if (!page) {
|
|
5
|
+
throw new Error('page is required');
|
|
6
|
+
}
|
|
7
|
+
// 强制重新注入或首次注入
|
|
8
|
+
if (forceReinject || !injectedPages.has(page)) {
|
|
9
|
+
await injectRuntimeBundle({ page });
|
|
10
|
+
injectedPages.add(page);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
await page.waitForFunction(() => Boolean(window.__webautoRuntime && window.__webautoRuntime.ready), {
|
|
14
|
+
timeout: 4000,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
// Runtime is best-effort for system-level mouse/keyboard commands.
|
|
19
|
+
// If injection readiness times out (common on slow/heavy pages), we must not block
|
|
20
|
+
// low-level commands like mouse:click/mouse:wheel.
|
|
21
|
+
// Higher-level operations (containers:match, overlay highlight) will handle their own retries.
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function evalPageRuntime(page, fn) {
|
|
26
|
+
await ensurePageRuntime(page);
|
|
27
|
+
return page.evaluate(fn);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=pageRuntime.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
let resolvedRuntimePath = null;
|
|
5
|
+
function resolveRuntime() {
|
|
6
|
+
if (resolvedRuntimePath)
|
|
7
|
+
return resolvedRuntimePath;
|
|
8
|
+
const base = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const candidates = [
|
|
10
|
+
path.join(process.cwd(), 'modules/camo-backend/src/internal/page-runtime/runtime.js'),
|
|
11
|
+
path.join(base, 'page-runtime/runtime.js'),
|
|
12
|
+
];
|
|
13
|
+
for (const candidate of candidates) {
|
|
14
|
+
if (fs.existsSync(candidate)) {
|
|
15
|
+
resolvedRuntimePath = candidate;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!resolvedRuntimePath) {
|
|
20
|
+
throw new Error('Runtime script not found');
|
|
21
|
+
}
|
|
22
|
+
return resolvedRuntimePath;
|
|
23
|
+
}
|
|
24
|
+
export async function injectRuntimeBundle({ page }) {
|
|
25
|
+
const runtimePath = resolveRuntime();
|
|
26
|
+
console.log(`[runtimeInjector] injecting runtime from ${runtimePath}`);
|
|
27
|
+
await page.addInitScript({ path: runtimePath });
|
|
28
|
+
await page.addScriptTag({ path: runtimePath });
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=runtimeInjector.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class LocalStateBus {
|
|
2
|
+
state = new Map();
|
|
3
|
+
subscribers = new Map();
|
|
4
|
+
setState(key, payload) {
|
|
5
|
+
this.state.set(key, { ...payload, lastUpdate: Date.now() });
|
|
6
|
+
this.publish(`state:${key}`, this.state.get(key));
|
|
7
|
+
}
|
|
8
|
+
getState(key) {
|
|
9
|
+
if (key)
|
|
10
|
+
return this.state.get(key);
|
|
11
|
+
return Object.fromEntries(this.state);
|
|
12
|
+
}
|
|
13
|
+
publish(event, payload) {
|
|
14
|
+
const listeners = this.subscribers.get(event) || [];
|
|
15
|
+
for (const listener of listeners) {
|
|
16
|
+
try {
|
|
17
|
+
listener(payload);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Keep runtime event pipeline resilient.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
subscribe(event, listener) {
|
|
25
|
+
const current = this.subscribers.get(event) || [];
|
|
26
|
+
current.push(listener);
|
|
27
|
+
this.subscribers.set(event, current);
|
|
28
|
+
return () => {
|
|
29
|
+
const next = (this.subscribers.get(event) || []).filter((fn) => fn !== listener);
|
|
30
|
+
if (next.length === 0) {
|
|
31
|
+
this.subscribers.delete(event);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.subscribers.set(event, next);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let stateBus = null;
|
|
40
|
+
export function getStateBus() {
|
|
41
|
+
if (!stateBus)
|
|
42
|
+
stateBus = new LocalStateBus();
|
|
43
|
+
return stateBus;
|
|
44
|
+
}
|
|
45
|
+
export { LocalStateBus };
|
|
46
|
+
//# sourceMappingURL=state-bus.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
function resolveHomeDir() {
|
|
4
|
+
const envHome = process.platform === 'win32'
|
|
5
|
+
? String(process.env.USERPROFILE || '').trim()
|
|
6
|
+
: String(process.env.HOME || '').trim();
|
|
7
|
+
return envHome || os.homedir();
|
|
8
|
+
}
|
|
9
|
+
function resolvePortableRoot() {
|
|
10
|
+
return String(process.env.WEBAUTO_PORTABLE_ROOT || process.env.WEBAUTO_ROOT || '').trim();
|
|
11
|
+
}
|
|
12
|
+
function resolveDataRoot() {
|
|
13
|
+
const portableRoot = resolvePortableRoot();
|
|
14
|
+
if (portableRoot)
|
|
15
|
+
return path.join(portableRoot, '.webauto');
|
|
16
|
+
return path.join(resolveHomeDir(), '.webauto');
|
|
17
|
+
}
|
|
18
|
+
export function resolveProfilesRoot() {
|
|
19
|
+
const envRoot = String(process.env.WEBAUTO_PATHS_PROFILES || '').trim();
|
|
20
|
+
if (envRoot)
|
|
21
|
+
return envRoot;
|
|
22
|
+
return path.join(resolveDataRoot(), 'profiles');
|
|
23
|
+
}
|
|
24
|
+
export function resolveCookiesRoot() {
|
|
25
|
+
const envRoot = String(process.env.WEBAUTO_PATHS_COOKIES || '').trim();
|
|
26
|
+
if (envRoot)
|
|
27
|
+
return envRoot;
|
|
28
|
+
return path.join(resolveDataRoot(), 'cookies');
|
|
29
|
+
}
|
|
30
|
+
export function resolveLocksRoot() {
|
|
31
|
+
const envRoot = String(process.env.WEBAUTO_PATHS_LOCKS || '').trim();
|
|
32
|
+
if (envRoot)
|
|
33
|
+
return envRoot;
|
|
34
|
+
return path.join(resolveDataRoot(), 'locks');
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=storage-paths.js.map
|