@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,817 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import { ProfileLock } from './ProfileLock.js';
|
|
6
|
+
import { ensurePageRuntime } from './pageRuntime.js';
|
|
7
|
+
import { logDebug } from '../../../../modules/logging/src/index.js';
|
|
8
|
+
import { getStateBus } from './state-bus.js';
|
|
9
|
+
import { loadOrGenerateFingerprint, applyFingerprint } from './fingerprint.js';
|
|
10
|
+
import { launchEngineContext } from './engine-manager.js';
|
|
11
|
+
import { resolveCookiesRoot, resolveProfilesRoot } from './storage-paths.js';
|
|
12
|
+
const stateBus = getStateBus();
|
|
13
|
+
export class BrowserSession {
|
|
14
|
+
options;
|
|
15
|
+
browser;
|
|
16
|
+
context;
|
|
17
|
+
page;
|
|
18
|
+
lock;
|
|
19
|
+
profileDir;
|
|
20
|
+
lastKnownUrl = null;
|
|
21
|
+
mode = 'dev';
|
|
22
|
+
lastCookieSignature = null;
|
|
23
|
+
lastCookieSaveTs = 0;
|
|
24
|
+
runtimeObservers = new Set();
|
|
25
|
+
bridgedPages = new WeakSet();
|
|
26
|
+
lastViewport = null;
|
|
27
|
+
fingerprint = null;
|
|
28
|
+
onExit;
|
|
29
|
+
exitNotified = false;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.options = options;
|
|
32
|
+
const profileId = options.profileId || 'default';
|
|
33
|
+
const root = resolveProfilesRoot();
|
|
34
|
+
this.profileDir = path.join(root, profileId);
|
|
35
|
+
fs.mkdirSync(this.profileDir, { recursive: true });
|
|
36
|
+
this.lock = new ProfileLock(profileId);
|
|
37
|
+
}
|
|
38
|
+
get id() {
|
|
39
|
+
return this.options.profileId;
|
|
40
|
+
}
|
|
41
|
+
get currentPage() {
|
|
42
|
+
return this.page;
|
|
43
|
+
}
|
|
44
|
+
get modeName() {
|
|
45
|
+
return this.mode;
|
|
46
|
+
}
|
|
47
|
+
setMode(next = 'dev') {
|
|
48
|
+
this.mode = next === 'run' ? 'run' : 'dev';
|
|
49
|
+
}
|
|
50
|
+
getInfo() {
|
|
51
|
+
return {
|
|
52
|
+
session_id: this.options.profileId,
|
|
53
|
+
profileId: this.options.profileId,
|
|
54
|
+
current_url: this.getCurrentUrl(),
|
|
55
|
+
mode: this.mode,
|
|
56
|
+
headless: !!this.options.headless,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async start(initialUrl) {
|
|
60
|
+
if (!this.lock.acquire()) {
|
|
61
|
+
throw new Error(`无法获取 profile ${this.options.profileId} 的锁`);
|
|
62
|
+
}
|
|
63
|
+
const engine = 'camoufox';
|
|
64
|
+
// 加载或生成指纹(支持 Win/Mac 随机)
|
|
65
|
+
const fingerprint = await loadOrGenerateFingerprint(this.options.profileId, {
|
|
66
|
+
platform: this.options.fingerprintPlatform || null,
|
|
67
|
+
});
|
|
68
|
+
this.fingerprint = fingerprint;
|
|
69
|
+
logDebug('browser-service', 'session:fingerprint', {
|
|
70
|
+
profileId: this.options.profileId,
|
|
71
|
+
platform: fingerprint.platform,
|
|
72
|
+
userAgent: fingerprint.userAgent?.substring(0, 50) + '...',
|
|
73
|
+
});
|
|
74
|
+
const viewport = this.options.viewport || { width: 3840, height: 2046 };
|
|
75
|
+
const deviceScaleFactor = this.resolveDeviceScaleFactor();
|
|
76
|
+
// 使用 EngineManager 启动上下文(Chromium 已移除,仅支持 Camoufox)
|
|
77
|
+
this.context = await launchEngineContext({
|
|
78
|
+
engine,
|
|
79
|
+
headless: !!this.options.headless,
|
|
80
|
+
profileDir: this.profileDir,
|
|
81
|
+
viewport: fingerprint?.viewport || viewport,
|
|
82
|
+
userAgent: fingerprint?.userAgent,
|
|
83
|
+
locale: 'zh-CN',
|
|
84
|
+
timezoneId: fingerprint?.timezoneId || 'Asia/Shanghai',
|
|
85
|
+
});
|
|
86
|
+
// 应用指纹到上下文(Playwright JS 注入)
|
|
87
|
+
await applyFingerprint(this.context, fingerprint);
|
|
88
|
+
// NOTE: deviceScaleFactor override was Chromium-only (CDP). Chromium removed.
|
|
89
|
+
this.lastViewport = { width: viewport.width, height: viewport.height };
|
|
90
|
+
this.browser = this.context.browser();
|
|
91
|
+
this.browser.on('disconnected', () => this.notifyExit());
|
|
92
|
+
this.context.on('close', () => this.notifyExit());
|
|
93
|
+
const existing = this.context.pages();
|
|
94
|
+
this.page = existing.length ? existing[0] : await this.context.newPage();
|
|
95
|
+
this.setupPageHooks(this.page);
|
|
96
|
+
this.context.on('page', (p) => this.setupPageHooks(p));
|
|
97
|
+
if (initialUrl) {
|
|
98
|
+
await this.goto(initialUrl);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
setupPageHooks(page) {
|
|
102
|
+
const profileTag = `[session:${this.options.profileId}]`;
|
|
103
|
+
const ensure = (reason) => {
|
|
104
|
+
ensurePageRuntime(page, true).catch((err) => {
|
|
105
|
+
console.warn(`${profileTag} ensure runtime failed (${reason})`, err?.message || err);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
this.bindRuntimeBridge(page);
|
|
109
|
+
page.on('domcontentloaded', () => ensure('domcontentloaded'));
|
|
110
|
+
page.on('framenavigated', (frame) => {
|
|
111
|
+
if (frame === page.mainFrame()) {
|
|
112
|
+
ensure('framenavigated');
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
page.on('pageerror', (error) => {
|
|
116
|
+
console.warn(`${profileTag} pageerror`, error?.message || error);
|
|
117
|
+
});
|
|
118
|
+
page.on('console', (msg) => {
|
|
119
|
+
if (msg.type() === 'error') {
|
|
120
|
+
console.warn(`${profileTag} console.error`, msg.text());
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
ensure('initial');
|
|
124
|
+
}
|
|
125
|
+
addRuntimeEventObserver(observer) {
|
|
126
|
+
this.runtimeObservers.add(observer);
|
|
127
|
+
logDebug('browser-service', 'runtimeObserver:add', { sessionId: this.id, total: this.runtimeObservers.size });
|
|
128
|
+
return () => {
|
|
129
|
+
this.runtimeObservers.delete(observer);
|
|
130
|
+
logDebug('browser-service', 'runtimeObserver:remove', { sessionId: this.id, total: this.runtimeObservers.size });
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
emitRuntimeEvent(event) {
|
|
134
|
+
const payload = {
|
|
135
|
+
ts: Date.now(),
|
|
136
|
+
sessionId: this.id,
|
|
137
|
+
...event,
|
|
138
|
+
};
|
|
139
|
+
logDebug('browser-service', 'runtimeEvent', {
|
|
140
|
+
sessionId: this.id,
|
|
141
|
+
type: event?.type || 'unknown',
|
|
142
|
+
observers: this.runtimeObservers.size,
|
|
143
|
+
});
|
|
144
|
+
this.runtimeObservers.forEach((observer) => {
|
|
145
|
+
try {
|
|
146
|
+
observer(payload);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.warn('[BrowserSession] runtime observer error', err);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.publishRuntimeState(payload);
|
|
153
|
+
}
|
|
154
|
+
publishRuntimeState(payload) {
|
|
155
|
+
try {
|
|
156
|
+
stateBus.setState(`browser-session:${this.id}`, {
|
|
157
|
+
status: 'running',
|
|
158
|
+
lastRuntimeEvent: payload?.type || 'unknown',
|
|
159
|
+
lastUrl: payload?.pageUrl || this.getCurrentUrl(),
|
|
160
|
+
lastUpdate: payload?.ts || Date.now(),
|
|
161
|
+
});
|
|
162
|
+
stateBus.publish('browser.runtime.event', payload);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
logDebug('browser-service', 'runtimeEvent:stateBus:error', {
|
|
166
|
+
sessionId: this.id,
|
|
167
|
+
error: err?.message || err,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
bindRuntimeBridge(page) {
|
|
172
|
+
if (this.bridgedPages.has(page))
|
|
173
|
+
return;
|
|
174
|
+
this.bridgedPages.add(page);
|
|
175
|
+
page.exposeFunction('webauto_dispatch', (evt) => {
|
|
176
|
+
this.emitRuntimeEvent({
|
|
177
|
+
...evt,
|
|
178
|
+
pageUrl: page.url(),
|
|
179
|
+
});
|
|
180
|
+
}).catch((err) => {
|
|
181
|
+
console.warn(`[session:${this.id}] failed to expose webauto_dispatch`, err?.message || err);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
getActivePage() {
|
|
185
|
+
if (this.page && !this.page.isClosed()) {
|
|
186
|
+
return this.page;
|
|
187
|
+
}
|
|
188
|
+
if (!this.context)
|
|
189
|
+
return null;
|
|
190
|
+
const alive = this.context.pages().find((p) => !p.isClosed());
|
|
191
|
+
if (alive) {
|
|
192
|
+
this.page = alive;
|
|
193
|
+
return alive;
|
|
194
|
+
}
|
|
195
|
+
this.page = undefined;
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
resolveDeviceScaleFactor() {
|
|
199
|
+
const raw = String(process.env.WEBAUTO_DEVICE_SCALE || '').trim();
|
|
200
|
+
if (raw) {
|
|
201
|
+
const parsed = Number(raw);
|
|
202
|
+
if (Number.isFinite(parsed) && parsed > 0)
|
|
203
|
+
return parsed;
|
|
204
|
+
}
|
|
205
|
+
if (os.platform() === 'win32' && this.options.profileId?.startsWith('xiaohongshu_')) {
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
async syncDeviceScaleFactor(page, viewport) {
|
|
211
|
+
if (String(this.options.engine ?? 'camoufox') !== 'chromium')
|
|
212
|
+
return;
|
|
213
|
+
const desired = this.resolveDeviceScaleFactor();
|
|
214
|
+
if (!desired || !this.context)
|
|
215
|
+
return;
|
|
216
|
+
try {
|
|
217
|
+
const client = await this.context.newCDPSession(page);
|
|
218
|
+
await client.send('Emulation.setDeviceMetricsOverride', {
|
|
219
|
+
width: viewport.width,
|
|
220
|
+
height: viewport.height,
|
|
221
|
+
deviceScaleFactor: desired,
|
|
222
|
+
mobile: false,
|
|
223
|
+
scale: 1,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
console.warn(`[browser-session] sync device scale failed: ${error?.message || String(error)}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async ensurePageViewport(page) {
|
|
231
|
+
if (!this.lastViewport)
|
|
232
|
+
return;
|
|
233
|
+
const current = page.viewportSize();
|
|
234
|
+
if (current && current.width === this.lastViewport.width && current.height === this.lastViewport.height) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
await page.setViewportSize({
|
|
238
|
+
width: this.lastViewport.width,
|
|
239
|
+
height: this.lastViewport.height,
|
|
240
|
+
});
|
|
241
|
+
await this.syncWindowBounds(page, { ...this.lastViewport });
|
|
242
|
+
await this.syncDeviceScaleFactor(page, { ...this.lastViewport });
|
|
243
|
+
}
|
|
244
|
+
ensureContext() {
|
|
245
|
+
if (!this.context) {
|
|
246
|
+
throw new Error('browser context not ready');
|
|
247
|
+
}
|
|
248
|
+
return this.context;
|
|
249
|
+
}
|
|
250
|
+
async ensurePrimaryPage() {
|
|
251
|
+
const ctx = this.ensureContext();
|
|
252
|
+
const existing = this.getActivePage();
|
|
253
|
+
if (existing) {
|
|
254
|
+
return existing;
|
|
255
|
+
}
|
|
256
|
+
this.page = await ctx.newPage();
|
|
257
|
+
this.setupPageHooks(this.page);
|
|
258
|
+
try {
|
|
259
|
+
await this.ensurePageViewport(this.page);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
/* ignore */
|
|
263
|
+
}
|
|
264
|
+
return this.page;
|
|
265
|
+
}
|
|
266
|
+
async ensurePage(url) {
|
|
267
|
+
let page = await this.ensurePrimaryPage();
|
|
268
|
+
if (url) {
|
|
269
|
+
const current = this.getCurrentUrl();
|
|
270
|
+
if (!current || this.normalizeUrl(current) !== this.normalizeUrl(url)) {
|
|
271
|
+
await this.goto(url);
|
|
272
|
+
page = await this.ensurePrimaryPage();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return page;
|
|
276
|
+
}
|
|
277
|
+
async goBack() {
|
|
278
|
+
const page = await this.ensurePrimaryPage();
|
|
279
|
+
try {
|
|
280
|
+
const res = await page
|
|
281
|
+
.goBack({ waitUntil: 'domcontentloaded' })
|
|
282
|
+
.catch(() => null);
|
|
283
|
+
await ensurePageRuntime(page, true).catch(() => { });
|
|
284
|
+
this.lastKnownUrl = page.url();
|
|
285
|
+
return { ok: Boolean(res), url: page.url() };
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
await ensurePageRuntime(page, true).catch(() => { });
|
|
289
|
+
this.lastKnownUrl = page.url();
|
|
290
|
+
return { ok: false, url: page.url() };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
listPages() {
|
|
294
|
+
if (!this.context)
|
|
295
|
+
return [];
|
|
296
|
+
const pages = this.context.pages().filter((p) => !p.isClosed());
|
|
297
|
+
const active = this.getActivePage();
|
|
298
|
+
return pages.map((p, index) => ({
|
|
299
|
+
index,
|
|
300
|
+
url: p.url(),
|
|
301
|
+
active: active === p,
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
async newPage(url) {
|
|
305
|
+
const ctx = this.ensureContext();
|
|
306
|
+
const isMac = process.platform === 'darwin';
|
|
307
|
+
const shortcut = isMac ? 'Meta+t' : 'Control+t';
|
|
308
|
+
let page = null;
|
|
309
|
+
// Strictly use keyboard shortcut to create a new tab in the same window
|
|
310
|
+
const opener = this.page || ctx.pages()[0];
|
|
311
|
+
if (!opener)
|
|
312
|
+
throw new Error('no_opener_page');
|
|
313
|
+
await opener.bringToFront().catch(() => null);
|
|
314
|
+
const before = ctx.pages().filter((p) => !p.isClosed()).length;
|
|
315
|
+
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
316
|
+
const waitPage = ctx.waitForEvent('page', { timeout: 8000 }).catch(() => null);
|
|
317
|
+
await opener.keyboard.press(shortcut).catch(() => null);
|
|
318
|
+
page = await waitPage;
|
|
319
|
+
const pagesNow = ctx.pages().filter((p) => !p.isClosed());
|
|
320
|
+
const after = pagesNow.length;
|
|
321
|
+
if (page && after > before)
|
|
322
|
+
break;
|
|
323
|
+
if (!page && after > before) {
|
|
324
|
+
page = pagesNow[pagesNow.length - 1] || null;
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
328
|
+
}
|
|
329
|
+
const after = ctx.pages().filter((p) => !p.isClosed()).length;
|
|
330
|
+
if (!page || after <= before) {
|
|
331
|
+
throw new Error('new_tab_failed');
|
|
332
|
+
}
|
|
333
|
+
this.setupPageHooks(page);
|
|
334
|
+
this.page = page;
|
|
335
|
+
try {
|
|
336
|
+
await this.ensurePageViewport(page);
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
/* ignore */
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
await this.maybeCenterWindow(page, this.lastViewport || { width: 1920, height: 1080 });
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
/* ignore */
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
await page.bringToFront();
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
/* ignore */
|
|
352
|
+
}
|
|
353
|
+
if (url) {
|
|
354
|
+
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
355
|
+
await ensurePageRuntime(page);
|
|
356
|
+
this.lastKnownUrl = url;
|
|
357
|
+
}
|
|
358
|
+
const pages = ctx.pages().filter((p) => !p.isClosed());
|
|
359
|
+
return { index: Math.max(0, pages.indexOf(page)), url: page.url() };
|
|
360
|
+
}
|
|
361
|
+
async switchPage(index) {
|
|
362
|
+
const ctx = this.ensureContext();
|
|
363
|
+
const pages = ctx.pages().filter((p) => !p.isClosed());
|
|
364
|
+
const idx = Number(index);
|
|
365
|
+
if (!Number.isFinite(idx) || idx < 0 || idx >= pages.length) {
|
|
366
|
+
throw new Error(`invalid_page_index: ${index}`);
|
|
367
|
+
}
|
|
368
|
+
const page = pages[idx];
|
|
369
|
+
this.page = page;
|
|
370
|
+
try {
|
|
371
|
+
await this.ensurePageViewport(page);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
/* ignore */
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
await page.bringToFront();
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
/* ignore */
|
|
381
|
+
}
|
|
382
|
+
await ensurePageRuntime(page, true).catch(() => { });
|
|
383
|
+
this.lastKnownUrl = page.url();
|
|
384
|
+
return { index: idx, url: page.url() };
|
|
385
|
+
}
|
|
386
|
+
async closePage(index) {
|
|
387
|
+
const ctx = this.ensureContext();
|
|
388
|
+
const pages = ctx.pages().filter((p) => !p.isClosed());
|
|
389
|
+
if (pages.length === 0) {
|
|
390
|
+
return { closedIndex: -1, activeIndex: -1, total: 0 };
|
|
391
|
+
}
|
|
392
|
+
const active = this.getActivePage();
|
|
393
|
+
const requested = typeof index === 'number' && Number.isFinite(index) ? index : null;
|
|
394
|
+
const closedIndex = requested !== null ? requested : Math.max(0, pages.findIndex((p) => p === active));
|
|
395
|
+
if (closedIndex < 0 || closedIndex >= pages.length) {
|
|
396
|
+
throw new Error(`invalid_page_index: ${index}`);
|
|
397
|
+
}
|
|
398
|
+
const page = pages[closedIndex];
|
|
399
|
+
await page.close().catch(() => { });
|
|
400
|
+
const remaining = ctx.pages().filter((p) => !p.isClosed());
|
|
401
|
+
const nextIndex = remaining.length === 0 ? -1 : Math.min(Math.max(0, closedIndex - 1), remaining.length - 1);
|
|
402
|
+
if (nextIndex >= 0) {
|
|
403
|
+
const nextPage = remaining[nextIndex];
|
|
404
|
+
this.page = nextPage;
|
|
405
|
+
try {
|
|
406
|
+
await nextPage.bringToFront();
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
/* ignore */
|
|
410
|
+
}
|
|
411
|
+
await ensurePageRuntime(nextPage, true).catch(() => { });
|
|
412
|
+
this.lastKnownUrl = nextPage.url();
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
this.page = undefined;
|
|
416
|
+
}
|
|
417
|
+
return { closedIndex, activeIndex: nextIndex, total: remaining.length };
|
|
418
|
+
}
|
|
419
|
+
async saveCookiesForActivePage() {
|
|
420
|
+
if (!this.context)
|
|
421
|
+
return [];
|
|
422
|
+
const page = this.getActivePage();
|
|
423
|
+
if (!page)
|
|
424
|
+
return [];
|
|
425
|
+
const cookies = await this.context.cookies();
|
|
426
|
+
if (!cookies.length)
|
|
427
|
+
return [];
|
|
428
|
+
const digest = this.hashCookies(cookies);
|
|
429
|
+
const now = Date.now();
|
|
430
|
+
if (digest === this.lastCookieSignature && now - this.lastCookieSaveTs < 2000) {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
const targets = this.resolveCookieTargets(page.url());
|
|
434
|
+
if (!targets.length)
|
|
435
|
+
return [];
|
|
436
|
+
const payload = JSON.stringify({
|
|
437
|
+
timestamp: now,
|
|
438
|
+
profileId: this.options.profileId,
|
|
439
|
+
url: page.url(),
|
|
440
|
+
cookies,
|
|
441
|
+
}, null, 2);
|
|
442
|
+
const results = [];
|
|
443
|
+
for (const target of targets) {
|
|
444
|
+
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
|
445
|
+
await fs.promises.writeFile(target, payload, 'utf-8');
|
|
446
|
+
results.push({ path: target, count: cookies.length });
|
|
447
|
+
}
|
|
448
|
+
this.lastCookieSignature = digest;
|
|
449
|
+
this.lastCookieSaveTs = now;
|
|
450
|
+
return results;
|
|
451
|
+
}
|
|
452
|
+
async getCookies() {
|
|
453
|
+
if (!this.context)
|
|
454
|
+
return [];
|
|
455
|
+
return this.context.cookies();
|
|
456
|
+
}
|
|
457
|
+
async saveCookiesToFile(filePath) {
|
|
458
|
+
const cookies = await this.getCookies();
|
|
459
|
+
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
460
|
+
await fs.promises.writeFile(filePath, JSON.stringify({ timestamp: Date.now(), cookies }, null, 2), 'utf-8');
|
|
461
|
+
return { path: filePath, count: cookies.length };
|
|
462
|
+
}
|
|
463
|
+
async saveCookiesIfStable(filePath, opts = {}) {
|
|
464
|
+
const minDelayMs = Math.max(1000, Number(opts.minDelayMs) || 2000);
|
|
465
|
+
const page = this.getActivePage();
|
|
466
|
+
if (!page)
|
|
467
|
+
return null;
|
|
468
|
+
const html = await page.content();
|
|
469
|
+
const isLoggedIn = html.includes('Frame_wrap_') && !html.includes('LoginCard') && !html.includes('passport');
|
|
470
|
+
if (!isLoggedIn)
|
|
471
|
+
return null;
|
|
472
|
+
const cookies = await this.getCookies();
|
|
473
|
+
if (!cookies.length)
|
|
474
|
+
return null;
|
|
475
|
+
const digest = this.hashCookies(cookies);
|
|
476
|
+
const now = Date.now();
|
|
477
|
+
if (digest === this.lastCookieSignature && now - this.lastCookieSaveTs < minDelayMs) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
481
|
+
await fs.promises.writeFile(filePath, JSON.stringify({ timestamp: now, cookies }, null, 2), 'utf-8');
|
|
482
|
+
this.lastCookieSignature = digest;
|
|
483
|
+
this.lastCookieSaveTs = now;
|
|
484
|
+
return { path: filePath, count: cookies.length };
|
|
485
|
+
}
|
|
486
|
+
async injectCookiesFromFile(filePath) {
|
|
487
|
+
if (!this.context)
|
|
488
|
+
throw new Error('context not ready');
|
|
489
|
+
const raw = JSON.parse(await fs.promises.readFile(filePath, 'utf-8'));
|
|
490
|
+
const cookies = Array.isArray(raw) ? raw : Array.isArray(raw?.cookies) ? raw.cookies : [];
|
|
491
|
+
if (!cookies.length)
|
|
492
|
+
return { count: 0 };
|
|
493
|
+
await this.context.addCookies(cookies);
|
|
494
|
+
return { count: cookies.length };
|
|
495
|
+
}
|
|
496
|
+
async goto(url) {
|
|
497
|
+
const page = await this.ensurePrimaryPage();
|
|
498
|
+
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
499
|
+
await ensurePageRuntime(page);
|
|
500
|
+
this.lastKnownUrl = url;
|
|
501
|
+
}
|
|
502
|
+
async screenshot(fullPage = true) {
|
|
503
|
+
const page = await this.ensurePrimaryPage();
|
|
504
|
+
return page.screenshot({ fullPage });
|
|
505
|
+
}
|
|
506
|
+
async click(selector) {
|
|
507
|
+
const page = await this.ensurePrimaryPage();
|
|
508
|
+
await page.click(selector, { timeout: 20000 });
|
|
509
|
+
}
|
|
510
|
+
async fill(selector, text) {
|
|
511
|
+
const page = await this.ensurePrimaryPage();
|
|
512
|
+
await page.fill(selector, text, { timeout: 20000 });
|
|
513
|
+
}
|
|
514
|
+
async ensureInputReady(page) {
|
|
515
|
+
if (this.options.headless)
|
|
516
|
+
return;
|
|
517
|
+
if (os.platform() !== 'win32')
|
|
518
|
+
return;
|
|
519
|
+
let needsFocus = false;
|
|
520
|
+
try {
|
|
521
|
+
const state = await page.evaluate(() => ({
|
|
522
|
+
hasFocus: typeof document?.hasFocus === 'function' ? document.hasFocus() : true,
|
|
523
|
+
hidden: !!document?.hidden,
|
|
524
|
+
visibilityState: String(document?.visibilityState || 'visible'),
|
|
525
|
+
}));
|
|
526
|
+
needsFocus = !state.hasFocus || state.hidden || state.visibilityState !== 'visible';
|
|
527
|
+
}
|
|
528
|
+
catch {
|
|
529
|
+
// If we cannot read focus state, conservatively try to bring page to front.
|
|
530
|
+
needsFocus = true;
|
|
531
|
+
}
|
|
532
|
+
if (!needsFocus)
|
|
533
|
+
return;
|
|
534
|
+
try {
|
|
535
|
+
await page.bringToFront();
|
|
536
|
+
await page.waitForTimeout(80);
|
|
537
|
+
}
|
|
538
|
+
catch {
|
|
539
|
+
// Keep best-effort behavior and do not block input flow on platform quirks.
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* 基于屏幕坐标的系统级鼠标点击(Playwright 原生)
|
|
544
|
+
* @param opts 屏幕坐标及点击选项
|
|
545
|
+
*/
|
|
546
|
+
async mouseClick(opts) {
|
|
547
|
+
const page = await this.ensurePrimaryPage();
|
|
548
|
+
await this.ensureInputReady(page);
|
|
549
|
+
const { x, y, button = 'left', clicks = 1, delay = 50 } = opts;
|
|
550
|
+
// 移动鼠标到目标位置(模拟轨迹)
|
|
551
|
+
await page.mouse.move(x, y, { steps: 3 });
|
|
552
|
+
// 执行点击(支持多次、间隔随机抖动)
|
|
553
|
+
for (let i = 0; i < clicks; i++) {
|
|
554
|
+
if (i > 0) {
|
|
555
|
+
// 多次点击间隔 100-200ms
|
|
556
|
+
await new Promise(r => setTimeout(r, 100 + Math.random() * 100));
|
|
557
|
+
}
|
|
558
|
+
await page.mouse.click(x, y, {
|
|
559
|
+
button,
|
|
560
|
+
clickCount: 1,
|
|
561
|
+
delay // 按键间隔
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* 基于屏幕坐标的鼠标移动(Playwright 原生)
|
|
567
|
+
* @param opts 目标坐标及移动选项
|
|
568
|
+
*/
|
|
569
|
+
async mouseMove(opts) {
|
|
570
|
+
const page = await this.ensurePrimaryPage();
|
|
571
|
+
await this.ensureInputReady(page);
|
|
572
|
+
const { x, y, steps = 3 } = opts;
|
|
573
|
+
await page.mouse.move(x, y, { steps });
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* 基于键盘的系统输入(Playwright keyboard)
|
|
577
|
+
*/
|
|
578
|
+
async keyboardType(opts) {
|
|
579
|
+
const page = await this.ensurePrimaryPage();
|
|
580
|
+
await this.ensureInputReady(page);
|
|
581
|
+
const { text, delay = 80, submit } = opts;
|
|
582
|
+
if (text && text.length > 0) {
|
|
583
|
+
await page.keyboard.type(text, { delay });
|
|
584
|
+
}
|
|
585
|
+
if (submit) {
|
|
586
|
+
await page.keyboard.press('Enter');
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
async keyboardPress(opts) {
|
|
590
|
+
const page = await this.ensurePrimaryPage();
|
|
591
|
+
await this.ensureInputReady(page);
|
|
592
|
+
const { key, delay } = opts;
|
|
593
|
+
await page.keyboard.press(key, typeof delay === 'number' ? { delay } : undefined);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* 基于鼠标滚轮的系统滚动(Playwright mouse.wheel)
|
|
597
|
+
* @param opts deltaY 为垂直滚动(正=向下,负=向上),deltaX 可选
|
|
598
|
+
*/
|
|
599
|
+
async mouseWheel(opts) {
|
|
600
|
+
const page = await this.ensurePrimaryPage();
|
|
601
|
+
await this.ensureInputReady(page);
|
|
602
|
+
const { deltaX = 0, deltaY } = opts;
|
|
603
|
+
await page.mouse.wheel(Number(deltaX) || 0, Number(deltaY) || 0);
|
|
604
|
+
}
|
|
605
|
+
async syncWindowBounds(page, viewport) {
|
|
606
|
+
const engine = String(this.options.engine ?? 'camoufox');
|
|
607
|
+
// Log viewport metrics for diagnosis
|
|
608
|
+
try {
|
|
609
|
+
const metrics = await page.evaluate(() => ({
|
|
610
|
+
innerWidth: window.innerWidth || 0,
|
|
611
|
+
innerHeight: window.innerHeight || 0,
|
|
612
|
+
outerWidth: window.outerWidth || 0,
|
|
613
|
+
outerHeight: window.outerHeight || 0,
|
|
614
|
+
screenX: Math.floor(window.screenX || 0),
|
|
615
|
+
screenY: Math.floor(window.screenY || 0),
|
|
616
|
+
devicePixelRatio: window.devicePixelRatio || 1,
|
|
617
|
+
visualViewport: window.visualViewport ? {
|
|
618
|
+
width: window.visualViewport.width || 0,
|
|
619
|
+
height: window.visualViewport.height || 0,
|
|
620
|
+
offsetLeft: window.visualViewport.offsetLeft || 0,
|
|
621
|
+
offsetTop: window.visualViewport.offsetTop || 0,
|
|
622
|
+
scale: window.visualViewport.scale || 1,
|
|
623
|
+
} : null,
|
|
624
|
+
}));
|
|
625
|
+
console.log(`[viewport-metrics] target=${viewport.width}x${viewport.height} inner=${metrics.innerWidth}x${metrics.innerHeight} outer=${metrics.outerWidth}x${metrics.outerHeight} screen=(${metrics.screenX},${metrics.screenY}) dpr=${metrics.devicePixelRatio} visual=${JSON.stringify(metrics.visualViewport)}`);
|
|
626
|
+
// If inner dimensions don't match target, retry setViewportSize
|
|
627
|
+
const widthDelta = Math.abs(metrics.innerWidth - viewport.width);
|
|
628
|
+
const heightDelta = Math.abs(metrics.innerHeight - viewport.height);
|
|
629
|
+
if (widthDelta > 50 || heightDelta > 50) {
|
|
630
|
+
console.warn(`[viewport-metrics] MISMATCH detected: widthDelta=${widthDelta} heightDelta=${heightDelta}, retrying setViewportSize...`);
|
|
631
|
+
await page.setViewportSize({ width: viewport.width, height: viewport.height });
|
|
632
|
+
await page.waitForTimeout(500);
|
|
633
|
+
const retry = await page.evaluate(() => ({
|
|
634
|
+
innerWidth: window.innerWidth || 0,
|
|
635
|
+
innerHeight: window.innerHeight || 0,
|
|
636
|
+
}));
|
|
637
|
+
console.log(`[viewport-metrics] after retry: inner=${retry.innerWidth}x${retry.innerHeight}`);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
catch (err) {
|
|
641
|
+
console.warn(`[viewport-metrics] log failed: ${err?.message || String(err)}`);
|
|
642
|
+
}
|
|
643
|
+
if (engine !== 'chromium')
|
|
644
|
+
return;
|
|
645
|
+
if (this.options.headless)
|
|
646
|
+
return;
|
|
647
|
+
if (!this.context)
|
|
648
|
+
return;
|
|
649
|
+
try {
|
|
650
|
+
const client = await this.context.newCDPSession(page);
|
|
651
|
+
const { windowId } = await client.send('Browser.getWindowForTarget');
|
|
652
|
+
const metrics = await page.evaluate(() => ({
|
|
653
|
+
innerWidth: window.innerWidth || 0,
|
|
654
|
+
innerHeight: window.innerHeight || 0,
|
|
655
|
+
outerWidth: window.outerWidth || 0,
|
|
656
|
+
outerHeight: window.outerHeight || 0,
|
|
657
|
+
}));
|
|
658
|
+
const deltaW = Math.max(0, Math.floor((metrics.outerWidth || 0) - (metrics.innerWidth || 0)));
|
|
659
|
+
const deltaH = Math.max(0, Math.floor((metrics.outerHeight || 0) - (metrics.innerHeight || 0)));
|
|
660
|
+
const targetWidth = Math.max(300, Math.floor(Number(viewport.width) + deltaW));
|
|
661
|
+
const targetHeight = Math.max(300, Math.floor(Number(viewport.height) + deltaH));
|
|
662
|
+
await client.send('Browser.setWindowBounds', {
|
|
663
|
+
windowId,
|
|
664
|
+
bounds: { width: targetWidth, height: targetHeight },
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
catch (error) {
|
|
668
|
+
console.warn(`[browser-session] sync window bounds failed: ${error?.message || String(error)}`);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
async maybeCenterWindow(page, viewport) {
|
|
672
|
+
if (this.options.headless)
|
|
673
|
+
return;
|
|
674
|
+
try {
|
|
675
|
+
const metrics = await page.evaluate(() => ({
|
|
676
|
+
screenX: Math.floor(window.screenX || 0),
|
|
677
|
+
screenY: Math.floor(window.screenY || 0),
|
|
678
|
+
outerWidth: Math.floor(window.outerWidth || 0),
|
|
679
|
+
outerHeight: Math.floor(window.outerHeight || 0),
|
|
680
|
+
innerWidth: Math.floor(window.innerWidth || 0),
|
|
681
|
+
innerHeight: Math.floor(window.innerHeight || 0),
|
|
682
|
+
screenWidth: Math.floor(window.screen?.availWidth || window.screen?.width || 0),
|
|
683
|
+
screenHeight: Math.floor(window.screen?.availHeight || window.screen?.height || 0),
|
|
684
|
+
}));
|
|
685
|
+
const sw = Math.max(metrics.screenWidth || 0, viewport.width);
|
|
686
|
+
const sh = Math.max(metrics.screenHeight || 0, viewport.height);
|
|
687
|
+
// Try to resize outer window to fit viewport (inner) + chrome delta
|
|
688
|
+
const deltaW = Math.max(0, (metrics.outerWidth || 0) - (metrics.innerWidth || 0));
|
|
689
|
+
const deltaH = Math.max(0, (metrics.outerHeight || 0) - (metrics.innerHeight || 0));
|
|
690
|
+
const targetOuterW = Math.max(viewport.width + deltaW, 300);
|
|
691
|
+
const targetOuterH = Math.max(viewport.height + deltaH, 300);
|
|
692
|
+
await page.evaluate(({ w, h }) => { try {
|
|
693
|
+
window.resizeTo(w, h);
|
|
694
|
+
}
|
|
695
|
+
catch { } }, { w: targetOuterW, h: targetOuterH });
|
|
696
|
+
await page.waitForTimeout(200);
|
|
697
|
+
const ow = Math.max(metrics.outerWidth || 0, targetOuterW);
|
|
698
|
+
const oh = Math.max(metrics.outerHeight || 0, targetOuterH);
|
|
699
|
+
const targetX = Math.max(0, Math.floor((sw - ow) / 2));
|
|
700
|
+
const targetY = Math.max(0, Math.floor((sh - oh) / 2));
|
|
701
|
+
// Only move if we're clearly off-center
|
|
702
|
+
if (Math.abs(metrics.screenX - targetX) > 5 || Math.abs(metrics.screenY - targetY) > 5) {
|
|
703
|
+
await page.evaluate(({ x, y }) => { try {
|
|
704
|
+
window.moveTo(x, y);
|
|
705
|
+
}
|
|
706
|
+
catch { } }, { x: targetX, y: targetY });
|
|
707
|
+
await page.waitForTimeout(200);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
catch (err) {
|
|
711
|
+
console.warn('[browser-session] maybeCenterWindow failed:', err?.message || String(err));
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
async setViewportSize(opts) {
|
|
715
|
+
const page = await this.ensurePrimaryPage();
|
|
716
|
+
const width = Math.max(800, Math.floor(Number(opts.width) || 0));
|
|
717
|
+
const height = Math.max(700, Math.floor(Number(opts.height) || 0));
|
|
718
|
+
if (!width || !height) {
|
|
719
|
+
throw new Error('invalid_viewport_size');
|
|
720
|
+
}
|
|
721
|
+
await page.setViewportSize({ width, height });
|
|
722
|
+
await this.syncWindowBounds(page, { width, height });
|
|
723
|
+
await this.syncDeviceScaleFactor(page, { width, height });
|
|
724
|
+
await this.maybeCenterWindow(page, { width, height });
|
|
725
|
+
this.lastViewport = { width, height };
|
|
726
|
+
return { width, height };
|
|
727
|
+
}
|
|
728
|
+
async evaluate(expression, arg) {
|
|
729
|
+
const page = await this.ensurePrimaryPage();
|
|
730
|
+
if (typeof arg === 'undefined') {
|
|
731
|
+
return page.evaluate(expression);
|
|
732
|
+
}
|
|
733
|
+
return page.evaluate(expression, arg);
|
|
734
|
+
}
|
|
735
|
+
getCurrentUrl() {
|
|
736
|
+
const page = this.getActivePage();
|
|
737
|
+
if (page) {
|
|
738
|
+
return page.url() || this.lastKnownUrl;
|
|
739
|
+
}
|
|
740
|
+
return this.lastKnownUrl;
|
|
741
|
+
}
|
|
742
|
+
resolveCookieTargets(currentUrl) {
|
|
743
|
+
const cookieDir = resolveCookiesRoot();
|
|
744
|
+
const targets = new Set([path.join(cookieDir, `${this.options.profileId}.json`)]);
|
|
745
|
+
if (currentUrl) {
|
|
746
|
+
try {
|
|
747
|
+
const { hostname } = new URL(currentUrl);
|
|
748
|
+
const hostSegment = this.sanitizeHost(hostname);
|
|
749
|
+
if (hostSegment) {
|
|
750
|
+
targets.add(path.join(cookieDir, `${hostSegment}-latest.json`));
|
|
751
|
+
}
|
|
752
|
+
if (hostname && hostname.includes('weibo')) {
|
|
753
|
+
targets.add(path.join(cookieDir, 'weibo.com-latest.json'));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
catch {
|
|
757
|
+
targets.add(path.join(cookieDir, 'default-latest.json'));
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return Array.from(targets);
|
|
761
|
+
}
|
|
762
|
+
sanitizeHost(host) {
|
|
763
|
+
if (!host)
|
|
764
|
+
return 'default';
|
|
765
|
+
return host.replace(/[^a-z0-9.-]/gi, '_');
|
|
766
|
+
}
|
|
767
|
+
hashCookies(cookies) {
|
|
768
|
+
const normalized = cookies
|
|
769
|
+
.map((c) => ({
|
|
770
|
+
name: c.name,
|
|
771
|
+
value: c.value,
|
|
772
|
+
domain: c.domain,
|
|
773
|
+
path: c.path,
|
|
774
|
+
expires: c.expires,
|
|
775
|
+
httpOnly: !!c.httpOnly,
|
|
776
|
+
secure: !!c.secure,
|
|
777
|
+
}))
|
|
778
|
+
.sort((a, b) => {
|
|
779
|
+
if (a.domain === b.domain) {
|
|
780
|
+
if (a.name === b.name)
|
|
781
|
+
return (a.path || '').localeCompare(b.path || '');
|
|
782
|
+
return a.name.localeCompare(b.name);
|
|
783
|
+
}
|
|
784
|
+
return (a.domain || '').localeCompare(b.domain || '');
|
|
785
|
+
});
|
|
786
|
+
const hash = crypto.createHash('sha1');
|
|
787
|
+
hash.update(JSON.stringify(normalized));
|
|
788
|
+
return hash.digest('hex');
|
|
789
|
+
}
|
|
790
|
+
async close() {
|
|
791
|
+
try {
|
|
792
|
+
await this.context?.close();
|
|
793
|
+
}
|
|
794
|
+
finally {
|
|
795
|
+
await this.browser?.close();
|
|
796
|
+
this.lock.release();
|
|
797
|
+
this.runtimeObservers.clear();
|
|
798
|
+
this.notifyExit();
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
notifyExit() {
|
|
802
|
+
if (this.exitNotified)
|
|
803
|
+
return;
|
|
804
|
+
this.exitNotified = true;
|
|
805
|
+
this.onExit?.(this.options.profileId);
|
|
806
|
+
}
|
|
807
|
+
normalizeUrl(raw) {
|
|
808
|
+
try {
|
|
809
|
+
const url = new URL(raw);
|
|
810
|
+
return `${url.origin}${url.pathname}`;
|
|
811
|
+
}
|
|
812
|
+
catch {
|
|
813
|
+
return raw;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
//# sourceMappingURL=BrowserSession.js.map
|