@andorra-labs/code 0.1.11 → 0.1.13
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/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/account-presentation.d.ts +1 -37
- package/dist/src/account-presentation.js +2 -42
- package/dist/src/activity.d.ts +0 -25
- package/dist/src/activity.js +1 -23
- package/dist/src/agent-definitions.d.ts +0 -26
- package/dist/src/agent-definitions.js +0 -43
- package/dist/src/agent-execution.d.ts +0 -2
- package/dist/src/agent-execution.js +59 -414
- package/dist/src/agent-mcp-catalog.d.ts +0 -8
- package/dist/src/agent-mcp-catalog.js +0 -2
- package/dist/src/agent-mcp.d.ts +0 -56
- package/dist/src/agent-mcp.js +14 -153
- package/dist/src/agent-modifiers.d.ts +0 -1
- package/dist/src/agent-modifiers.js +25 -68
- package/dist/src/analytics.d.ts +0 -66
- package/dist/src/analytics.js +0 -45
- package/dist/src/anthropic-console-auth.d.ts +0 -24
- package/dist/src/anthropic-console-auth.js +0 -37
- package/dist/src/anthropic-credentials.d.ts +0 -25
- package/dist/src/anthropic-credentials.js +0 -28
- package/dist/src/app-server/protocol.d.ts +19 -244
- package/dist/src/app-server/protocol.js +1 -132
- package/dist/src/app-server/reasoning.d.ts +0 -31
- package/dist/src/app-server/reasoning.js +0 -54
- package/dist/src/app-server/terminal.d.ts +0 -36
- package/dist/src/app-server/terminal.js +3 -39
- package/dist/src/app-server/workspace.d.ts +0 -167
- package/dist/src/app-server/workspace.js +4 -406
- package/dist/src/app-server.d.ts +33 -918
- package/dist/src/app-server.js +608 -2984
- package/dist/src/artifacts.d.ts +0 -10
- package/dist/src/artifacts.js +1 -11
- package/dist/src/attachments.d.ts +4 -98
- package/dist/src/attachments.js +10 -130
- package/dist/src/auth/AuthManager.d.ts +0 -93
- package/dist/src/auth/AuthManager.js +3 -165
- package/dist/src/auth/callback-page.d.ts +0 -1
- package/dist/src/auth/callback-page.js +0 -4
- package/dist/src/auth/callback.d.ts +0 -25
- package/dist/src/auth/callback.js +1 -29
- package/dist/src/auth/deployment.d.ts +0 -16
- package/dist/src/auth/deployment.js +0 -16
- package/dist/src/auth/index.d.ts +0 -11
- package/dist/src/auth/index.js +0 -11
- package/dist/src/auth/lock.d.ts +0 -1
- package/dist/src/auth/lock.js +0 -1
- package/dist/src/auth/store.d.ts +7 -108
- package/dist/src/auth/store.js +21 -129
- package/dist/src/auth/types.d.ts +0 -8
- package/dist/src/auth-commands.d.ts +0 -5
- package/dist/src/auth-commands.js +0 -1
- package/dist/src/automation-runner.d.ts +0 -9
- package/dist/src/automation-runner.js +0 -11
- package/dist/src/automation-service.d.ts +0 -10
- package/dist/src/automation-service.js +3 -17
- package/dist/src/automation-tool.js +0 -5
- package/dist/src/automation-worker-shutdown.d.ts +0 -1
- package/dist/src/automation-worker-shutdown.js +0 -3
- package/dist/src/automations.d.ts +23 -2
- package/dist/src/automations.js +91 -12
- package/dist/src/background-tasks.d.ts +0 -23
- package/dist/src/background-tasks.js +0 -11
- package/dist/src/boot-trace.d.ts +0 -13
- package/dist/src/boot-trace.js +1 -14
- package/dist/src/browser-activity.js +0 -2
- package/dist/src/browser-bridge.d.ts +0 -2
- package/dist/src/browser-bridge.js +0 -27
- package/dist/src/browser-captcha-tool.d.ts +0 -13
- package/dist/src/browser-captcha-tool.js +3 -35
- package/dist/src/browser-extensions-tool.d.ts +24 -0
- package/dist/src/browser-extensions-tool.js +137 -0
- package/dist/src/browser-extensions.d.ts +127 -0
- package/dist/src/browser-extensions.js +729 -0
- package/dist/src/browser-observation.d.ts +0 -15
- package/dist/src/browser-observation.js +1 -22
- package/dist/src/browser-panel-tool.d.ts +10 -25
- package/dist/src/browser-panel-tool.js +64 -60
- package/dist/src/browser-runner.d.ts +0 -1
- package/dist/src/browser-runner.js +7 -46
- package/dist/src/browser-server.d.ts +0 -6
- package/dist/src/browser-server.js +6 -229
- package/dist/src/browser-session.d.ts +0 -25
- package/dist/src/browser-session.js +1 -71
- package/dist/src/browser-stealth.d.ts +0 -12
- package/dist/src/browser-stealth.js +0 -36
- package/dist/src/browser-ui/app.js +7 -174
- package/dist/src/browser-ui/style.css +0 -68
- package/dist/src/browser-ui/tokens.css +11 -93
- package/dist/src/browser-view.d.ts +52 -290
- package/dist/src/browser-view.js +354 -567
- package/dist/src/capabilities.d.ts +0 -8
- package/dist/src/capabilities.js +0 -29
- package/dist/src/capsolver.d.ts +0 -13
- package/dist/src/capsolver.js +0 -15
- package/dist/src/clarification-ui.d.ts +0 -7
- package/dist/src/clarification-ui.js +0 -8
- package/dist/src/claude-executable.d.ts +0 -1
- package/dist/src/claude-executable.js +1 -2
- package/dist/src/claude-provider.d.ts +6 -19
- package/dist/src/claude-provider.js +166 -61
- package/dist/src/cli-executable.d.ts +0 -16
- package/dist/src/cli-executable.js +0 -7
- package/dist/src/cli-process.d.ts +0 -26
- package/dist/src/cli-process.js +0 -18
- package/dist/src/cli-sign-in.d.ts +0 -20
- package/dist/src/cli-sign-in.js +1 -17
- package/dist/src/cli.d.ts +3 -56
- package/dist/src/cli.js +193 -702
- package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +4 -59
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +27 -100
- package/dist/src/code-intelligence/ContextLedger.d.ts +0 -4
- package/dist/src/code-intelligence/ContextLedger.js +0 -10
- package/dist/src/code-intelligence/ContextRouter.d.ts +0 -6
- package/dist/src/code-intelligence/ContextRouter.js +0 -8
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.d.ts +0 -2
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.js +5 -12
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.d.ts +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.js +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.js +1 -17
- package/dist/src/code-intelligence/codegraph/repoExploreTool.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/repoExploreTool.js +0 -5
- package/dist/src/code-intelligence/repository.d.ts +0 -9
- package/dist/src/code-intelligence/repository.js +1 -11
- package/dist/src/code-intelligence/types.d.ts +0 -8
- package/dist/src/codex-auth.d.ts +0 -44
- package/dist/src/codex-auth.js +0 -45
- package/dist/src/codex-browser-auth.d.ts +0 -13
- package/dist/src/codex-browser-auth.js +3 -20
- package/dist/src/codex-errors.js +0 -2
- package/dist/src/codex-executable.d.ts +0 -2
- package/dist/src/codex-executable.js +1 -7
- package/dist/src/codex-provider.d.ts +0 -13
- package/dist/src/codex-provider.js +1 -26
- package/dist/src/codex-rpc.d.ts +0 -10
- package/dist/src/codex-rpc.js +0 -12
- package/dist/src/coding-tools.d.ts +6 -27
- package/dist/src/coding-tools.js +193 -205
- package/dist/src/command-metrics.d.ts +0 -4
- package/dist/src/command-output-tap.d.ts +0 -11
- package/dist/src/command-output-tap.js +0 -3
- package/dist/src/command-screens.d.ts +24 -0
- package/dist/src/command-screens.js +132 -100
- package/dist/src/commands.d.ts +6 -63
- package/dist/src/commands.js +20 -100
- package/dist/src/completion-gates.d.ts +0 -47
- package/dist/src/completion-gates.js +0 -14
- package/dist/src/completion.d.ts +2 -58
- package/dist/src/completion.js +90 -186
- package/dist/src/config.d.ts +12 -116
- package/dist/src/config.js +41 -171
- package/dist/src/context-budget.d.ts +0 -22
- package/dist/src/context-budget.js +0 -44
- package/dist/src/context-compaction.d.ts +29 -6
- package/dist/src/context-compaction.js +94 -25
- package/dist/src/context-selection.d.ts +0 -24
- package/dist/src/context-selection.js +0 -34
- package/dist/src/dashboard-view.d.ts +0 -2
- package/dist/src/dashboard-view.js +0 -35
- package/dist/src/dashboard.d.ts +0 -2
- package/dist/src/dashboard.js +0 -9
- package/dist/src/deadline.d.ts +0 -45
- package/dist/src/deadline.js +0 -54
- package/dist/src/decision/ContinuationAdapter.d.ts +0 -5
- package/dist/src/decision/ContinuationAdapter.js +0 -5
- package/dist/src/decision/DecisionEngine.d.ts +0 -4
- package/dist/src/decision/DecisionManager.d.ts +0 -1
- package/dist/src/decision/DecisionManager.js +2 -7
- package/dist/src/decision/DecisionPolicy.d.ts +0 -1
- package/dist/src/decision/DecisionPolicy.js +0 -1
- package/dist/src/decision/FactContinuations.d.ts +11 -43
- package/dist/src/decision/FactContinuations.js +126 -95
- package/dist/src/decision/FactServiceGate.d.ts +0 -1
- package/dist/src/decision/FactServiceGate.js +0 -4
- package/dist/src/decision/PreparedSteps.d.ts +0 -15
- package/dist/src/decision/PreparedSteps.js +1 -11
- package/dist/src/decision/applyToolMenu.d.ts +0 -1
- package/dist/src/decision/applyToolMenu.js +1 -5
- package/dist/src/decision/checks.d.ts +15 -28
- package/dist/src/decision/checks.js +118 -49
- package/dist/src/decision/facts.d.ts +0 -16
- package/dist/src/decision/facts.js +0 -30
- package/dist/src/decision/guidancePolicy.js +0 -1
- package/dist/src/decision/hostedPolicy.d.ts +0 -6
- package/dist/src/decision/hostedPolicy.js +0 -7
- package/dist/src/decision/hostedSkills.d.ts +0 -19
- package/dist/src/decision/hostedSkills.js +0 -19
- package/dist/src/decision/optimizationPolicy.d.ts +0 -3
- package/dist/src/decision/optimizationPolicy.js +1 -4
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +0 -7
- package/dist/src/decision/providers/AndorraDecisionProvider.js +4 -27
- package/dist/src/decision/providers/HttpDecisionProvider.d.ts +0 -2
- package/dist/src/decision/providers/HttpDecisionProvider.js +0 -6
- package/dist/src/decision/routeTools.d.ts +0 -8
- package/dist/src/decision/routeTools.js +1 -8
- package/dist/src/decision/toolFamilies.d.ts +0 -1
- package/dist/src/decision/toolFamilies.js +0 -1
- package/dist/src/decision/toolMenu.d.ts +0 -3
- package/dist/src/decision/toolMenu.js +0 -4
- package/dist/src/decision/types.d.ts +0 -6
- package/dist/src/default-graph.d.ts +0 -9
- package/dist/src/default-graph.js +0 -9
- package/dist/src/delegation-changes.d.ts +0 -56
- package/dist/src/delegation-changes.js +15 -124
- package/dist/src/diff-preview.d.ts +1 -1
- package/dist/src/diff-preview.js +4 -12
- package/dist/src/duration.d.ts +0 -50
- package/dist/src/duration.js +0 -50
- package/dist/src/efficiency.d.ts +0 -39
- package/dist/src/efficiency.js +0 -16
- package/dist/src/engine/protocol.d.ts +0 -2
- package/dist/src/engine/protocol.js +0 -2
- package/dist/src/engine-streams.d.ts +13 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.d.ts +3 -2
- package/dist/src/extensions.js +76 -37
- package/dist/src/favicons.d.ts +0 -26
- package/dist/src/favicons.js +0 -34
- package/dist/src/file-diff.d.ts +2 -58
- package/dist/src/file-diff.js +0 -32
- package/dist/src/file-read-key.d.ts +1 -0
- package/dist/src/file-read-key.js +5 -0
- package/dist/src/file-read-state.d.ts +0 -1
- package/dist/src/file-read-state.js +0 -4
- package/dist/src/firefox-cookies.d.ts +0 -34
- package/dist/src/firefox-cookies.js +1 -55
- package/dist/src/git-identity-audit.d.ts +27 -0
- package/dist/src/git-identity-audit.js +286 -0
- package/dist/src/git-identity-guard.d.ts +4 -0
- package/dist/src/git-identity-guard.js +998 -0
- package/dist/src/git-identity-hold.d.ts +12 -0
- package/dist/src/git-identity-hold.js +81 -0
- package/dist/src/git-summary.d.ts +0 -58
- package/dist/src/git-summary.js +2 -212
- package/dist/src/goal-completion-verification.d.ts +2 -2
- package/dist/src/goal-completion-verification.js +3 -6
- package/dist/src/graph-account.d.ts +0 -21
- package/dist/src/graph-account.js +0 -17
- package/dist/src/graph-editor-session.d.ts +0 -1
- package/dist/src/graph-editor-session.js +1 -3
- package/dist/src/graph-health.d.ts +7 -49
- package/dist/src/graph-health.js +35 -46
- package/dist/src/graph-manager-chat.d.ts +27 -128
- package/dist/src/graph-manager-chat.js +36 -166
- package/dist/src/graph-provider-portability.d.ts +1 -21
- package/dist/src/graph-provider-portability.js +6 -45
- package/dist/src/graph-quota.d.ts +0 -33
- package/dist/src/graph-quota.js +1 -44
- package/dist/src/graph-runner.d.ts +0 -1
- package/dist/src/graph-runner.js +47 -387
- package/dist/src/graph-selection.d.ts +0 -14
- package/dist/src/graph-selection.js +0 -14
- package/dist/src/graph-server.d.ts +3 -11
- package/dist/src/graph-server.js +70 -111
- package/dist/src/graph-studio-features.d.ts +0 -5
- package/dist/src/graph-studio-features.js +2 -42
- package/dist/src/graph-sync.d.ts +0 -78
- package/dist/src/graph-sync.js +5 -201
- package/dist/src/graph-tool.d.ts +0 -18
- package/dist/src/graph-tool.js +0 -27
- package/dist/src/graph-ui/app.js +229 -498
- package/dist/src/graph-ui/compat.js +0 -7
- package/dist/src/graph-ui/controls.css +47 -43
- package/dist/src/graph-ui/controls.js +0 -88
- package/dist/src/graph-ui/drafts.js +0 -12
- package/dist/src/graph-ui/edge-router.js +0 -62
- package/dist/src/graph-ui/embed.js +0 -59
- package/dist/src/graph-ui/icons.js +2 -7
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/library.css +0 -5
- package/dist/src/graph-ui/manager-markdown.js +0 -11
- package/dist/src/graph-ui/manager-state.js +110 -49
- package/dist/src/graph-ui/manager.css +2 -20
- package/dist/src/graph-ui/manager.js +251 -166
- package/dist/src/graph-ui/model-picker.js +250 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graph-ui/sidebar.js +2 -3
- package/dist/src/graph-ui/skill-picker.js +373 -39
- package/dist/src/graph-ui/studio-canvas.js +3 -38
- package/dist/src/graph-ui/studio.css +0 -18
- package/dist/src/graph-ui/studio.js +3 -71
- package/dist/src/graph-ui/style.css +11 -134
- package/dist/src/graph-ui/theme.js +1 -26
- package/dist/src/graph-ui/tokens.css +15 -114
- package/dist/src/graphs.d.ts +7 -156
- package/dist/src/graphs.js +72 -273
- package/dist/src/grep-regex-worker.js +0 -2
- package/dist/src/grep-regex.d.ts +1 -5
- package/dist/src/grep-regex.js +6 -8
- package/dist/src/grok-provider.d.ts +0 -17
- package/dist/src/grok-provider.js +1 -26
- package/dist/src/handoffs.d.ts +0 -11
- package/dist/src/handoffs.js +0 -13
- package/dist/src/hardened-runtime.d.ts +0 -10
- package/dist/src/hardened-runtime.js +8 -46
- package/dist/src/harness-home.d.ts +21 -0
- package/dist/src/harness-home.js +87 -0
- package/dist/src/host-process-guard.d.ts +0 -50
- package/dist/src/host-process-guard.js +0 -641
- package/dist/src/limits.d.ts +0 -64
- package/dist/src/limits.js +0 -62
- package/dist/src/managed-sign-in.d.ts +0 -12
- package/dist/src/managed-sign-in.js +0 -16
- package/dist/src/markdown.d.ts +0 -28
- package/dist/src/markdown.js +1 -175
- package/dist/src/mcp.d.ts +21 -82
- package/dist/src/mcp.js +228 -237
- package/dist/src/membership-errors.d.ts +0 -14
- package/dist/src/membership-errors.js +0 -13
- package/dist/src/membership.d.ts +2 -60
- package/dist/src/membership.js +0 -85
- package/dist/src/memory/LocalToolMemory.d.ts +0 -1
- package/dist/src/memory/LocalToolMemory.js +2 -7
- package/dist/src/memory/MemoryDistiller.js +0 -15
- package/dist/src/memory/MemoryManager.d.ts +0 -3
- package/dist/src/memory/MemoryManager.js +6 -18
- package/dist/src/memory/MemoryPolicy.d.ts +0 -2
- package/dist/src/memory/MemoryPolicy.js +0 -2
- package/dist/src/memory/MemoryProvider.d.ts +0 -6
- package/dist/src/memory/MemoryRetriever.js +0 -7
- package/dist/src/memory/PermissionMemoryProvider.d.ts +0 -1
- package/dist/src/memory/PermissionMemoryProvider.js +0 -1
- package/dist/src/memory/ProjectMemory.d.ts +42 -0
- package/dist/src/memory/ProjectMemory.js +285 -0
- package/dist/src/memory/ToolFailureLessons.d.ts +0 -3
- package/dist/src/memory/ToolFailureLessons.js +0 -6
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/memory/providers/NoOpMemoryProvider.d.ts +0 -1
- package/dist/src/memory/providers/NoOpMemoryProvider.js +0 -1
- package/dist/src/memory/redaction.d.ts +0 -5
- package/dist/src/memory/redaction.js +0 -11
- package/dist/src/memory/repository.d.ts +0 -6
- package/dist/src/memory/repository.js +2 -12
- package/dist/src/memory/types.d.ts +0 -1
- package/dist/src/model-health-cache.d.ts +0 -38
- package/dist/src/model-health-cache.js +1 -49
- package/dist/src/model-metadata.d.ts +0 -18
- package/dist/src/model-metadata.js +2 -42
- package/dist/src/model-override.d.ts +0 -36
- package/dist/src/model-override.js +0 -43
- package/dist/src/model-tiers.d.ts +0 -13
- package/dist/src/model-tiers.js +0 -23
- package/dist/src/opencode-catalog.d.ts +0 -2
- package/dist/src/opencode-catalog.js +0 -11
- package/dist/src/opencode-cli-provider.d.ts +0 -35
- package/dist/src/opencode-cli-provider.js +1 -44
- package/dist/src/opencode-provider.d.ts +0 -2
- package/dist/src/opencode-provider.js +6 -22
- package/dist/src/package-name.d.ts +1 -0
- package/dist/src/package-name.js +1 -0
- package/dist/src/paged-transcript.d.ts +0 -11
- package/dist/src/paged-transcript.js +2 -20
- package/dist/src/palette.d.ts +0 -63
- package/dist/src/palette.js +0 -63
- package/dist/src/permissions.d.ts +0 -15
- package/dist/src/permissions.js +0 -17
- package/dist/src/powershell-pool.d.ts +0 -9
- package/dist/src/powershell-pool.js +3 -26
- package/dist/src/process-warnings.d.ts +4 -0
- package/dist/src/process-warnings.js +103 -0
- package/dist/src/profile.d.ts +0 -43
- package/dist/src/profile.js +0 -43
- package/dist/src/project-reservation.d.ts +11 -0
- package/dist/src/project-reservation.js +143 -0
- package/dist/src/provider-connection.d.ts +0 -18
- package/dist/src/provider-connection.js +0 -39
- package/dist/src/provider-engine.d.ts +0 -21
- package/dist/src/provider-engine.js +3 -98
- package/dist/src/provider-import.d.ts +0 -49
- package/dist/src/provider-import.js +0 -60
- package/dist/src/provider-keys.d.ts +1 -36
- package/dist/src/provider-keys.js +5 -48
- package/dist/src/provider-settings.d.ts +0 -2
- package/dist/src/provider-settings.js +0 -32
- package/dist/src/providers.d.ts +0 -217
- package/dist/src/providers.js +0 -315
- package/dist/src/pull-requests.d.ts +0 -173
- package/dist/src/pull-requests.js +5 -195
- package/dist/src/qa/browser/PlaywrightRunner.d.ts +0 -7
- package/dist/src/qa/browser/PlaywrightRunner.js +2 -16
- package/dist/src/qa/command-policy.d.ts +0 -23
- package/dist/src/qa/command-policy.js +0 -30
- package/dist/src/qa/guidance.d.ts +0 -21
- package/dist/src/qa/guidance.js +0 -20
- package/dist/src/qa/profile/ProjectInspector.d.ts +0 -4
- package/dist/src/qa/profile/ProjectInspector.js +0 -6
- package/dist/src/qa/profile/QaConfigLoader.d.ts +0 -7
- package/dist/src/qa/profile/QaConfigLoader.js +0 -6
- package/dist/src/qa/profile/QaProfile.d.ts +0 -7
- package/dist/src/qa/profile/QaProfile.js +0 -7
- package/dist/src/qa/profile/yaml.d.ts +0 -9
- package/dist/src/qa/profile/yaml.js +0 -13
- package/dist/src/qa/qa-authorize.d.ts +0 -19
- package/dist/src/qa/qa-authorize.js +4 -11
- package/dist/src/qa/runtime/ProcessManager.d.ts +0 -31
- package/dist/src/qa/runtime/ProcessManager.js +4 -41
- package/dist/src/qa/runtime/PtyManager.d.ts +0 -4
- package/dist/src/qa/runtime/PtyManager.js +2 -7
- package/dist/src/qa/runtime/changes.d.ts +0 -11
- package/dist/src/qa/runtime/changes.js +1 -3
- package/dist/src/qa/tools.d.ts +0 -10
- package/dist/src/qa/tools.js +0 -12
- package/dist/src/qa/types.d.ts +0 -13
- package/dist/src/react-runtime.d.ts +2 -21
- package/dist/src/react-runtime.js +106 -418
- package/dist/src/read-document-doc.d.ts +0 -6
- package/dist/src/read-document-doc.js +0 -55
- package/dist/src/read-document-docx.d.ts +0 -16
- package/dist/src/read-document-docx.js +2 -69
- package/dist/src/read-document-text.d.ts +0 -17
- package/dist/src/read-document-text.js +0 -22
- package/dist/src/read-document-tool.d.ts +0 -31
- package/dist/src/read-document-tool.js +0 -30
- package/dist/src/read-document.d.ts +0 -49
- package/dist/src/read-document.js +1 -67
- package/dist/src/read-image.d.ts +0 -32
- package/dist/src/read-image.js +0 -33
- package/dist/src/remote/cert.d.ts +1 -19
- package/dist/src/remote/cert.js +2 -51
- package/dist/src/remote/client.d.ts +0 -70
- package/dist/src/remote/client.js +2 -117
- package/dist/src/remote/command.js +0 -17
- package/dist/src/remote/engine-pool.d.ts +0 -152
- package/dist/src/remote/engine-pool.js +17 -335
- package/dist/src/remote/errors.d.ts +0 -15
- package/dist/src/remote/errors.js +0 -7
- package/dist/src/remote/network.d.ts +0 -26
- package/dist/src/remote/network.js +1 -34
- package/dist/src/remote/pairing.d.ts +16 -51
- package/dist/src/remote/pairing.js +50 -57
- package/dist/src/remote/pem.d.ts +2 -0
- package/dist/src/remote/pem.js +7 -0
- package/dist/src/remote/roots.d.ts +0 -20
- package/dist/src/remote/roots.js +0 -8
- package/dist/src/remote/serve.d.ts +0 -47
- package/dist/src/remote/serve.js +0 -30
- package/dist/src/remote/server.d.ts +0 -14
- package/dist/src/remote/server.js +1 -79
- package/dist/src/remote/types.d.ts +1 -32
- package/dist/src/remote/types.js +0 -10
- package/dist/src/run-control.d.ts +0 -7
- package/dist/src/run-control.js +0 -7
- package/dist/src/run-progress.d.ts +0 -170
- package/dist/src/run-progress.js +0 -285
- package/dist/src/run-records.d.ts +0 -443
- package/dist/src/run-records.js +44 -678
- package/dist/src/run-temp.d.ts +12 -0
- package/dist/src/run-temp.js +50 -0
- package/dist/src/runtime.d.ts +11 -227
- package/dist/src/runtime.js +0 -127
- package/dist/src/sandbox-child.js +0 -1
- package/dist/src/save-lock.d.ts +0 -12
- package/dist/src/save-lock.js +0 -28
- package/dist/src/screen-selection.d.ts +0 -23
- package/dist/src/screen-selection.js +0 -22
- package/dist/src/secret-redaction.d.ts +0 -12
- package/dist/src/secret-redaction.js +0 -45
- package/dist/src/session-changes.d.ts +4 -80
- package/dist/src/session-changes.js +25 -130
- package/dist/src/session-goal.d.ts +129 -0
- package/dist/src/session-goal.js +230 -0
- package/dist/src/session-monitor.d.ts +1 -10
- package/dist/src/session-monitor.js +2 -39
- package/dist/src/session-reaper.d.ts +0 -15
- package/dist/src/session-reaper.js +0 -14
- package/dist/src/session-skills.d.ts +15 -44
- package/dist/src/session-skills.js +75 -60
- package/dist/src/session-summary.d.ts +0 -26
- package/dist/src/session-summary.js +0 -32
- package/dist/src/session-title.d.ts +0 -1
- package/dist/src/session-title.js +0 -2
- package/dist/src/sessions.d.ts +2 -120
- package/dist/src/sessions.js +9 -178
- package/dist/src/shell.d.ts +3 -20
- package/dist/src/shell.js +8 -72
- package/dist/src/side-panel.d.ts +5 -99
- package/dist/src/side-panel.js +76 -133
- package/dist/src/sign-in-detection.d.ts +43 -0
- package/dist/src/sign-in-detection.js +154 -0
- package/dist/src/sign-in-offer.d.ts +17 -0
- package/dist/src/sign-in-offer.js +103 -0
- package/dist/src/skill-commands.d.ts +0 -1
- package/dist/src/skill-commands.js +1 -4
- package/dist/src/skills/bundled/control-browser/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/invocable-skills.d.ts +0 -18
- package/dist/src/skills/invocable-skills.js +0 -17
- package/dist/src/skills/project-skills.d.ts +0 -1
- package/dist/src/skills/project-skills.js +0 -3
- package/dist/src/skills/prompt-skills.js +0 -14
- package/dist/src/skills/runtime-skills.d.ts +1 -8
- package/dist/src/skills/runtime-skills.js +8 -32
- package/dist/src/stall-recovery.d.ts +0 -25
- package/dist/src/stall-recovery.js +0 -38
- package/dist/src/stray-files.d.ts +5 -0
- package/dist/src/stray-files.js +65 -0
- package/dist/src/structured-step.d.ts +0 -22
- package/dist/src/structured-step.js +0 -22
- package/dist/src/subagent-run.d.ts +0 -163
- package/dist/src/subagent-run.js +10 -374
- package/dist/src/subagent-tree.d.ts +32 -0
- package/dist/src/subagent-tree.js +128 -0
- package/dist/src/telemetry/aggregate.d.ts +0 -37
- package/dist/src/telemetry/aggregate.js +0 -40
- package/dist/src/telemetry/capture-core.d.ts +0 -87
- package/dist/src/telemetry/capture-core.js +0 -67
- package/dist/src/telemetry/capture.d.ts +0 -1
- package/dist/src/telemetry/capture.js +0 -3
- package/dist/src/telemetry/classify.d.ts +0 -58
- package/dist/src/telemetry/classify.js +0 -60
- package/dist/src/telemetry/decision-capture.d.ts +0 -1
- package/dist/src/telemetry/emitter.d.ts +0 -30
- package/dist/src/telemetry/emitter.js +1 -62
- package/dist/src/telemetry/gate.d.ts +0 -29
- package/dist/src/telemetry/gate.js +0 -22
- package/dist/src/telemetry/identity.d.ts +0 -13
- package/dist/src/telemetry/identity.js +0 -29
- package/dist/src/telemetry/outbox.d.ts +0 -64
- package/dist/src/telemetry/outbox.js +1 -108
- package/dist/src/telemetry/schema.d.ts +1 -49
- package/dist/src/telemetry/schema.js +1 -82
- package/dist/src/telemetry/state.d.ts +0 -53
- package/dist/src/telemetry/state.js +0 -64
- package/dist/src/telemetry/surface.d.ts +0 -31
- package/dist/src/telemetry/surface.js +1 -39
- package/dist/src/telemetry/uploader.d.ts +0 -11
- package/dist/src/telemetry/uploader.js +0 -46
- package/dist/src/telemetry/uploads.d.ts +0 -11
- package/dist/src/telemetry/uploads.js +0 -11
- package/dist/src/telemetry/version.d.ts +0 -4
- package/dist/src/telemetry/version.js +0 -14
- package/dist/src/telemetry/workspace.d.ts +0 -7
- package/dist/src/telemetry/workspace.js +1 -22
- package/dist/src/terminal-ui.d.ts +15 -524
- package/dist/src/terminal-ui.js +80 -876
- package/dist/src/test-edit-guard.d.ts +74 -0
- package/dist/src/test-edit-guard.js +269 -0
- package/dist/src/text.d.ts +0 -1
- package/dist/src/text.js +0 -1
- package/dist/src/time-limit.d.ts +0 -36
- package/dist/src/time-limit.js +0 -37
- package/dist/src/timers.d.ts +0 -161
- package/dist/src/timers.js +0 -126
- package/dist/src/todos.d.ts +0 -1
- package/dist/src/todos.js +0 -3
- package/dist/src/token-rate.d.ts +0 -94
- package/dist/src/token-rate.js +0 -154
- package/dist/src/tool-activity.d.ts +0 -6
- package/dist/src/tool-activity.js +1 -8
- package/dist/src/tool-availability.d.ts +0 -13
- package/dist/src/tool-availability.js +1 -14
- package/dist/src/tool-call-clock.d.ts +1 -4
- package/dist/src/tool-call-clock.js +0 -13
- package/dist/src/tool-catalog.d.ts +0 -11
- package/dist/src/tool-catalog.js +0 -23
- package/dist/src/tool-dependencies.d.ts +0 -5
- package/dist/src/tool-dependencies.js +0 -4
- package/dist/src/tool-diff-stats.d.ts +0 -23
- package/dist/src/tool-diff-stats.js +0 -49
- package/dist/src/tool-errors.d.ts +9 -7
- package/dist/src/tool-errors.js +13 -6
- package/dist/src/tool-failure-tracker.d.ts +3 -11
- package/dist/src/tool-failure-tracker.js +19 -27
- package/dist/src/tool-names.d.ts +0 -16
- package/dist/src/tool-names.js +0 -12
- package/dist/src/tool-profile.d.ts +6 -0
- package/dist/src/tool-profile.js +23 -0
- package/dist/src/tool-result-filter.d.ts +0 -19
- package/dist/src/tool-result-filter.js +1 -66
- package/dist/src/tool-schema-compatibility.d.ts +1 -2
- package/dist/src/tool-schema-compatibility.js +2 -7
- package/dist/src/tools.d.ts +0 -4
- package/dist/src/tools.js +11 -114
- package/dist/src/trajectory.d.ts +0 -13
- package/dist/src/trajectory.js +23 -79
- package/dist/src/transcript.d.ts +1 -37
- package/dist/src/transcript.js +11 -61
- package/dist/src/types.d.ts +2 -167
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +105 -0
- package/dist/src/update-check.d.ts +0 -14
- package/dist/src/update-check.js +2 -16
- package/dist/src/update.d.ts +4 -29
- package/dist/src/update.js +20 -98
- package/dist/src/usage-analytics.d.ts +17 -17
- package/dist/src/usage-analytics.js +168 -209
- package/dist/src/web-search.d.ts +0 -23
- package/dist/src/web-search.js +1 -27
- package/dist/src/widgets.d.ts +0 -25
- package/dist/src/widgets.js +0 -24
- package/dist/src/workspace-facts.d.ts +0 -12
- package/dist/src/workspace-facts.js +1 -18
- package/dist/src/workspace-git-metadata.d.ts +4 -5
- package/dist/src/workspace-git-metadata.js +37 -9
- package/dist/src/workspace-instructions.d.ts +3 -15
- package/dist/src/workspace-instructions.js +7 -20
- package/package.json +2 -2
package/dist/src/browser-view.js
CHANGED
|
@@ -9,35 +9,15 @@ import { desktopUaOverride, hardenContext, stealthContextOptions, stealthLaunchA
|
|
|
9
9
|
export const VIEW_TAB_LIMIT = 6;
|
|
10
10
|
export const VIEW_SESSION_LIMIT = 4;
|
|
11
11
|
export const VIEW_IDLE_CLOSE_MS = 10 * 60 * 1000;
|
|
12
|
-
|
|
12
|
+
export const VIEW_HOLD_MAX_MS = 10 * 60 * 1000;
|
|
13
13
|
export const VIEW_FRAME_MIN_INTERVAL_MS = 16;
|
|
14
14
|
export const VIEW_GOTO_TIMEOUT_MS = 30_000;
|
|
15
|
-
/** The viewport Mobile mode simulates, in CSS pixels: an iPhone-class layout. */
|
|
16
15
|
export const VIEW_MOBILE_VIEWPORT = { width: 390, height: 844 };
|
|
17
|
-
/** The pixel density Mobile mode emulates: a current phone's. */
|
|
18
16
|
const VIEW_MOBILE_SCALE = 3;
|
|
19
|
-
/** The JPEG quality stream frames use; agent screenshots keep their own setting. */
|
|
20
17
|
export const VIEW_STREAM_QUALITY = 90;
|
|
21
|
-
/**
|
|
22
|
-
* The largest display pixel ratio a desktop-mode page renders at. A 4K laptop
|
|
23
|
-
* panel at 300% scaling is the densest display Windows ships with; past that
|
|
24
|
-
* the frames only cost bandwidth the pane cannot show.
|
|
25
|
-
*/
|
|
26
18
|
export const VIEW_MAX_SCALE = 3;
|
|
27
|
-
/**
|
|
28
|
-
* The largest frame the desktop accepts, in base64 characters (`parseFrameEvent`
|
|
29
|
-
* in desktop/src/engine/browserView.ts drops anything bigger). A dropped frame
|
|
30
|
-
* leaves the pane frozen, so a frame over this is never sent: the stream steps
|
|
31
|
-
* its quality and then its size down until the page's frames fit.
|
|
32
|
-
*/
|
|
33
19
|
export const VIEW_FRAME_LIMIT = 4 * 1024 * 1024;
|
|
34
|
-
/** The lowest JPEG quality the frame budget steps down to before it shrinks frames instead. */
|
|
35
20
|
const VIEW_BUDGET_QUALITY_FLOOR = 50;
|
|
36
|
-
/**
|
|
37
|
-
* The next, smaller frame budget after a frame came out over the limit: quality
|
|
38
|
-
* first, in steps of 20 down to 50, then the frame size in steps of a quarter,
|
|
39
|
-
* down to the page's CSS size. Undefined when there is nothing left to give up.
|
|
40
|
-
*/
|
|
41
21
|
export function nextFrameBudget(budget, scale) {
|
|
42
22
|
if (budget.quality > VIEW_BUDGET_QUALITY_FLOOR)
|
|
43
23
|
return { quality: Math.max(VIEW_BUDGET_QUALITY_FLOOR, budget.quality - 20), size: budget.size };
|
|
@@ -46,27 +26,10 @@ export function nextFrameBudget(budget, scale) {
|
|
|
46
26
|
return { quality: budget.quality, size: Math.max(floor, budget.size * 0.75) };
|
|
47
27
|
return undefined;
|
|
48
28
|
}
|
|
49
|
-
/** The largest viewport `clampViewport` allows, in CSS pixels. */
|
|
50
29
|
const VIEW_MAX_VIEWPORT = { width: 1600, height: 2200 };
|
|
51
|
-
/**
|
|
52
|
-
* The mobile Chrome UA Mobile mode presents. A Chromium engine claiming to be
|
|
53
|
-
* iOS Safari confuses sites that branch on it, so the UA names the platform the
|
|
54
|
-
* page actually renders with.
|
|
55
|
-
*/
|
|
56
30
|
export const VIEW_MOBILE_USER_AGENT = 'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Mobile Safari/537.36';
|
|
57
31
|
const VIEW_URL_LIMIT = 2048;
|
|
58
|
-
// A copy is answered as one JSON string over the same pipe as everything else,
|
|
59
|
-
// so the largest plausible selection is bounded rather than trusted.
|
|
60
32
|
const VIEW_CLIPBOARD_LIMIT = 1_000_000;
|
|
61
|
-
/**
|
|
62
|
-
* The top document's selection, and whether focus is inside a child frame.
|
|
63
|
-
*
|
|
64
|
-
* `document.activeElement` is the iframe element itself, never the field inside
|
|
65
|
-
* it, and the top document's own selection is empty while a frame holds focus —
|
|
66
|
-
* so a selection made in a frame is invisible here and the caller has to ask the
|
|
67
|
-
* frames. It is an expression rather than a function: this file compiles without
|
|
68
|
-
* the DOM library, and Playwright evaluates a string inside the page as-is.
|
|
69
|
-
*/
|
|
70
33
|
const SELECTION_STATE = `(() => {
|
|
71
34
|
const active = document.activeElement;
|
|
72
35
|
const inFrame = !!active && (active.tagName === 'IFRAME' || active.tagName === 'FRAME');
|
|
@@ -80,13 +43,6 @@ const SELECTION_STATE = `(() => {
|
|
|
80
43
|
}
|
|
81
44
|
return { inFrame: false, focused, text: window.getSelection ? String(window.getSelection() || '') : '' };
|
|
82
45
|
})()`;
|
|
83
|
-
/**
|
|
84
|
-
* The cursor style in effect at a point in the page.
|
|
85
|
-
*
|
|
86
|
-
* The pane shows a streamed image, so the page's pointer never appears on its
|
|
87
|
-
* own: the panel asks for the style under the pointer and draws that shape
|
|
88
|
-
* itself. Same-origin frames are entered by mapping the point into each one.
|
|
89
|
-
*/
|
|
90
46
|
const CURSOR_AT = `((point) => {
|
|
91
47
|
let doc = document;
|
|
92
48
|
let x = point.x;
|
|
@@ -110,9 +66,13 @@ const CURSOR_AT = `((point) => {
|
|
|
110
66
|
}
|
|
111
67
|
return 'default';
|
|
112
68
|
})`;
|
|
113
|
-
|
|
69
|
+
export function browserViewUrl(value) {
|
|
114
70
|
const url = new URL(value);
|
|
115
|
-
if (
|
|
71
|
+
if (url.protocol === 'chrome-extension:') {
|
|
72
|
+
if (!/^[a-p]{32}$/.test(url.hostname) || url.username || url.password)
|
|
73
|
+
throw new Error('Use a chrome-extension://<32-letter id>/ page');
|
|
74
|
+
}
|
|
75
|
+
else if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
|
|
116
76
|
throw new Error('Use an HTTP(S) URL without embedded credentials');
|
|
117
77
|
if (url.href.length > VIEW_URL_LIMIT)
|
|
118
78
|
throw new Error('URL exceeds the 2048-character limit');
|
|
@@ -122,25 +82,11 @@ export function clampViewport(width, height) {
|
|
|
122
82
|
const value = (input, min, max, fallback) => Number.isSafeInteger(input) ? Math.max(min, Math.min(max, input)) : fallback;
|
|
123
83
|
return { width: value(width, 280, VIEW_MAX_VIEWPORT.width, 900), height: value(height, 240, VIEW_MAX_VIEWPORT.height, 700) };
|
|
124
84
|
}
|
|
125
|
-
/**
|
|
126
|
-
* The pane's display pixel ratio, which sizes its frames (and the factor a
|
|
127
|
-
* browser launched for it runs at), so one frame pixel is one screen pixel and
|
|
128
|
-
* the pane never stretches a frame rendered at CSS size. Anything that is not a finite number is the plain 1×
|
|
129
|
-
* an old panel (which sends none) has always had; the value is rounded to
|
|
130
|
-
* hundredths so a ratio like 1.2500000001 does not count as a change.
|
|
131
|
-
*/
|
|
132
85
|
export function clampScale(value) {
|
|
133
86
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
134
87
|
return 1;
|
|
135
88
|
return Math.round(Math.max(1, Math.min(VIEW_MAX_SCALE, value)) * 100) / 100;
|
|
136
89
|
}
|
|
137
|
-
/**
|
|
138
|
-
* JPEG dimensions straight from the SOF markers, without decoding pixels.
|
|
139
|
-
*
|
|
140
|
-
* Screencast frames carry no size fields; the panel sends input in image pixels
|
|
141
|
-
* and the engine must translate to page CSS pixels, so the real image size is
|
|
142
|
-
* load-bearing, not decorative.
|
|
143
|
-
*/
|
|
144
90
|
export function jpegSize(bytes) {
|
|
145
91
|
if (bytes.length < 4 || bytes[0] !== 0xff || bytes[1] !== 0xd8)
|
|
146
92
|
return undefined;
|
|
@@ -151,13 +97,11 @@ export function jpegSize(bytes) {
|
|
|
151
97
|
continue;
|
|
152
98
|
}
|
|
153
99
|
const marker = bytes[offset + 1];
|
|
154
|
-
// Fill bytes before a marker, and the stand-alone markers that carry no length.
|
|
155
100
|
if (marker === 0xff || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd9)) {
|
|
156
101
|
offset += 2;
|
|
157
102
|
continue;
|
|
158
103
|
}
|
|
159
104
|
const length = (bytes[offset + 2] << 8) | bytes[offset + 3];
|
|
160
|
-
// Baseline and progressive DCT carry the frame size; every other segment is skipped whole.
|
|
161
105
|
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
162
106
|
if (length < 7 || offset + 9 > bytes.length)
|
|
163
107
|
return undefined;
|
|
@@ -169,7 +113,6 @@ export function jpegSize(bytes) {
|
|
|
169
113
|
}
|
|
170
114
|
return undefined;
|
|
171
115
|
}
|
|
172
|
-
/** Windows virtual-key codes for the named keys a panel keypress can produce. */
|
|
173
116
|
const KEY_CODE = {
|
|
174
117
|
Enter: 13, Backspace: 8, Tab: 9, Escape: 27, Delete: 46, Insert: 45,
|
|
175
118
|
ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40, Home: 36, End: 35, PageUp: 33, PageDown: 34,
|
|
@@ -180,19 +123,6 @@ const CODE_KEY = {
|
|
|
180
123
|
Backslash: 220, Minus: 189, Equal: 187, Backquote: 192, NumpadEnter: 13, NumpadAdd: 107, NumpadSubtract: 109,
|
|
181
124
|
NumpadMultiply: 106, NumpadDivide: 111, NumpadDecimal: 110,
|
|
182
125
|
};
|
|
183
|
-
/**
|
|
184
|
-
* One panel key event as the CDP input domain needs it.
|
|
185
|
-
*
|
|
186
|
-
* A key is always a keyboard event, with the character a key-down inserts in
|
|
187
|
-
* `text`: an ordinary letter is inserted that way, and Enter carries Chromium's
|
|
188
|
-
* carriage return so a textarea or a content-editable field gets its newline.
|
|
189
|
-
* Keeping the gesture as a key event is what lets the page run its own keydown
|
|
190
|
-
* handling — Space activating a focused button, a page's printable-key shortcut —
|
|
191
|
-
* which text insertion alone would never trigger. A Ctrl, Alt or Meta held over a
|
|
192
|
-
* key drops the text (Ctrl+C must be a key event, never the character "c"), with
|
|
193
|
-
* one exception: AltGr is reported as Ctrl+Alt, and the character it produced —
|
|
194
|
-
* "@" on a German layout, "€" on many others — must survive.
|
|
195
|
-
*/
|
|
196
126
|
export function keyDescriptor(key, code, modifiers = 0) {
|
|
197
127
|
const named = KEY_CODE[key]
|
|
198
128
|
?? (code?.startsWith('Key') && code.length === 4 ? code.charCodeAt(3) : undefined)
|
|
@@ -203,13 +133,7 @@ export function keyDescriptor(key, code, modifiers = 0) {
|
|
|
203
133
|
throw new Error(`Unsupported key: ${key}`);
|
|
204
134
|
const ctrl = (modifiers & MODIFIER_BITS.ctrl) !== 0;
|
|
205
135
|
const alt = (modifiers & MODIFIER_BITS.alt) !== 0;
|
|
206
|
-
// An Option gesture on macOS that produces a character changes the key itself to
|
|
207
|
-
// that character (Option+2 is '™' on a US layout), while an Alt shortcut leaves
|
|
208
|
-
// the letter or digit it names untouched: a non-ASCII single character with Alt
|
|
209
|
-
// held is text to insert, not a shortcut, or the page would see the key and
|
|
210
|
-
// insert nothing.
|
|
211
136
|
const altCharacter = alt && !ctrl && printable && (key.codePointAt(0) ?? 0) > 0x7f;
|
|
212
|
-
// AltGr arrives as Ctrl+Alt together; a shortcut has exactly one of them (or Meta).
|
|
213
137
|
const shortcut = !altCharacter && ((modifiers & MODIFIER_BITS.meta) !== 0 || (ctrl !== alt && (ctrl || alt)));
|
|
214
138
|
const keyCode = named ?? key.toUpperCase().charCodeAt(0);
|
|
215
139
|
const text = shortcut ? undefined : printable ? key : key === 'Enter' ? '\r' : undefined;
|
|
@@ -229,16 +153,6 @@ export function modifierMask(modifiers) {
|
|
|
229
153
|
throw new Error('modifiers must be a list of alt, ctrl, meta, shift');
|
|
230
154
|
return modifiers.reduce((mask, name) => mask | MODIFIER_BITS[name], 0);
|
|
231
155
|
}
|
|
232
|
-
/**
|
|
233
|
-
* The native editing commands a macOS page performs for a key-down.
|
|
234
|
-
*
|
|
235
|
-
* On macOS, gestures like Cmd+A, Cmd+Z, or Option+Arrow are not synthesized from
|
|
236
|
-
* key events: Chromium runs the named command instead, and nothing happens when
|
|
237
|
-
* none is sent — the panel suppresses the local default, so the page would be
|
|
238
|
-
* left without either. These are the mappings Playwright itself derives for the
|
|
239
|
-
* same CDP call (its macEditingCommands table), limited to the gestures a pane
|
|
240
|
-
* can forward.
|
|
241
|
-
*/
|
|
242
156
|
export function macEditingCommands(key, modifiers) {
|
|
243
157
|
const meta = (modifiers & MODIFIER_BITS.meta) !== 0;
|
|
244
158
|
const alt = (modifiers & MODIFIER_BITS.alt) !== 0;
|
|
@@ -267,36 +181,22 @@ export function macEditingCommands(key, modifiers) {
|
|
|
267
181
|
}
|
|
268
182
|
return [];
|
|
269
183
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
* (`--mute-audio`), which silences every page the user browses in the panel; the
|
|
273
|
-
* screencast carries pixels only, so the page's own audio output on the engine's
|
|
274
|
-
* machine is the only sound the panel has.
|
|
275
|
-
*/
|
|
276
|
-
export function viewLaunchOptions(channel, executablePath, scale = 1) {
|
|
184
|
+
export function viewLaunchOptions(channel, executablePath, scale = 1, extensionPaths = []) {
|
|
185
|
+
const extensions = channel === 'chromium' ? extensionPaths : [];
|
|
277
186
|
return {
|
|
278
187
|
headless: true,
|
|
279
188
|
...(channel === 'chromium' ? { executablePath } : { channel }),
|
|
280
|
-
ignoreDefaultArgs: ['--mute-audio'],
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// 800×600 frames with devicePixelRatio 2). The real factor is what puts
|
|
286
|
-
// screen-resolution pixels into the frames.
|
|
287
|
-
args: [...stealthLaunchArgs(), ...(scale !== 1 ? [`--force-device-scale-factor=${scale}`] : [])],
|
|
189
|
+
ignoreDefaultArgs: ['--mute-audio', ...(extensions.length ? ['--disable-extensions'] : [])],
|
|
190
|
+
args: [
|
|
191
|
+
...stealthLaunchArgs(), ...(scale !== 1 ? [`--force-device-scale-factor=${scale}`] : []),
|
|
192
|
+
...(extensions.length ? [`--disable-extensions-except=${extensions.join(',')}`, `--load-extension=${extensions.join(',')}`] : []),
|
|
193
|
+
],
|
|
288
194
|
timeout: 20_000,
|
|
289
195
|
};
|
|
290
196
|
}
|
|
291
|
-
/** Whether a frame arriving at `now` may be emitted, given the last emitted frame time. */
|
|
292
197
|
export function frameGate(now, lastEmittedAt, minIntervalMs) {
|
|
293
198
|
return lastEmittedAt === undefined || now - lastEmittedAt >= minIntervalMs;
|
|
294
199
|
}
|
|
295
|
-
/**
|
|
296
|
-
* The file whose existence proves a channel is installed. The bundled Chromium's
|
|
297
|
-
* path comes from playwright-core itself; system channels have per-platform
|
|
298
|
-
* locations. The probe reads the filesystem and never launches anything.
|
|
299
|
-
*/
|
|
300
200
|
export function channelCandidate(channel, platform, chromiumExecutable) {
|
|
301
201
|
if (channel === 'chromium') {
|
|
302
202
|
try {
|
|
@@ -319,58 +219,33 @@ export function channelCandidate(channel, platform, chromiumExecutable) {
|
|
|
319
219
|
? ['/usr/bin/microsoft-edge', '/usr/bin/microsoft-edge-stable'].find(existsSync)
|
|
320
220
|
: ['/usr/bin/google-chrome', '/usr/bin/google-chrome-stable'].find(existsSync);
|
|
321
221
|
}
|
|
322
|
-
|
|
222
|
+
const EXTENSION_RESTART_POLL_MS = 5_000;
|
|
223
|
+
const EXTENSION_PROBE_TIMEOUT_MS = 4_000;
|
|
323
224
|
const PROFILE_CLOSE_TIMEOUT_MS = 5_000;
|
|
324
|
-
|
|
325
|
-
* One engine's panel browsers: a browser per session, a page per tab, and a CDP
|
|
326
|
-
* screencast relay per active tab. Everything is keyed by the saved session id —
|
|
327
|
-
* exactly the identity the desktop's browser pane already owns.
|
|
328
|
-
*/
|
|
225
|
+
const EXTENSION_PAGE_CLAIM_MS = 300;
|
|
329
226
|
export class BrowserViewManager {
|
|
330
227
|
emit;
|
|
331
228
|
launchBrowser;
|
|
332
229
|
options;
|
|
333
230
|
sessions = new Map();
|
|
334
|
-
/**
|
|
335
|
-
* The pane's standing stream request per session, kept before a browser exists.
|
|
336
|
-
*
|
|
337
|
-
* A panel mounts and asks for frames before its first tab is opened, so the
|
|
338
|
-
* request has to outlive the absence of a session: the open that follows
|
|
339
|
-
* adopts this along with its viewport, and a later re-open after an idle reap
|
|
340
|
-
* resumes streaming without another round trip.
|
|
341
|
-
*/
|
|
342
231
|
desired = new Map();
|
|
343
|
-
/**
|
|
344
|
-
* The display ratio a pane most recently reported, for any session. A browser
|
|
345
|
-
* an agent opens while its pane is collapsed has no request of its own to read
|
|
346
|
-
* a ratio from; the machine's display is the best answer there is.
|
|
347
|
-
*/
|
|
348
232
|
displayScale = 1;
|
|
349
|
-
/** Launches in flight per session, so concurrent opens share one browser. */
|
|
350
233
|
launching = new Map();
|
|
351
234
|
runtime = { state: 'checking' };
|
|
352
235
|
runtimeProbe;
|
|
353
236
|
installTask;
|
|
354
|
-
/**
|
|
355
|
-
* The running installer, held here rather than in the closure that started it:
|
|
356
|
-
* shutdown has to terminate the download and settle the request waiting on it,
|
|
357
|
-
* or the child outlives the engine that is being closed.
|
|
358
|
-
*/
|
|
359
237
|
installer;
|
|
360
|
-
/**
|
|
361
|
-
* Sessions released while their first launch was still in flight. The launch
|
|
362
|
-
* that arrives afterwards closes its browser instead of registering one the
|
|
363
|
-
* deleted session can never reach, or else it would hold a slot for good.
|
|
364
|
-
*/
|
|
365
238
|
released = new Set();
|
|
366
|
-
/** Project profiles open now, by profile key. */
|
|
367
239
|
profiles = new Map();
|
|
368
|
-
/**
|
|
369
|
-
* Sessions whose panel browser is (or is about to be) incognito. The mark
|
|
370
|
-
* lives exactly as long as that browser: it is cleared when the browser
|
|
371
|
-
* closes, so the next open returns to the project profile.
|
|
372
|
-
*/
|
|
373
240
|
incognito = new Set();
|
|
241
|
+
holds = new Map();
|
|
242
|
+
pendingRestart = new Set();
|
|
243
|
+
claimedPages = new WeakSet();
|
|
244
|
+
restartsInFlight = new Set();
|
|
245
|
+
/** The restart under way for each profile, through its tab restoration: one at a time per profile. */
|
|
246
|
+
restartingProfiles = new Map();
|
|
247
|
+
restoring = new Map();
|
|
248
|
+
restartPoll;
|
|
374
249
|
closed = false;
|
|
375
250
|
constructor(emit, launchBrowser, options = {}) {
|
|
376
251
|
this.emit = emit;
|
|
@@ -381,10 +256,6 @@ export class BrowserViewManager {
|
|
|
381
256
|
this.runtime = status;
|
|
382
257
|
this.emit('browser.runtime', { ...status });
|
|
383
258
|
}
|
|
384
|
-
/**
|
|
385
|
-
* Probe the same executables `launch` will use, without launching anything;
|
|
386
|
-
* the answer is cached.
|
|
387
|
-
*/
|
|
388
259
|
runtimeStatus(force = false) {
|
|
389
260
|
if (!force && this.runtime.state !== 'checking')
|
|
390
261
|
return Promise.resolve(this.runtime);
|
|
@@ -412,16 +283,9 @@ export class BrowserViewManager {
|
|
|
412
283
|
})().finally(() => { this.runtimeProbe = undefined; });
|
|
413
284
|
return this.runtimeProbe;
|
|
414
285
|
}
|
|
415
|
-
/**
|
|
416
|
-
* Download the bundled Chromium through playwright-core's own installer.
|
|
417
|
-
*
|
|
418
|
-
* A machine with Edge or Chrome installed never reaches this: the probe is
|
|
419
|
-
* satisfied by the system browser and the download is skipped.
|
|
420
|
-
*/
|
|
421
286
|
install() {
|
|
422
287
|
if (this.installTask)
|
|
423
288
|
return this.installTask;
|
|
424
|
-
// Nothing to install into a manager that is already gone.
|
|
425
289
|
if (this.closed)
|
|
426
290
|
return Promise.resolve({ state: 'failed', detail: 'Application is shutting down' });
|
|
427
291
|
const run = async () => new Promise(resolve => {
|
|
@@ -436,8 +300,6 @@ export class BrowserViewManager {
|
|
|
436
300
|
this.installer = undefined;
|
|
437
301
|
resolve(value);
|
|
438
302
|
};
|
|
439
|
-
// A stalled download must not wedge the runtime in 'installing' forever:
|
|
440
|
-
// the installer is stopped and the state reported as failed.
|
|
441
303
|
const timer = setTimeout(() => {
|
|
442
304
|
child?.kill();
|
|
443
305
|
const failed = { state: 'failed', detail: detail || 'Browser runtime install timed out' };
|
|
@@ -486,16 +348,10 @@ export class BrowserViewManager {
|
|
|
486
348
|
return this.installTask;
|
|
487
349
|
}
|
|
488
350
|
async launch(scale) {
|
|
489
|
-
// Tests supply a fake browser; production launches the real one below.
|
|
490
351
|
if (this.launchBrowser)
|
|
491
352
|
return await this.launchBrowser(scale);
|
|
492
353
|
const { chromium } = await import('playwright-core');
|
|
493
354
|
const failures = [];
|
|
494
|
-
// The probe's candidates in the probe's order. The bundled Chromium is launched
|
|
495
|
-
// by the very executable the probe checked: a default headless launch selects
|
|
496
|
-
// Playwright's separate headless shell, which an install made with `--no-shell`
|
|
497
|
-
// does not have, so probing the full binary and launching the shell would report
|
|
498
|
-
// a ready runtime for a browser that cannot start.
|
|
499
355
|
for (const channel of ['chromium', 'msedge', 'chrome']) {
|
|
500
356
|
if (this.closed)
|
|
501
357
|
throw new Error('Application is shutting down');
|
|
@@ -511,10 +367,21 @@ export class BrowserViewManager {
|
|
|
511
367
|
}
|
|
512
368
|
throw new Error(`Browser runtime is not usable: ${failures.join('; ').slice(0, 1000)}`);
|
|
513
369
|
}
|
|
514
|
-
/** Launch Chromium on a project's profile folder, with the same candidates as `launch`. */
|
|
515
370
|
async launchPersistent(directory, viewport, scale) {
|
|
516
|
-
|
|
517
|
-
|
|
371
|
+
const set = this.options.extensions
|
|
372
|
+
? await this.options.extensions.launchSet().catch(() => ({ load: [], problems: {} }))
|
|
373
|
+
: { load: [], problems: {} };
|
|
374
|
+
const status = {};
|
|
375
|
+
for (const [id, detail] of Object.entries(set.problems))
|
|
376
|
+
status[id] = { state: 'failed', detail };
|
|
377
|
+
if (this.options.launchProfile) {
|
|
378
|
+
const context = await this.options.launchProfile(directory, viewport, scale, set);
|
|
379
|
+
if (set.load.length)
|
|
380
|
+
await this.reportLoaded(context, set, status);
|
|
381
|
+
else if (Object.keys(status).length)
|
|
382
|
+
this.options.extensions?.report(status);
|
|
383
|
+
return context;
|
|
384
|
+
}
|
|
518
385
|
await mkdir(directory, { recursive: true });
|
|
519
386
|
const { chromium } = await import('playwright-core');
|
|
520
387
|
const failures = [];
|
|
@@ -524,10 +391,34 @@ export class BrowserViewManager {
|
|
|
524
391
|
const candidate = channelCandidate(channel, process.platform, () => chromium.executablePath());
|
|
525
392
|
if (!candidate || !existsSync(candidate))
|
|
526
393
|
continue;
|
|
527
|
-
|
|
528
|
-
const context = await chromium.launchPersistentContext(directory, { ...viewLaunchOptions(channel, candidate, scale), ...stealthContextOptions(), viewport: { ...viewport }, acceptDownloads: false });
|
|
394
|
+
const open = async (paths) => {
|
|
395
|
+
const context = await chromium.launchPersistentContext(directory, { ...viewLaunchOptions(channel, candidate, scale, paths), ...stealthContextOptions(), viewport: { ...viewport }, acceptDownloads: false });
|
|
529
396
|
await hardenContext(context);
|
|
530
397
|
return context;
|
|
398
|
+
};
|
|
399
|
+
try {
|
|
400
|
+
if (channel !== 'chromium' || set.load.length === 0) {
|
|
401
|
+
const context = await open([]);
|
|
402
|
+
for (const item of set.load)
|
|
403
|
+
status[item.id] = { state: 'not-loaded', detail: 'The panel is running on Edge or Chrome, which cannot load extensions this way; install the browser runtime to use them' };
|
|
404
|
+
if (Object.keys(status).length)
|
|
405
|
+
this.options.extensions?.report(status);
|
|
406
|
+
return context;
|
|
407
|
+
}
|
|
408
|
+
let context;
|
|
409
|
+
try {
|
|
410
|
+
context = await open(set.load.map(item => item.path));
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
const detail = `The browser would not start with extensions: ${(error instanceof Error ? error.message : String(error)).split('\n')[0].slice(0, 300)}`;
|
|
414
|
+
context = await open([]);
|
|
415
|
+
for (const item of set.load)
|
|
416
|
+
status[item.id] = { state: 'failed', detail };
|
|
417
|
+
this.options.extensions?.report(status);
|
|
418
|
+
return context;
|
|
419
|
+
}
|
|
420
|
+
await this.reportLoaded(context, set, status);
|
|
421
|
+
return context;
|
|
531
422
|
}
|
|
532
423
|
catch (error) {
|
|
533
424
|
failures.push((error instanceof Error ? error.message : String(error)).split('\n')[0]);
|
|
@@ -535,12 +426,191 @@ export class BrowserViewManager {
|
|
|
535
426
|
}
|
|
536
427
|
throw new Error(`Project browser profile is not usable: ${failures.join('; ').slice(0, 1000)}`);
|
|
537
428
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
429
|
+
async reportLoaded(context, set, status) {
|
|
430
|
+
let page;
|
|
431
|
+
try {
|
|
432
|
+
page = await context.newPage();
|
|
433
|
+
for (const item of set.load) {
|
|
434
|
+
try {
|
|
435
|
+
await page.goto(`chrome-extension://${item.id}/manifest.json`, { timeout: EXTENSION_PROBE_TIMEOUT_MS });
|
|
436
|
+
status[item.id] = { state: 'loaded' };
|
|
437
|
+
}
|
|
438
|
+
catch {
|
|
439
|
+
status[item.id] = { state: 'failed', detail: 'Chromium did not load it: check the folder for manifest errors or missing files' };
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
catch { }
|
|
444
|
+
finally {
|
|
445
|
+
await Promise.resolve().then(() => page?.close()).catch(() => { });
|
|
446
|
+
}
|
|
447
|
+
this.options.extensions?.report(status);
|
|
448
|
+
}
|
|
449
|
+
async restartForExtensions(force = false) {
|
|
450
|
+
if (this.closed)
|
|
451
|
+
return { restarted: 0, pending: [] };
|
|
452
|
+
for (const key of this.profiles.keys())
|
|
453
|
+
this.pendingRestart.add(key);
|
|
454
|
+
return await this.retryPendingRestarts(force);
|
|
455
|
+
}
|
|
456
|
+
async restartWithSession(sessionId, everyProfile) {
|
|
457
|
+
if (this.closed)
|
|
458
|
+
return { open: false, restarted: false, waitingOn: [] };
|
|
459
|
+
const key = this.sessions.get(sessionId)?.profileKey;
|
|
460
|
+
if (key !== undefined)
|
|
461
|
+
while (this.restartingProfiles.has(key))
|
|
462
|
+
await this.restartingProfiles.get(key).catch(() => { });
|
|
463
|
+
if (everyProfile)
|
|
464
|
+
for (const profile of this.profiles.keys())
|
|
465
|
+
this.pendingRestart.add(profile);
|
|
466
|
+
if (key !== undefined && this.sessions.get(sessionId)?.profileKey === key)
|
|
467
|
+
this.pendingRestart.add(key);
|
|
468
|
+
await this.retryPendingRestarts(false, sessionId);
|
|
469
|
+
if (key === undefined || this.sessions.get(sessionId)?.profileKey !== key)
|
|
470
|
+
return { open: false, restarted: false, waitingOn: [] };
|
|
471
|
+
if (!this.pendingRestart.has(key))
|
|
472
|
+
return { open: true, restarted: true, waitingOn: [] };
|
|
473
|
+
const now = Date.now();
|
|
474
|
+
const waitingOn = [...this.sessions].filter(([id, session]) => id !== sessionId && session.profileKey === key && (this.holds.get(id) ?? 0) > now).map(([id]) => id);
|
|
475
|
+
return { open: true, restarted: false, waitingOn };
|
|
476
|
+
}
|
|
477
|
+
async retryPendingRestarts(force = false, ownHold) {
|
|
478
|
+
if (this.closed)
|
|
479
|
+
return { restarted: 0, pending: [] };
|
|
480
|
+
const now = Date.now();
|
|
481
|
+
let restarted = 0;
|
|
482
|
+
const work = [];
|
|
483
|
+
for (const key of [...this.pendingRestart]) {
|
|
484
|
+
const members = [...this.sessions].filter(([, session]) => session.profileKey === key);
|
|
485
|
+
const host = this.profiles.get(key);
|
|
486
|
+
if (!host && members.length === 0) {
|
|
487
|
+
this.pendingRestart.delete(key);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
if (host && (!host.context || members.length === 0))
|
|
491
|
+
continue;
|
|
492
|
+
// A restart still restoring this profile's tabs finishes first; the change stays queued and runs
|
|
493
|
+
// once it is done, with a snapshot of every restored tab rather than a half-restored one.
|
|
494
|
+
if (this.restartingProfiles.has(key))
|
|
495
|
+
continue;
|
|
496
|
+
const held = members.some(([id]) => id !== ownHold && (this.holds.get(id) ?? 0) > now);
|
|
497
|
+
if (held && !force)
|
|
498
|
+
continue;
|
|
499
|
+
this.pendingRestart.delete(key);
|
|
500
|
+
restarted += 1;
|
|
501
|
+
const running = this.restartProfile(key, members.map(([id]) => id));
|
|
502
|
+
this.restartsInFlight.add(running);
|
|
503
|
+
this.restartingProfiles.set(key, running);
|
|
504
|
+
work.push(running.finally(() => {
|
|
505
|
+
this.restartsInFlight.delete(running);
|
|
506
|
+
if (this.restartingProfiles.get(key) === running)
|
|
507
|
+
this.restartingProfiles.delete(key);
|
|
508
|
+
if (this.pendingRestart.has(key) && !this.closed)
|
|
509
|
+
void this.retryPendingRestarts(force).catch(() => { });
|
|
510
|
+
}));
|
|
511
|
+
}
|
|
512
|
+
await Promise.all(work);
|
|
513
|
+
this.armRestartPoll();
|
|
514
|
+
if (this.pendingRestart.size === 0 && this.restartsInFlight.size === 0)
|
|
515
|
+
this.options.extensions?.settled?.();
|
|
516
|
+
const pending = this.pendingRestartSessions();
|
|
517
|
+
this.emit('browser.extensions', { kind: 'restart', pending });
|
|
518
|
+
return { restarted, pending };
|
|
519
|
+
}
|
|
520
|
+
pendingRestartSessions() {
|
|
521
|
+
return [...this.sessions].filter(([, session]) => session.profileKey !== undefined && this.pendingRestart.has(session.profileKey)).map(([id]) => id);
|
|
522
|
+
}
|
|
523
|
+
armRestartPoll() {
|
|
524
|
+
if (this.restartPoll || this.pendingRestart.size === 0 || this.closed)
|
|
525
|
+
return;
|
|
526
|
+
this.restartPoll = setTimeout(() => {
|
|
527
|
+
this.restartPoll = undefined;
|
|
528
|
+
if (this.pendingRestart.size)
|
|
529
|
+
void this.retryPendingRestarts(false).catch(() => { });
|
|
530
|
+
}, EXTENSION_RESTART_POLL_MS);
|
|
531
|
+
this.restartPoll.unref?.();
|
|
532
|
+
}
|
|
533
|
+
async restartProfile(key, sessionIds) {
|
|
534
|
+
const snapshots = sessionIds.flatMap(sessionId => {
|
|
535
|
+
const session = this.sessions.get(sessionId);
|
|
536
|
+
if (!session)
|
|
537
|
+
return [];
|
|
538
|
+
const tabs = [...session.tabs.values()];
|
|
539
|
+
const urls = tabs.map(tab => tab.url);
|
|
540
|
+
return [{ sessionId, urls, active: tabs.findIndex(tab => tab.id === session.activeTabId) }];
|
|
541
|
+
});
|
|
542
|
+
const tokens = new Map(snapshots.map(snapshot => [snapshot.sessionId, { cancelled: false, abandoned: false }]));
|
|
543
|
+
for (const [sessionId, token] of tokens)
|
|
544
|
+
this.restoring.set(sessionId, token);
|
|
545
|
+
const host = this.profiles.get(key);
|
|
546
|
+
let finishRestart;
|
|
547
|
+
if (host)
|
|
548
|
+
host.restarting = new Promise(resolve => { finishRestart = resolve; });
|
|
549
|
+
try {
|
|
550
|
+
try {
|
|
551
|
+
await Promise.all(sessionIds.map(sessionId => this.closeSession(sessionId, 'extensions')));
|
|
552
|
+
await host?.closing;
|
|
553
|
+
}
|
|
554
|
+
finally {
|
|
555
|
+
if (host) {
|
|
556
|
+
host.restarting = undefined;
|
|
557
|
+
finishRestart();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
for (const snapshot of snapshots) {
|
|
561
|
+
const token = tokens.get(snapshot.sessionId);
|
|
562
|
+
const opened = [];
|
|
563
|
+
for (const url of snapshot.urls) {
|
|
564
|
+
if (token.cancelled || token.abandoned || this.closed)
|
|
565
|
+
break;
|
|
566
|
+
// The session may have moved to another browser meanwhile (incognito): its tabs are not
|
|
567
|
+
// this profile's to fill, and the switch's own blank tab stays the one shown.
|
|
568
|
+
const current = this.sessions.get(snapshot.sessionId);
|
|
569
|
+
if (this.incognito.has(snapshot.sessionId) || (current && current.profileKey !== key)) {
|
|
570
|
+
token.abandoned = true;
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
let target;
|
|
574
|
+
try {
|
|
575
|
+
target = browserViewUrl(url);
|
|
576
|
+
}
|
|
577
|
+
catch {
|
|
578
|
+
target = undefined;
|
|
579
|
+
}
|
|
580
|
+
if (!target) {
|
|
581
|
+
opened.push(undefined);
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
opened.push((await this.openPage(snapshot.sessionId, target)).tabId);
|
|
586
|
+
}
|
|
587
|
+
catch {
|
|
588
|
+
opened.push(undefined);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (token.cancelled) {
|
|
592
|
+
await this.closeSession(snapshot.sessionId, 'released');
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
if (token.abandoned)
|
|
596
|
+
continue;
|
|
597
|
+
const active = snapshot.active >= 0 ? opened[snapshot.active] : undefined;
|
|
598
|
+
if (active)
|
|
599
|
+
await this.activateTab(snapshot.sessionId, active).catch(() => { });
|
|
600
|
+
// The saved tabs are back; extension pages the relaunch opened take what room is left.
|
|
601
|
+
if (this.restoring.get(snapshot.sessionId) === token)
|
|
602
|
+
this.restoring.delete(snapshot.sessionId);
|
|
603
|
+
const restored = this.sessions.get(snapshot.sessionId);
|
|
604
|
+
if (restored)
|
|
605
|
+
this.claimUnclaimed(snapshot.sessionId, restored);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
finally {
|
|
609
|
+
for (const [sessionId, token] of tokens)
|
|
610
|
+
if (this.restoring.get(sessionId) === token)
|
|
611
|
+
this.restoring.delete(sessionId);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
544
614
|
async acquireProfile(owner, profile, viewport, scale) {
|
|
545
615
|
for (;;) {
|
|
546
616
|
const current = this.profiles.get(profile.key);
|
|
@@ -548,19 +618,25 @@ export class BrowserViewManager {
|
|
|
548
618
|
await current.closing;
|
|
549
619
|
continue;
|
|
550
620
|
}
|
|
621
|
+
if (current?.restarting) {
|
|
622
|
+
await current.restarting;
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
551
625
|
const host = current ?? { users: new Set() };
|
|
552
626
|
if (!current)
|
|
553
627
|
this.profiles.set(profile.key, host);
|
|
554
628
|
host.users.add(owner);
|
|
555
|
-
// A profile already running keeps the factor it was launched with: one
|
|
556
|
-
// process, one surface scale, shared by every session of the project.
|
|
557
629
|
if (!host.starting)
|
|
558
630
|
host.scale = scale;
|
|
559
631
|
host.starting ??= this.launchPersistent(profile.directory, viewport, scale).then(async (context) => {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
632
|
+
for (const page of context.pages?.() ?? []) {
|
|
633
|
+
const url = String(page.url?.() ?? '');
|
|
634
|
+
if (url && url !== 'about:blank')
|
|
635
|
+
(host.unclaimed ??= []).push(page);
|
|
636
|
+
else
|
|
637
|
+
await Promise.resolve().then(() => page.close()).catch(() => { });
|
|
638
|
+
}
|
|
639
|
+
context.on?.('page', (page) => { void this.claimExtensionPage(profile.key, page); });
|
|
564
640
|
context.on?.('close', () => { if (this.profiles.get(profile.key) === host)
|
|
565
641
|
this.profiles.delete(profile.key); });
|
|
566
642
|
host.context = context;
|
|
@@ -570,7 +646,6 @@ export class BrowserViewManager {
|
|
|
570
646
|
return { context: await host.starting, scale: host.scale ?? 1 };
|
|
571
647
|
}
|
|
572
648
|
catch (error) {
|
|
573
|
-
// A failed launch is not cached: the next open tries the profile again.
|
|
574
649
|
host.users.delete(owner);
|
|
575
650
|
if (this.profiles.get(profile.key) === host)
|
|
576
651
|
this.profiles.delete(profile.key);
|
|
@@ -578,7 +653,41 @@ export class BrowserViewManager {
|
|
|
578
653
|
}
|
|
579
654
|
}
|
|
580
655
|
}
|
|
581
|
-
|
|
656
|
+
async claimExtensionPage(key, page) {
|
|
657
|
+
await new Promise(resolve => { const timer = setTimeout(resolve, EXTENSION_PAGE_CLAIM_MS); timer.unref?.(); });
|
|
658
|
+
if (this.claimedPages.has(page) || page.isClosed?.() === true || this.closed)
|
|
659
|
+
return;
|
|
660
|
+
for (const session of this.sessions.values())
|
|
661
|
+
for (const tab of session.tabs.values())
|
|
662
|
+
if (tab.page === page)
|
|
663
|
+
return;
|
|
664
|
+
// A session whose saved tabs are still being reopened takes extension pages only once they are all back.
|
|
665
|
+
const members = [...this.sessions].filter(([id, session]) => session.profileKey === key && !session.closing && !this.restoring.has(id));
|
|
666
|
+
const [owner] = members.filter(([, session]) => session.streaming).concat(members);
|
|
667
|
+
if (!owner) {
|
|
668
|
+
const host = this.profiles.get(key);
|
|
669
|
+
if (host)
|
|
670
|
+
(host.unclaimed ??= []).push(page);
|
|
671
|
+
else
|
|
672
|
+
await Promise.resolve().then(() => page.close()).catch(() => { });
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
this.claimedPages.add(page);
|
|
676
|
+
await this.adoptPage(owner[0], owner[1], page);
|
|
677
|
+
}
|
|
678
|
+
claimUnclaimed(sessionId, session) {
|
|
679
|
+
// Saved tabs come first: a session being restored claims extension pages after its last tab is back.
|
|
680
|
+
if (this.restoring.has(sessionId))
|
|
681
|
+
return;
|
|
682
|
+
const host = session.profileKey === undefined ? undefined : this.profiles.get(session.profileKey);
|
|
683
|
+
const pages = host?.unclaimed?.splice(0) ?? [];
|
|
684
|
+
for (const page of pages) {
|
|
685
|
+
if (page.isClosed?.() === true)
|
|
686
|
+
continue;
|
|
687
|
+
this.claimedPages.add(page);
|
|
688
|
+
void this.adoptPage(sessionId, session, page);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
582
691
|
async releaseProfile(key, owner) {
|
|
583
692
|
const host = this.profiles.get(key);
|
|
584
693
|
if (!host)
|
|
@@ -597,10 +706,6 @@ export class BrowserViewManager {
|
|
|
597
706
|
})();
|
|
598
707
|
await host.closing;
|
|
599
708
|
}
|
|
600
|
-
/**
|
|
601
|
-
* Open the browser a new session's pages will live in: its project's profile,
|
|
602
|
-
* or a throwaway browser when the session is incognito or has no usable profile.
|
|
603
|
-
*/
|
|
604
709
|
async openBrowserFor(sessionId, viewport, scale) {
|
|
605
710
|
if (!this.incognito.has(sessionId)) {
|
|
606
711
|
const profile = this.options.profileFor ? await this.options.profileFor(sessionId).catch(() => undefined) : undefined;
|
|
@@ -613,18 +718,13 @@ export class BrowserViewManager {
|
|
|
613
718
|
catch (error) {
|
|
614
719
|
if (this.closed)
|
|
615
720
|
throw error;
|
|
616
|
-
// Another process holds the folder, or the profile cannot be opened: the
|
|
617
|
-
// panel still works, on a throwaway browser that says so.
|
|
618
721
|
}
|
|
619
722
|
}
|
|
620
723
|
}
|
|
621
724
|
return { browser: await this.launch(scale), profile: this.incognito.has(sessionId) ? 'incognito' : 'isolated', renderScale: scale };
|
|
622
725
|
}
|
|
623
|
-
/** Close a session's browser, or only its pages when they live in a shared project profile. */
|
|
624
726
|
async disposeBrowser(session) {
|
|
625
727
|
if (session.profileKey === undefined || session.profileOwner === undefined) {
|
|
626
|
-
// Playwright transport shutdown is not reliably awaitable; own the
|
|
627
|
-
// rejection and let the browser close land whenever it lands.
|
|
628
728
|
await Promise.resolve().then(() => session.browser?.close()).catch(() => { });
|
|
629
729
|
return;
|
|
630
730
|
}
|
|
@@ -639,24 +739,35 @@ export class BrowserViewManager {
|
|
|
639
739
|
};
|
|
640
740
|
}
|
|
641
741
|
publishTabs(sessionId, session) {
|
|
642
|
-
// A browser being torn down is no longer the session's: a replacement may
|
|
643
|
-
// already hold the id, and the old generation's late events must not speak
|
|
644
|
-
// for it.
|
|
645
742
|
if (session.closing || this.sessions.get(sessionId) !== session)
|
|
646
743
|
return;
|
|
647
744
|
this.emit('browser.view', { kind: 'tabs', sessionId, ...this.summary(session) });
|
|
648
745
|
}
|
|
649
|
-
|
|
746
|
+
hold(sessionId, ms) {
|
|
747
|
+
const now = Date.now();
|
|
748
|
+
for (const [id, until] of this.holds)
|
|
749
|
+
if (until + VIEW_IDLE_CLOSE_MS <= now)
|
|
750
|
+
this.holds.delete(id);
|
|
751
|
+
this.holds.set(sessionId, now + Math.max(0, Math.min(ms, VIEW_HOLD_MAX_MS)));
|
|
752
|
+
return { held: this.sessions.has(sessionId) };
|
|
753
|
+
}
|
|
754
|
+
scheduleIdleClose(sessionId, session, delay = VIEW_IDLE_CLOSE_MS) {
|
|
650
755
|
if (session.idleTimer)
|
|
651
756
|
clearTimeout(session.idleTimer);
|
|
652
|
-
// A session someone is watching (streaming) is never idle-reaped; only an
|
|
653
|
-
// abandoned open browser is, so a forgotten panel cannot pin memory forever.
|
|
654
757
|
session.idleTimer = setTimeout(() => {
|
|
655
758
|
session.idleTimer = undefined;
|
|
656
|
-
|
|
759
|
+
const until = this.holds.get(sessionId);
|
|
760
|
+
if (until !== undefined) {
|
|
761
|
+
const remaining = until + VIEW_IDLE_CLOSE_MS - Date.now();
|
|
762
|
+
if (remaining > 0) {
|
|
763
|
+
this.scheduleIdleClose(sessionId, session, remaining);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
this.holds.delete(sessionId);
|
|
767
|
+
}
|
|
657
768
|
if (!session.streaming && session.pendingTabs === 0)
|
|
658
769
|
void this.closeSession(sessionId, 'idle', session);
|
|
659
|
-
},
|
|
770
|
+
}, delay);
|
|
660
771
|
session.idleTimer.unref?.();
|
|
661
772
|
}
|
|
662
773
|
async stopScreencast(tab) {
|
|
@@ -669,56 +780,20 @@ export class BrowserViewManager {
|
|
|
669
780
|
try {
|
|
670
781
|
await tab.cdp?.send('Page.stopScreencast');
|
|
671
782
|
}
|
|
672
|
-
catch {
|
|
783
|
+
catch { }
|
|
673
784
|
}
|
|
674
|
-
/**
|
|
675
|
-
* Show one tab: the pane's current size, then its stream.
|
|
676
|
-
*
|
|
677
|
-
* Every path that makes a tab the visible one goes through here — an explicit
|
|
678
|
-
* activation, an open that completed while it still owned the selection, and
|
|
679
|
-
* the fallback chosen when the active tab closes — because a pane resized
|
|
680
|
-
* while the tab was inactive only sized the active page, and a page laid out
|
|
681
|
-
* at a stale size puts every translated click in the wrong place.
|
|
682
|
-
*/
|
|
683
785
|
async showTab(session, tab) {
|
|
684
786
|
if (session.activeTabId !== tab.id)
|
|
685
787
|
return;
|
|
686
788
|
await this.queueViewportMode(session, tab);
|
|
687
|
-
// Two activations can overlap: the later one owns the pane by the time this
|
|
688
|
-
// page finishes resizing, and a stream started for the earlier tab would be
|
|
689
|
-
// a stream nobody sees — while its `streaming` flag would keep the next
|
|
690
|
-
// selection of that tab from ever starting one.
|
|
691
789
|
if (session.activeTabId !== tab.id)
|
|
692
790
|
return;
|
|
693
791
|
await this.startScreencast(session, tab);
|
|
694
792
|
}
|
|
695
|
-
/**
|
|
696
|
-
* Put one page into the session's viewport mode.
|
|
697
|
-
*
|
|
698
|
-
* Desktop sizes the page to the pane. Mobile is full emulation: the fixed
|
|
699
|
-
* phone's device metrics — `mobile: true` is what makes the meta viewport
|
|
700
|
-
* respected, with a phone's pixel density — a mobile Chrome user agent, and
|
|
701
|
-
* touch events, so the sites the pane shows answer with their mobile layouts
|
|
702
|
-
* and hover-dependent UIs behave like they do on a phone. Leaving Mobile
|
|
703
|
-
* clears the metrics and applies the desktop spoof identity (see
|
|
704
|
-
* browser-stealth), so the page presents as a normal desktop browser rather
|
|
705
|
-
* than the headless automation UA a reset would expose. A switch changes the
|
|
706
|
-
* page's size, so the caller restarts the screencast for the new capture
|
|
707
|
-
* scale.
|
|
708
|
-
*
|
|
709
|
-
* Calls for one tab are serialized by `queueViewportMode`: each applies
|
|
710
|
-
* whatever the session's mode is at its turn, so a rapid toggle cannot leave
|
|
711
|
-
* a page emulated under a session that has already moved on.
|
|
712
|
-
*/
|
|
713
793
|
async applyViewportMode(session, tab) {
|
|
714
794
|
const mobile = session.mode === 'mobile';
|
|
715
795
|
try {
|
|
716
796
|
if (mobile) {
|
|
717
|
-
// Full device metrics, not just dimensions. Playwright's own
|
|
718
|
-
// setViewportSize would re-issue the override with `mobile: false`, so
|
|
719
|
-
// while Mobile is on, this override is the page's only sizing
|
|
720
|
-
// authority (verified live: the metrics override yields exactly
|
|
721
|
-
// 390×844 screencast frames at a phone's pixel density).
|
|
722
797
|
await tab.cdp.send('Emulation.setDeviceMetricsOverride', {
|
|
723
798
|
width: VIEW_MOBILE_VIEWPORT.width, height: VIEW_MOBILE_VIEWPORT.height, deviceScaleFactor: VIEW_MOBILE_SCALE, mobile: true,
|
|
724
799
|
});
|
|
@@ -727,13 +802,6 @@ export class BrowserViewManager {
|
|
|
727
802
|
if (tab.emulated)
|
|
728
803
|
await tab.cdp.send('Emulation.clearDeviceMetricsOverride');
|
|
729
804
|
await tab.page.setViewportSize(session.viewport).catch(() => { });
|
|
730
|
-
// Playwright sizes the page at 1×, which on a browser launched at a
|
|
731
|
-
// higher factor renders at 1× and stretches into the surface — the blur
|
|
732
|
-
// this exists to remove. The page renders at the browser's real factor
|
|
733
|
-
// instead, as a native window on that display would, sharp text and
|
|
734
|
-
// `srcset` images included. The override is sent every time and after
|
|
735
|
-
// Playwright's: Playwright skips a size it believes it already applied,
|
|
736
|
-
// so it cannot be relied on to put back a ratio this override replaced.
|
|
737
805
|
await tab.cdp.send('Emulation.setDeviceMetricsOverride', {
|
|
738
806
|
width: session.viewport.width, height: session.viewport.height, deviceScaleFactor: session.renderScale, mobile: false,
|
|
739
807
|
});
|
|
@@ -743,21 +811,17 @@ export class BrowserViewManager {
|
|
|
743
811
|
tab.emulated = mobile;
|
|
744
812
|
await tab.cdp.send('Emulation.setUserAgentOverride', mobile
|
|
745
813
|
? { userAgent: VIEW_MOBILE_USER_AGENT }
|
|
746
|
-
// Desktop presents the spoofed identity too: an empty override would
|
|
747
|
-
// expose the headless browser's own UA to every site the panel shows.
|
|
748
814
|
: desktopUaOverride());
|
|
749
815
|
await tab.cdp.send('Emulation.setTouchEmulationEnabled', { enabled: mobile, ...(mobile ? { maxTouchPoints: 5 } : {}) });
|
|
750
816
|
}
|
|
751
|
-
catch {
|
|
817
|
+
catch { }
|
|
752
818
|
}
|
|
753
|
-
/** The per-tab serialization `applyViewportMode` relies on; see its note. */
|
|
754
819
|
queueViewportMode(session, tab) {
|
|
755
820
|
const tail = (tab.modeTask ?? Promise.resolve()).catch(() => { });
|
|
756
821
|
tab.modeTask = tail.then(() => this.applyViewportMode(session, tab));
|
|
757
822
|
return tab.modeTask;
|
|
758
823
|
}
|
|
759
824
|
emitFrame(sessionId, session, tab, payload) {
|
|
760
|
-
// Frames still in flight from a replaced browser belong to nobody.
|
|
761
825
|
if (session.closing || this.sessions.get(sessionId) !== session)
|
|
762
826
|
return;
|
|
763
827
|
if (payload.data.length > VIEW_FRAME_LIMIT) {
|
|
@@ -786,11 +850,6 @@ export class BrowserViewManager {
|
|
|
786
850
|
try {
|
|
787
851
|
await tab.cdp.send('Page.startScreencast', {
|
|
788
852
|
format: 'jpeg', quality: Math.min(session.quality, budget.quality),
|
|
789
|
-
// The viewport at the pane's ratio: one frame pixel per screen pixel.
|
|
790
|
-
// A browser launched at that ratio fills it exactly; one launched
|
|
791
|
-
// denser (the window moved to a lower-density monitor) is scaled down
|
|
792
|
-
// to it once, and the caps never scale a frame up. A page whose frames
|
|
793
|
-
// outgrew the payload limit runs at a reduced size until it changes.
|
|
794
853
|
maxWidth: Math.ceil(session.viewport.width * session.scale * budget.size),
|
|
795
854
|
maxHeight: Math.ceil(session.viewport.height * session.scale * budget.size),
|
|
796
855
|
everyNthFrame: 1,
|
|
@@ -800,11 +859,6 @@ export class BrowserViewManager {
|
|
|
800
859
|
tab.streaming = false;
|
|
801
860
|
}
|
|
802
861
|
}
|
|
803
|
-
/**
|
|
804
|
-
* Step one tab's frame budget down after a frame came out over the limit, and
|
|
805
|
-
* restart its stream at it. The oversized frame itself is not sent; the pane
|
|
806
|
-
* keeps its previous frame until the smaller stream delivers.
|
|
807
|
-
*/
|
|
808
862
|
async shrinkStream(session, tab) {
|
|
809
863
|
if (tab.shrinking || !tab.streaming)
|
|
810
864
|
return;
|
|
@@ -814,7 +868,6 @@ export class BrowserViewManager {
|
|
|
814
868
|
tab.budget = next;
|
|
815
869
|
await this.restartStream(session, tab);
|
|
816
870
|
}
|
|
817
|
-
/** Stop and start one tab's stream, keeping it only while it still owns the pane. */
|
|
818
871
|
async restartStream(session, tab) {
|
|
819
872
|
if (tab.shrinking)
|
|
820
873
|
return;
|
|
@@ -834,18 +887,13 @@ export class BrowserViewManager {
|
|
|
834
887
|
streaming: false, seq: 0, lastEmitAt: undefined, imageWidth: session.viewport.width, imageHeight: session.viewport.height,
|
|
835
888
|
};
|
|
836
889
|
const publish = () => this.publishTabs(sessionId, session);
|
|
837
|
-
// A fragment link or a `pushState` route change commits without loading a
|
|
838
|
-
// document: `framenavigated` fires, `domcontentloaded` does not. Tracking the
|
|
839
|
-
// document request is what tells the two apart, so the commit of a new
|
|
840
|
-
// document clears the previous one's title and marks the tab loading while a
|
|
841
|
-
// same-document commit only moves the address.
|
|
842
890
|
let documentRequest;
|
|
843
891
|
page.on('request', (request) => {
|
|
844
892
|
try {
|
|
845
893
|
if (request?.isNavigationRequest?.() === true && request.frame?.() === page.mainFrame())
|
|
846
894
|
documentRequest = request;
|
|
847
895
|
}
|
|
848
|
-
catch {
|
|
896
|
+
catch { }
|
|
849
897
|
});
|
|
850
898
|
page.on('requestfailed', (request) => { if (request === documentRequest)
|
|
851
899
|
documentRequest = undefined; });
|
|
@@ -858,8 +906,6 @@ export class BrowserViewManager {
|
|
|
858
906
|
if (newDocument) {
|
|
859
907
|
tab.loading = true;
|
|
860
908
|
tab.title = '';
|
|
861
|
-
// The budget was earned by the previous document's content; the next
|
|
862
|
-
// page gets full quality and size again.
|
|
863
909
|
if (tab.budget) {
|
|
864
910
|
tab.budget = undefined;
|
|
865
911
|
if (tab.streaming)
|
|
@@ -886,27 +932,18 @@ export class BrowserViewManager {
|
|
|
886
932
|
if (next)
|
|
887
933
|
void this.showTab(session, next);
|
|
888
934
|
}
|
|
889
|
-
// A tab whose page is still being created is a live session too: closing
|
|
890
|
-
// the browser here would take it away from the open that is waiting on it.
|
|
891
935
|
if (session.tabs.size === 0 && session.pendingTabs === 0)
|
|
892
936
|
void this.closeSession(sessionId, undefined, session);
|
|
893
937
|
else
|
|
894
938
|
publish();
|
|
895
939
|
});
|
|
896
940
|
page.on('crash', () => { void page.close().catch(() => { }); });
|
|
897
|
-
|
|
898
|
-
// this the destination loads in a browser nobody can see. A popup becomes a
|
|
899
|
-
// tab of the session (the cap applies to it like any other open), and it
|
|
900
|
-
// takes the pane so the user follows the link they clicked.
|
|
901
|
-
page.on('popup', (popup) => { void this.adoptPage(sessionId, session, popup); });
|
|
941
|
+
page.on('popup', (popup) => { this.claimedPages.add(popup); void this.adoptPage(sessionId, session, popup); });
|
|
902
942
|
cdp.on('Page.screencastFrame', async (payload) => {
|
|
903
|
-
// Acknowledge first, always: the stream has a small outstanding-frame
|
|
904
|
-
// window, and an unacknowledged frame stalls it even when this frame is
|
|
905
|
-
// held back by the pacing window or its tab is no longer active.
|
|
906
943
|
try {
|
|
907
944
|
await cdp.send('Page.screencastFrameAck', { sessionId: payload.sessionId });
|
|
908
945
|
}
|
|
909
|
-
catch {
|
|
946
|
+
catch { }
|
|
910
947
|
if (!tab.streaming || session.activeTabId !== tab.id || session.closing)
|
|
911
948
|
return;
|
|
912
949
|
const now = Date.now();
|
|
@@ -919,9 +956,6 @@ export class BrowserViewManager {
|
|
|
919
956
|
this.emitFrame(sessionId, session, tab, payload);
|
|
920
957
|
return;
|
|
921
958
|
}
|
|
922
|
-
// Inside the pacing window: keep only the newest image and deliver it
|
|
923
|
-
// when the window opens. Dropping it outright would leave the panel on an
|
|
924
|
-
// older frame forever when the page's last update lands here.
|
|
925
959
|
tab.pendingFrame = payload;
|
|
926
960
|
if (tab.pendingTimer)
|
|
927
961
|
return;
|
|
@@ -939,14 +973,6 @@ export class BrowserViewManager {
|
|
|
939
973
|
session.tabs.set(tab.id, tab);
|
|
940
974
|
return tab;
|
|
941
975
|
}
|
|
942
|
-
/**
|
|
943
|
-
* A frame straight from the page, for a stream that is already running.
|
|
944
|
-
*
|
|
945
|
-
* A pane that reattaches (a renderer reload) has no image of its own, and a
|
|
946
|
-
* static page produces no new screencast frames, so the screencast's own
|
|
947
|
-
* stream cannot supply one. A screenshot is bounded and always reflects the
|
|
948
|
-
* page as it is now.
|
|
949
|
-
*/
|
|
950
976
|
async captureFrame(sessionId, session, tab) {
|
|
951
977
|
try {
|
|
952
978
|
const shot = await tab.cdp?.send('Page.captureScreenshot', { format: 'jpeg', quality: session.quality });
|
|
@@ -956,15 +982,8 @@ export class BrowserViewManager {
|
|
|
956
982
|
return;
|
|
957
983
|
this.emitFrame(sessionId, session, tab, { data: shot.data, sessionId: 'capture' });
|
|
958
984
|
}
|
|
959
|
-
catch {
|
|
985
|
+
catch { }
|
|
960
986
|
}
|
|
961
|
-
/**
|
|
962
|
-
* A page the browser opened on its own, adopted as a tab of the session.
|
|
963
|
-
*
|
|
964
|
-
* The page is already live, so it only needs a CDP session and its pane
|
|
965
|
-
* geometry. Past the tab cap the popup is closed rather than left running as an
|
|
966
|
-
* invisible page: the cap states one bound for everything the browser holds.
|
|
967
|
-
*/
|
|
968
987
|
async adoptPage(sessionId, session, page) {
|
|
969
988
|
if (session.closing) {
|
|
970
989
|
await Promise.resolve().then(() => page.close()).catch(() => { });
|
|
@@ -980,12 +999,6 @@ export class BrowserViewManager {
|
|
|
980
999
|
const previous = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
981
1000
|
if (previous)
|
|
982
1001
|
await this.stopScreencast(previous);
|
|
983
|
-
// Adoption yields before it takes the pane, so a tab activated meanwhile is
|
|
984
|
-
// streaming by now; assigning the popup would discard its frames while its
|
|
985
|
-
// `streaming` flag stayed on, and reselecting it would request neither a new
|
|
986
|
-
// screencast nor a screenshot. Stop the tab that actually holds the pane, as
|
|
987
|
-
// an open does; the loop is bounded by a stream really running, because a
|
|
988
|
-
// stop with nothing to do cannot have yielded.
|
|
989
1002
|
let selected = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
990
1003
|
while (selected && selected.streaming) {
|
|
991
1004
|
await this.stopScreencast(selected);
|
|
@@ -997,9 +1010,6 @@ export class BrowserViewManager {
|
|
|
997
1010
|
}
|
|
998
1011
|
const tab = this.wireTab(sessionId, session, page, cdp);
|
|
999
1012
|
await this.queueViewportMode(session, tab);
|
|
1000
|
-
// The mode application yields, so a tab the user activated meanwhile can
|
|
1001
|
-
// be streaming: it stops before the popup takes the pane, or it would
|
|
1002
|
-
// stream on with nobody watching — the same reason the loop above ran.
|
|
1003
1013
|
selected = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1004
1014
|
while (selected && selected.streaming) {
|
|
1005
1015
|
await this.stopScreencast(selected);
|
|
@@ -1010,8 +1020,6 @@ export class BrowserViewManager {
|
|
|
1010
1020
|
return;
|
|
1011
1021
|
}
|
|
1012
1022
|
session.activeTabId = tab.id;
|
|
1013
|
-
// The popup has usually navigated before it reached us, so its landing URL
|
|
1014
|
-
// is read from the page rather than waiting for an event that already fired.
|
|
1015
1023
|
tab.url = String(page.url?.() ?? '').slice(0, VIEW_URL_LIMIT);
|
|
1016
1024
|
void page.title?.().then((title) => {
|
|
1017
1025
|
if (typeof title === 'string' && title) {
|
|
@@ -1035,9 +1043,6 @@ export class BrowserViewManager {
|
|
|
1035
1043
|
this.scheduleIdleClose(sessionId, existing);
|
|
1036
1044
|
return existing;
|
|
1037
1045
|
}
|
|
1038
|
-
// A second open can arrive while the first is still launching (Enter pressed
|
|
1039
|
-
// twice). It joins that launch instead of starting a second browser whose
|
|
1040
|
-
// session record would overwrite the first and leave it unreachable.
|
|
1041
1046
|
const inflight = this.launching.get(sessionId);
|
|
1042
1047
|
if (inflight)
|
|
1043
1048
|
return await inflight;
|
|
@@ -1049,23 +1054,14 @@ export class BrowserViewManager {
|
|
|
1049
1054
|
const desired = this.desired.get(sessionId);
|
|
1050
1055
|
const viewport = desired?.viewport ?? clampViewport(undefined, undefined);
|
|
1051
1056
|
const opened = await this.openBrowserFor(sessionId, viewport, desired?.scale ?? this.displayScale);
|
|
1052
|
-
// Shutdown may have finished while the launch was in flight: the browser
|
|
1053
|
-
// that arrived late belongs to nobody, so it is closed here rather than
|
|
1054
|
-
// inserted into a manager that has already visited its sessions.
|
|
1055
1057
|
if (this.closed) {
|
|
1056
1058
|
await this.disposeBrowser({ ...opened, tabs: new Map() });
|
|
1057
1059
|
throw new Error('Application is shutting down');
|
|
1058
1060
|
}
|
|
1059
|
-
// A release that landed while this launch was in flight has already closed
|
|
1060
|
-
// whatever it found; the browser this launch just produced belongs to the
|
|
1061
|
-
// session that no longer exists, so it goes the same way.
|
|
1062
1061
|
if (this.released.delete(sessionId)) {
|
|
1063
1062
|
await this.disposeBrowser({ ...opened, tabs: new Map() });
|
|
1064
1063
|
throw new Error('That session was deleted.');
|
|
1065
1064
|
}
|
|
1066
|
-
// The pane can enable streaming, resize or switch mode while the launch is in
|
|
1067
|
-
// flight; those requests found no session to update, so the session takes
|
|
1068
|
-
// the request as it stands now, not as it stood when the launch began.
|
|
1069
1065
|
const current = this.desired.get(sessionId);
|
|
1070
1066
|
const session = {
|
|
1071
1067
|
...opened, tabs: new Map(), activeTabId: undefined, pendingTabs: 0,
|
|
@@ -1076,6 +1072,7 @@ export class BrowserViewManager {
|
|
|
1076
1072
|
};
|
|
1077
1073
|
this.sessions.set(sessionId, session);
|
|
1078
1074
|
this.scheduleIdleClose(sessionId, session);
|
|
1075
|
+
this.claimUnclaimed(sessionId, session);
|
|
1079
1076
|
return session;
|
|
1080
1077
|
})();
|
|
1081
1078
|
this.launching.set(sessionId, starting);
|
|
@@ -1086,14 +1083,6 @@ export class BrowserViewManager {
|
|
|
1086
1083
|
this.launching.delete(sessionId);
|
|
1087
1084
|
}
|
|
1088
1085
|
}
|
|
1089
|
-
/**
|
|
1090
|
-
* The session's browser context, created once.
|
|
1091
|
-
*
|
|
1092
|
-
* One context is what makes the tabs one browser: cookies, local storage and
|
|
1093
|
-
* cache are shared across the pages in it. A project session's context is its
|
|
1094
|
-
* project's persistent profile, shared with that project's other sessions; an
|
|
1095
|
-
* incognito or isolated session gets a fresh context of its own.
|
|
1096
|
-
*/
|
|
1097
1086
|
async contextFor(session) {
|
|
1098
1087
|
if (session.context)
|
|
1099
1088
|
return session.context;
|
|
@@ -1105,24 +1094,14 @@ export class BrowserViewManager {
|
|
|
1105
1094
|
async openTab(sessionId, url, signal) {
|
|
1106
1095
|
return await this.openPage(sessionId, browserViewUrl(url), signal);
|
|
1107
1096
|
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Replace the session's panel browser with an incognito one showing a blank tab.
|
|
1110
|
-
*
|
|
1111
|
-
* The current browser closes first — its tabs go with it, and a project
|
|
1112
|
-
* profile it used is left untouched on disk. Nothing the incognito browser
|
|
1113
|
-
* does is saved, and it lasts until `endIncognito` or until it closes.
|
|
1114
|
-
*/
|
|
1115
1097
|
async startIncognito(sessionId, signal) {
|
|
1116
|
-
// Wait out every launch for this session, including one an open began while
|
|
1117
|
-
// this call was waiting, so nothing registers a project browser behind it.
|
|
1118
1098
|
while (this.launching.has(sessionId))
|
|
1119
1099
|
await this.launching.get(sessionId).catch(() => undefined);
|
|
1120
|
-
// A switch that was stopped or timed out while waiting must not tear down the
|
|
1121
|
-
// browser the user is using: nothing has been closed yet.
|
|
1122
1100
|
signal?.throwIfAborted();
|
|
1123
|
-
//
|
|
1124
|
-
|
|
1125
|
-
|
|
1101
|
+
// An extension restart about to reopen this session's project tabs leaves the switch alone.
|
|
1102
|
+
const restoring = this.restoring.get(sessionId);
|
|
1103
|
+
if (restoring)
|
|
1104
|
+
restoring.abandoned = true;
|
|
1126
1105
|
const closing = this.closeSession(sessionId, 'incognito');
|
|
1127
1106
|
this.incognito.add(sessionId);
|
|
1128
1107
|
await closing;
|
|
@@ -1131,10 +1110,6 @@ export class BrowserViewManager {
|
|
|
1131
1110
|
return await this.openPage(sessionId, 'about:blank', signal, 'incognito');
|
|
1132
1111
|
}
|
|
1133
1112
|
catch (error) {
|
|
1134
|
-
// A start that failed or was abandoned (stopped, or past its deadline) must
|
|
1135
|
-
// not leave an incognito browser a later open would land in unannounced:
|
|
1136
|
-
// one that launched but holds no tab is closed, which also clears the mark,
|
|
1137
|
-
// and a browser that never started leaves no mark behind.
|
|
1138
1113
|
const session = this.sessions.get(sessionId);
|
|
1139
1114
|
if (!session)
|
|
1140
1115
|
this.incognito.delete(sessionId);
|
|
@@ -1143,12 +1118,9 @@ export class BrowserViewManager {
|
|
|
1143
1118
|
throw error;
|
|
1144
1119
|
}
|
|
1145
1120
|
}
|
|
1146
|
-
/** Close the session's incognito browser, if it has one; the next open uses the project profile. */
|
|
1147
1121
|
async endIncognito(sessionId, signal) {
|
|
1148
1122
|
while (this.launching.has(sessionId))
|
|
1149
1123
|
await this.launching.get(sessionId).catch(() => undefined);
|
|
1150
|
-
// An end that was stopped or timed out while a launch finished must not close
|
|
1151
|
-
// the browser afterwards: nothing has changed yet, and the agent was told it failed.
|
|
1152
1124
|
signal?.throwIfAborted();
|
|
1153
1125
|
const session = this.sessions.get(sessionId);
|
|
1154
1126
|
const active = this.incognito.delete(sessionId) || session?.profile === 'incognito';
|
|
@@ -1156,14 +1128,6 @@ export class BrowserViewManager {
|
|
|
1156
1128
|
await this.closeSession(sessionId, 'incognito ended');
|
|
1157
1129
|
return active;
|
|
1158
1130
|
}
|
|
1159
|
-
/**
|
|
1160
|
-
* Add cookies to the project profile the session's panel browser runs on, then
|
|
1161
|
-
* reload its active tab so the page is requested again with them.
|
|
1162
|
-
*
|
|
1163
|
-
* Only the project profile takes an import: it is the one browser whose cookies
|
|
1164
|
-
* are kept, and the one the pane's badge never marks as temporary. The cookies
|
|
1165
|
-
* go to the profile's shared context, so every session of the project has them.
|
|
1166
|
-
*/
|
|
1167
1131
|
async importCookies(sessionId, cookies) {
|
|
1168
1132
|
const session = this.sessions.get(sessionId);
|
|
1169
1133
|
if (!session || session.closing || session.tabs.size === 0)
|
|
@@ -1174,28 +1138,18 @@ export class BrowserViewManager {
|
|
|
1174
1138
|
throw new Error('This browser is temporary, so imported cookies would not be kept');
|
|
1175
1139
|
this.scheduleIdleClose(sessionId, session);
|
|
1176
1140
|
await session.context.addCookies(cookies);
|
|
1177
|
-
// The import has already happened; a page that fails to reload is the page's
|
|
1178
|
-
// own failure and shows in the pane, not a reason to report the import failed.
|
|
1179
1141
|
await this.go(sessionId, 'refresh').catch(() => { });
|
|
1180
1142
|
}
|
|
1181
|
-
/** The kind of browser the session's pages live in now, or would on the next open. */
|
|
1182
1143
|
profileKind(sessionId) {
|
|
1183
1144
|
return this.sessions.get(sessionId)?.profile ?? (this.incognito.has(sessionId) ? 'incognito' : undefined);
|
|
1184
1145
|
}
|
|
1185
1146
|
async openPage(sessionId, target, signal, requireProfile) {
|
|
1186
1147
|
const session = await this.ensureSession(sessionId);
|
|
1187
|
-
// The launch is the longest wait here, and the one a stop usually arrives
|
|
1188
|
-
// during: a cancelled call returns before creating a page at all.
|
|
1189
1148
|
signal?.throwIfAborted();
|
|
1190
|
-
// A switch to incognito must never report success on the signed-in profile.
|
|
1191
1149
|
if (requireProfile !== undefined && session.profile !== requireProfile)
|
|
1192
1150
|
throw new Error(`The panel browser is not ${requireProfile}; retry the switch`);
|
|
1193
1151
|
if (session.closing)
|
|
1194
1152
|
throw new Error('Browser is closing; retry shortly');
|
|
1195
|
-
// Capacity is reserved before the first await. Stopping the previous
|
|
1196
|
-
// screencast and creating the page both yield, so a burst of overlapping
|
|
1197
|
-
// opens would otherwise all pass a plain `tabs.size` check and exceed the
|
|
1198
|
-
// cap with pages nobody intended to keep.
|
|
1199
1153
|
if (session.tabs.size + session.pendingTabs >= VIEW_TAB_LIMIT)
|
|
1200
1154
|
throw new Error('Close a tab before opening another (maximum 6)');
|
|
1201
1155
|
session.pendingTabs += 1;
|
|
@@ -1212,84 +1166,43 @@ export class BrowserViewManager {
|
|
|
1212
1166
|
await this.stopScreencast(previous);
|
|
1213
1167
|
const context = await this.contextFor(session);
|
|
1214
1168
|
const page = await context.newPage();
|
|
1169
|
+
this.claimedPages.add(page);
|
|
1215
1170
|
const cdp = await Promise.resolve().then(() => page.context().newCDPSession(page)).catch(async (error) => {
|
|
1216
1171
|
await Promise.resolve().then(() => page.close()).catch(() => { });
|
|
1217
1172
|
throw error;
|
|
1218
1173
|
});
|
|
1219
|
-
// A shared project profile outlives this session: a page whose session
|
|
1220
|
-
// started closing while it was created or attached would otherwise stay
|
|
1221
|
-
// open in it, unowned, because teardown closes only registered tabs. The
|
|
1222
|
-
// check sits directly before registration, with no await between them, so
|
|
1223
|
-
// a teardown that starts afterwards always finds this tab.
|
|
1224
1174
|
if (session.closing) {
|
|
1225
1175
|
await Promise.resolve().then(() => cdp.detach?.()).catch(() => { });
|
|
1226
1176
|
await Promise.resolve().then(() => page.close()).catch(() => { });
|
|
1227
1177
|
throw new Error('Browser is closing; retry shortly');
|
|
1228
1178
|
}
|
|
1229
1179
|
const tab = this.wireTab(sessionId, session, page, cdp);
|
|
1230
|
-
// The context was created at the viewport of the first open; a tab opened
|
|
1231
|
-
// after the pane was resized has to match the pane it will be shown in, or
|
|
1232
|
-
// its layout and every translated click would use the old size. The mode's
|
|
1233
|
-
// emulation rides along on the same call.
|
|
1234
1180
|
await this.queueViewportMode(session, tab);
|
|
1235
|
-
// The reservation has become a real tab; the cap now counts it directly.
|
|
1236
1181
|
release();
|
|
1237
|
-
// The pane follows the newest open. The selection may have moved while this
|
|
1238
|
-
// page was being created, so it is re-read and stopped until it is this
|
|
1239
|
-
// tab's: a stream left running for a tab nobody sees discards its frames
|
|
1240
|
-
// while keeping `streaming` true, and selecting that tab again would then
|
|
1241
|
-
// start nothing. The loop is bounded by the tab actually streaming — a stop
|
|
1242
|
-
// with nothing to do cannot have yielded to another activation, so the
|
|
1243
|
-
// assignment that follows is atomic.
|
|
1244
1182
|
let selected = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1245
1183
|
while (selected && selected.id !== tab.id && selected.streaming) {
|
|
1246
1184
|
await this.stopScreencast(selected);
|
|
1247
|
-
// An activation can land during that await; stop whatever the selection
|
|
1248
|
-
// has become before this tab takes it.
|
|
1249
1185
|
selected = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1250
1186
|
}
|
|
1251
|
-
// Creating the page stops the previous screencast, and both yield: a run
|
|
1252
|
-
// stopped while its tab was being made must not select it or load the URL
|
|
1253
|
-
// afterwards, so only the unfinished tab is closed here — the rest of the
|
|
1254
|
-
// shared browser the user is watching stays exactly as it is.
|
|
1255
1187
|
if (signal?.aborted) {
|
|
1256
1188
|
await this.discardTab(sessionId, session, tab, previous);
|
|
1257
|
-
// The pane never left the tab it was on, but this open had already stopped that tab's
|
|
1258
|
-
// stream: without restarting it the panel would sit frozen on a tab that still accepts
|
|
1259
|
-
// input. `discardTab` restores the stream only for a tab that held the pane, which this
|
|
1260
|
-
// one never did.
|
|
1261
1189
|
const survivor = session.activeTabId === undefined ? undefined : session.tabs.get(session.activeTabId);
|
|
1262
1190
|
if (survivor && !survivor.streaming)
|
|
1263
1191
|
await this.showTab(session, survivor);
|
|
1264
1192
|
signal.throwIfAborted();
|
|
1265
1193
|
}
|
|
1266
1194
|
session.activeTabId = tab.id;
|
|
1267
|
-
// The pane's target changes here, before the navigation it waits for: an
|
|
1268
|
-
// input request naming no tab of its own would otherwise land on a page the
|
|
1269
|
-
// panel is not showing yet, and the strip would still name the old one.
|
|
1270
1195
|
this.publishTabs(sessionId, session);
|
|
1271
1196
|
try {
|
|
1272
1197
|
await page.goto(target, { waitUntil: 'domcontentloaded', timeout: VIEW_GOTO_TIMEOUT_MS });
|
|
1273
1198
|
}
|
|
1274
1199
|
catch (error) {
|
|
1275
|
-
// A page that failed its first navigation is not a tab worth keeping: an
|
|
1276
|
-
// address-bar retry would otherwise stack error pages behind it.
|
|
1277
1200
|
await this.discardTab(sessionId, session, tab, previous);
|
|
1278
1201
|
throw error;
|
|
1279
1202
|
}
|
|
1280
|
-
// The URL the tab shows is the one the page actually landed on
|
|
1281
|
-
// (`framenavigated` records redirects); the requested target may differ.
|
|
1282
|
-
// A slow open that finished after a later one took the selection must not
|
|
1283
|
-
// start a stream for a tab nobody is looking at: its frames would be
|
|
1284
|
-
// discarded while `streaming` stayed true, and activating it later would
|
|
1285
|
-
// find the stream already "running" and never ask for a fresh frame.
|
|
1286
1203
|
if (session.activeTabId === tab.id)
|
|
1287
1204
|
await this.showTab(session, tab);
|
|
1288
1205
|
this.publishTabs(sessionId, session);
|
|
1289
|
-
// The pane follows an open, whoever drove it: an agent's first tab is the
|
|
1290
|
-
// moment the panel should be on screen, and expanding an open pane is a
|
|
1291
|
-
// no-op, so the user's own opens can simply ride the same event. A session
|
|
1292
|
-
// being torn down is nobody's pane to open.
|
|
1293
1206
|
if (!session.closing)
|
|
1294
1207
|
this.emit('browser.panel.opened', { sessionId });
|
|
1295
1208
|
return { tabId: tab.id };
|
|
@@ -1298,21 +1211,8 @@ export class BrowserViewManager {
|
|
|
1298
1211
|
release();
|
|
1299
1212
|
}
|
|
1300
1213
|
}
|
|
1301
|
-
/**
|
|
1302
|
-
* Remove one tab an open created and did not finish.
|
|
1303
|
-
*
|
|
1304
|
-
* The page itself is closed too — a discarded page still runs and still counts
|
|
1305
|
-
* against the browser, and the tab cap only counts pages it holds. Only the
|
|
1306
|
-
* unfinished tab goes: the rest of the shared browser, which the user may be
|
|
1307
|
-
* watching, is left as it is.
|
|
1308
|
-
*/
|
|
1309
1214
|
async discardTab(sessionId, session, tab, previous) {
|
|
1310
1215
|
session.tabs.delete(tab.id);
|
|
1311
|
-
// Only the tab that is still selected may hand the pane back: an overlapping
|
|
1312
|
-
// open that succeeded meanwhile owns it, and clearing its selection would
|
|
1313
|
-
// leave a visible tab that input cannot address. The tab that owned the pane
|
|
1314
|
-
// before this open may itself have been closed while the open was in flight,
|
|
1315
|
-
// so a survivor is chosen instead.
|
|
1316
1216
|
if (session.activeTabId === tab.id) {
|
|
1317
1217
|
const fallback = previous && session.tabs.has(previous.id) ? previous : [...session.tabs.values()][0];
|
|
1318
1218
|
session.activeTabId = fallback?.id;
|
|
@@ -1321,13 +1221,10 @@ export class BrowserViewManager {
|
|
|
1321
1221
|
}
|
|
1322
1222
|
await tab.cdp?.detach().catch(() => { });
|
|
1323
1223
|
await tab.page.close().catch(() => { });
|
|
1324
|
-
// Another open may still be creating its page: the session is not empty.
|
|
1325
1224
|
if (session.tabs.size === 0 && session.pendingTabs === 0)
|
|
1326
1225
|
void this.closeSession(sessionId, undefined, session);
|
|
1327
1226
|
}
|
|
1328
1227
|
activeOrNamed(session, tabId) {
|
|
1329
|
-
// An explicit id names one tab: falling back to the selection would let a
|
|
1330
|
-
// repeated close of a tab that is already gone destroy an unrelated one.
|
|
1331
1228
|
if (tabId !== undefined) {
|
|
1332
1229
|
const named = session.tabs.get(tabId);
|
|
1333
1230
|
if (!named)
|
|
@@ -1347,10 +1244,7 @@ export class BrowserViewManager {
|
|
|
1347
1244
|
const tab = this.activeOrNamed(session, tabId);
|
|
1348
1245
|
this.scheduleIdleClose(sessionId, session);
|
|
1349
1246
|
await tab.page.goto(target, { waitUntil: 'domcontentloaded', timeout: VIEW_GOTO_TIMEOUT_MS });
|
|
1350
|
-
// `framenavigated` owns the tab's URL (it records where redirects landed);
|
|
1351
|
-
// overwriting it here would describe an address the page is not showing.
|
|
1352
1247
|
this.publishTabs(sessionId, session);
|
|
1353
|
-
// A navigation is new content in the pane: the same pop-up an open gets.
|
|
1354
1248
|
if (!session.closing)
|
|
1355
1249
|
this.emit('browser.panel.opened', { sessionId });
|
|
1356
1250
|
}
|
|
@@ -1361,18 +1255,11 @@ export class BrowserViewManager {
|
|
|
1361
1255
|
const previous = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1362
1256
|
if (previous && previous.id !== tabId)
|
|
1363
1257
|
await this.stopScreencast(previous);
|
|
1364
|
-
// Another activation can have taken the pane while this one waited for that
|
|
1365
|
-
// stop: whatever holds the selection now gives up its stream too, or its flag
|
|
1366
|
-
// would keep its next selection from ever starting one. Bounded by a stream
|
|
1367
|
-
// really running, as everywhere else that waits on a stop.
|
|
1368
1258
|
let holding = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1369
1259
|
while (holding && holding.streaming && holding.id !== tabId) {
|
|
1370
1260
|
await this.stopScreencast(holding);
|
|
1371
1261
|
holding = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1372
1262
|
}
|
|
1373
|
-
// The stop yields, so the tab being activated can have closed in that window.
|
|
1374
|
-
// Naming it anyway would strand the pane on an id nothing can address, with
|
|
1375
|
-
// the survivor's stream stopped and every implicit request refused.
|
|
1376
1263
|
if (!session.tabs.has(tabId)) {
|
|
1377
1264
|
const survivor = previous && session.tabs.has(previous.id) ? previous : [...session.tabs.values()][0];
|
|
1378
1265
|
session.activeTabId = survivor?.id;
|
|
@@ -1383,9 +1270,6 @@ export class BrowserViewManager {
|
|
|
1383
1270
|
}
|
|
1384
1271
|
session.activeTabId = tabId;
|
|
1385
1272
|
const tab = session.tabs.get(tabId);
|
|
1386
|
-
// A pane resized while this tab was inactive only sized the active page. The
|
|
1387
|
-
// page is brought to the session's current viewport before it streams, so
|
|
1388
|
-
// input translation and the displayed frame agree on the page's size.
|
|
1389
1273
|
await this.showTab(session, tab);
|
|
1390
1274
|
this.scheduleIdleClose(sessionId, session);
|
|
1391
1275
|
this.publishTabs(sessionId, session);
|
|
@@ -1398,15 +1282,6 @@ export class BrowserViewManager {
|
|
|
1398
1282
|
await this.stopScreencast(tab);
|
|
1399
1283
|
await tab.page.close().catch(() => { });
|
|
1400
1284
|
}
|
|
1401
|
-
/**
|
|
1402
|
-
* Panel geometry: the page viewport and the streamed frame target follow the
|
|
1403
|
-
* pane, or Mobile mode's fixed phone viewport with its emulation.
|
|
1404
|
-
*
|
|
1405
|
-
* The request is remembered even when the session has no browser yet: a panel
|
|
1406
|
-
* mounts and asks for frames before its first tab is opened, and the open
|
|
1407
|
-
* adopts the remembered request. Disabling forgets it, so a collapsed panel
|
|
1408
|
-
* that is later reopened makes a fresh, explicitly desired request.
|
|
1409
|
-
*/
|
|
1410
1285
|
async configureStream(sessionId, options) {
|
|
1411
1286
|
if (!options.enabled) {
|
|
1412
1287
|
this.desired.delete(sessionId);
|
|
@@ -1415,8 +1290,6 @@ export class BrowserViewManager {
|
|
|
1415
1290
|
return;
|
|
1416
1291
|
session.streaming = false;
|
|
1417
1292
|
for (const tab of session.tabs.values()) {
|
|
1418
|
-
// A newer enable took the pane back while this disable was stopping tabs:
|
|
1419
|
-
// its stream stands, and the stops still owed belong to it, not this one.
|
|
1420
1293
|
if (session.streaming)
|
|
1421
1294
|
return;
|
|
1422
1295
|
await this.stopScreencast(tab);
|
|
@@ -1428,8 +1301,6 @@ export class BrowserViewManager {
|
|
|
1428
1301
|
const viewport = mode === 'mobile' ? { ...VIEW_MOBILE_VIEWPORT } : clampViewport(options.viewportWidth, options.viewportHeight);
|
|
1429
1302
|
const quality = Number.isSafeInteger(options.quality) ? Math.max(30, Math.min(90, options.quality)) : VIEW_STREAM_QUALITY;
|
|
1430
1303
|
const scale = clampScale(options.scale);
|
|
1431
|
-
// Only a panel that sends a ratio speaks for the display; an old one that
|
|
1432
|
-
// sends none must not reset what a current one reported.
|
|
1433
1304
|
if (options.scale !== undefined)
|
|
1434
1305
|
this.displayScale = scale;
|
|
1435
1306
|
this.desired.set(sessionId, { viewport, quality, mode, scale });
|
|
@@ -1438,9 +1309,6 @@ export class BrowserViewManager {
|
|
|
1438
1309
|
return;
|
|
1439
1310
|
session.streaming = true;
|
|
1440
1311
|
const modeChanged = mode !== session.mode;
|
|
1441
|
-
// A new display ratio (the window moved to another monitor, or the system
|
|
1442
|
-
// scaling changed) sizes the frames differently, and the screencast bakes
|
|
1443
|
-
// its frame size in at start, so it restarts like a resize does.
|
|
1444
1312
|
const resized = viewport.width !== session.viewport.width || viewport.height !== session.viewport.height
|
|
1445
1313
|
|| scale !== session.scale;
|
|
1446
1314
|
session.mode = mode;
|
|
@@ -1452,14 +1320,8 @@ export class BrowserViewManager {
|
|
|
1452
1320
|
if (!active)
|
|
1453
1321
|
return;
|
|
1454
1322
|
if (resized || modeChanged) {
|
|
1455
|
-
// A new geometry changes every frame's size; the reduced budget belonged to the old one.
|
|
1456
1323
|
active.budget = undefined;
|
|
1457
|
-
// A mode switch is more than a resize: the page is put into or taken out
|
|
1458
|
-
// of the phone's emulation.
|
|
1459
1324
|
await this.queueViewportMode(session, active);
|
|
1460
|
-
// Applying yields, so the selection can have moved by the time it lands:
|
|
1461
|
-
// the tab that lost the pane stops streaming, and the pane's new owner
|
|
1462
|
-
// gets the fresh geometry through the guarded path.
|
|
1463
1325
|
if (session.activeTabId !== active.id) {
|
|
1464
1326
|
await this.stopScreencast(active);
|
|
1465
1327
|
const selected = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
@@ -1467,15 +1329,7 @@ export class BrowserViewManager {
|
|
|
1467
1329
|
await this.showTab(session, selected);
|
|
1468
1330
|
return;
|
|
1469
1331
|
}
|
|
1470
|
-
// The screencast bakes its capture scale in at start: a page resized under
|
|
1471
|
-
// a running stream delivers frames scaled to the old size (verified live —
|
|
1472
|
-
// a 560×800 page after a 390-wide capture arrives 390×557), so the stream
|
|
1473
|
-
// restarts to pick up the new geometry. The pane holds its last painted
|
|
1474
|
-
// frame through the gap, so the UI never blanks while it happens.
|
|
1475
1332
|
await this.stopScreencast(active);
|
|
1476
|
-
// The stop yields, so the selection can have moved by the time it lands:
|
|
1477
|
-
// restarting this tab would stream one nobody sees while leaving its flag
|
|
1478
|
-
// on, and the pane's new owner would wait for frames that never come.
|
|
1479
1333
|
if (session.activeTabId !== active.id) {
|
|
1480
1334
|
const selected = session.activeTabId ? session.tabs.get(session.activeTabId) : undefined;
|
|
1481
1335
|
if (selected)
|
|
@@ -1485,16 +1339,9 @@ export class BrowserViewManager {
|
|
|
1485
1339
|
}
|
|
1486
1340
|
const reattached = active.streaming;
|
|
1487
1341
|
await this.startScreencast(session, active);
|
|
1488
|
-
// A stream that was already running sends nothing more for a page that is
|
|
1489
|
-
// not repainting, so a pane that returned (renderer reload) would have no
|
|
1490
|
-
// image; asking for one now makes the resumed panel show the page as it is.
|
|
1491
1342
|
if (reattached)
|
|
1492
1343
|
await this.captureFrame(sessionId, session, active);
|
|
1493
1344
|
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Panel input, translated from image pixels to page CSS pixels and forwarded
|
|
1496
|
-
* as CDP input events. The panel never holds a CDP connection of its own.
|
|
1497
|
-
*/
|
|
1498
1345
|
async input(sessionId, payload) {
|
|
1499
1346
|
const session = this.sessions.get(sessionId);
|
|
1500
1347
|
if (!session)
|
|
@@ -1518,8 +1365,6 @@ export class BrowserViewManager {
|
|
|
1518
1365
|
const type = payload.type;
|
|
1519
1366
|
if (type === 'move') {
|
|
1520
1367
|
const at = point();
|
|
1521
|
-
// A held button during a drag: the mask is what makes the page treat the
|
|
1522
|
-
// movement as dragging rather than hovering.
|
|
1523
1368
|
const pressed = payload.pressed === true;
|
|
1524
1369
|
const name = pressed ? button(payload.button) : 'none';
|
|
1525
1370
|
const buttons = pressed ? (name === 'right' ? 2 : name === 'middle' ? 4 : 1) : 0;
|
|
@@ -1550,11 +1395,7 @@ export class BrowserViewManager {
|
|
|
1550
1395
|
else if (type === 'key') {
|
|
1551
1396
|
const down = payload.down === true;
|
|
1552
1397
|
const descriptor = keyDescriptor(String(payload.key ?? ''), typeof payload.code === 'string' ? payload.code : undefined, modifiers);
|
|
1553
|
-
// The character a key inserts belongs to the key-down; a key-up carries
|
|
1554
|
-
// none, so the page does not see the text twice.
|
|
1555
1398
|
const text = down ? descriptor.text : undefined;
|
|
1556
|
-
// A macOS browser performs its editing gestures as named commands on the
|
|
1557
|
-
// key-down, not from the key event itself; see `macEditingCommands`.
|
|
1558
1399
|
const commands = process.platform === 'darwin' && down ? macEditingCommands(descriptor.key, modifiers) : [];
|
|
1559
1400
|
await tab.cdp.send('Input.dispatchKeyEvent', {
|
|
1560
1401
|
type: down ? (text === undefined ? 'rawKeyDown' : 'keyDown') : 'keyUp',
|
|
@@ -1574,13 +1415,6 @@ export class BrowserViewManager {
|
|
|
1574
1415
|
throw new Error('Unsupported browser input type');
|
|
1575
1416
|
}
|
|
1576
1417
|
}
|
|
1577
|
-
/**
|
|
1578
|
-
* The cursor shape the page would show at a pane point, in image pixels.
|
|
1579
|
-
*
|
|
1580
|
-
* The pane draws frames and forwards input, so the page's own pointer is never
|
|
1581
|
-
* visible: a link must still read as a link. The answer is the page's computed
|
|
1582
|
-
* `cursor` at that point, bounded and lower-cased for the panel to draw.
|
|
1583
|
-
*/
|
|
1584
1418
|
async cursorAt(sessionId, x, y, tabId) {
|
|
1585
1419
|
const session = this.sessions.get(sessionId);
|
|
1586
1420
|
if (!session)
|
|
@@ -1589,7 +1423,6 @@ export class BrowserViewManager {
|
|
|
1589
1423
|
this.scheduleIdleClose(sessionId, session);
|
|
1590
1424
|
const px = Number(x);
|
|
1591
1425
|
const py = Number(y);
|
|
1592
|
-
// A point outside the frame the pane is showing names nothing in the page.
|
|
1593
1426
|
if (!Number.isSafeInteger(px) || !Number.isSafeInteger(py) || px < 0 || py < 0 || px > tab.imageWidth || py > tab.imageHeight)
|
|
1594
1427
|
return 'default';
|
|
1595
1428
|
const scaleX = tab.imageWidth / Math.max(1, session.viewport.width);
|
|
@@ -1598,15 +1431,6 @@ export class BrowserViewManager {
|
|
|
1598
1431
|
.catch(() => 'default');
|
|
1599
1432
|
return typeof cursor === 'string' && /^[a-z-]{1,40}$/.test(cursor) ? cursor : 'default';
|
|
1600
1433
|
}
|
|
1601
|
-
/**
|
|
1602
|
-
* The text a copy or cut would take from the page, for the viewer's clipboard.
|
|
1603
|
-
*
|
|
1604
|
-
* Copy and cut travel to the page as key events, so the text they produce stays
|
|
1605
|
-
* in the browser that owns the page. The viewer reads it back here and writes
|
|
1606
|
-
* it to its own clipboard, which is what makes a copy on a paired machine land
|
|
1607
|
-
* on the machine the user is sitting at. The viewer reads before it forwards
|
|
1608
|
-
* the key: a cut collapses the selection it just removed.
|
|
1609
|
-
*/
|
|
1610
1434
|
async selectionText(sessionId, tabId) {
|
|
1611
1435
|
const session = this.sessions.get(sessionId);
|
|
1612
1436
|
if (!session)
|
|
@@ -1614,29 +1438,16 @@ export class BrowserViewManager {
|
|
|
1614
1438
|
const tab = this.activeOrNamed(session, tabId);
|
|
1615
1439
|
this.scheduleIdleClose(sessionId, session);
|
|
1616
1440
|
const text = await this.selectionInPage(tab.page);
|
|
1617
|
-
// A selection past the bound is refused rather than truncated: the viewer
|
|
1618
|
-
// writes what it read and then forwards the key, and a cut removes the whole
|
|
1619
|
-
// selection from the page — a prefix on the clipboard would lose the rest.
|
|
1620
1441
|
if (typeof text !== 'string')
|
|
1621
1442
|
return '';
|
|
1622
1443
|
if (text.length > VIEW_CLIPBOARD_LIMIT)
|
|
1623
1444
|
throw new Error(`The selection is too large to copy (${text.length} characters)`);
|
|
1624
1445
|
return text;
|
|
1625
1446
|
}
|
|
1626
|
-
/**
|
|
1627
|
-
* The focused document's selection, including one made inside a frame.
|
|
1628
|
-
*
|
|
1629
|
-
* The top document is asked first, and it says when focus is inside a frame:
|
|
1630
|
-
* there the iframe element is the active element and the top selection is
|
|
1631
|
-
* empty, so each frame is asked in turn. Playwright evaluates inside a
|
|
1632
|
-
* cross-origin frame as well, because the evaluation runs over CDP rather than
|
|
1633
|
-
* through the page's own script context.
|
|
1634
|
-
*/
|
|
1635
1447
|
async selectionInPage(page) {
|
|
1636
1448
|
const top = await page.evaluate(SELECTION_STATE).catch(() => undefined);
|
|
1637
1449
|
if (typeof top?.text === 'string' && top.text)
|
|
1638
1450
|
return top.text;
|
|
1639
|
-
// The top document answered "no selection and focus is mine": no frame holds it.
|
|
1640
1451
|
if (top?.inFrame === false)
|
|
1641
1452
|
return '';
|
|
1642
1453
|
let frames = [];
|
|
@@ -1647,10 +1458,6 @@ export class BrowserViewManager {
|
|
|
1647
1458
|
catch {
|
|
1648
1459
|
return '';
|
|
1649
1460
|
}
|
|
1650
|
-
// A frame keeps its selection after focus moves elsewhere, so an unfocused
|
|
1651
|
-
// frame's text is not the user's. Only the focused document's selection is
|
|
1652
|
-
// the answer, even an empty one; a focused frame whose own active element is
|
|
1653
|
-
// another iframe is a step on the way to a deeper frame, not the caret itself.
|
|
1654
1461
|
let fallback = '';
|
|
1655
1462
|
let focusedAnswered = false;
|
|
1656
1463
|
for (const frame of frames) {
|
|
@@ -1665,16 +1472,8 @@ export class BrowserViewManager {
|
|
|
1665
1472
|
if (!fallback && text)
|
|
1666
1473
|
fallback = text;
|
|
1667
1474
|
}
|
|
1668
|
-
// The focus is deeper than the frames readable here: their stale text is not it.
|
|
1669
1475
|
return focusedAnswered ? '' : fallback;
|
|
1670
1476
|
}
|
|
1671
|
-
/**
|
|
1672
|
-
* Agent operations on the session's panel browser.
|
|
1673
|
-
*
|
|
1674
|
-
* The panel browser belongs to the user as much as to the agent: an operation
|
|
1675
|
-
* that fails, stalls or is cancelled ends only that call — never the browser —
|
|
1676
|
-
* and tab-affecting operations publish tabs so the pane follows along.
|
|
1677
|
-
*/
|
|
1678
1477
|
async boundedAgentOperation(signal, pending, timeoutMessage) {
|
|
1679
1478
|
return await new Promise((resolve, reject) => {
|
|
1680
1479
|
let settled = false;
|
|
@@ -1700,11 +1499,9 @@ export class BrowserViewManager {
|
|
|
1700
1499
|
this.scheduleIdleClose(sessionId, session);
|
|
1701
1500
|
return { session, tab: this.activeOrNamed(session, tabId) };
|
|
1702
1501
|
}
|
|
1703
|
-
/** The session's tabs as the agent sees them; a panel with no browser yet is simply empty. */
|
|
1704
1502
|
agentTabs(sessionId) {
|
|
1705
1503
|
return this.sessionSummaries()[sessionId] ?? { tabs: [] };
|
|
1706
1504
|
}
|
|
1707
|
-
/** Step a tab through its history or reload it, for the agent and the panel's toolbar alike. */
|
|
1708
1505
|
async go(sessionId, kind, tabId) {
|
|
1709
1506
|
const { session, tab } = this.agentTarget(sessionId, tabId);
|
|
1710
1507
|
if (kind === 'back')
|
|
@@ -1731,9 +1528,6 @@ export class BrowserViewManager {
|
|
|
1731
1528
|
}
|
|
1732
1529
|
async agentPress(sessionId, options, signal) {
|
|
1733
1530
|
const { tab } = this.agentTarget(sessionId, options.tabId);
|
|
1734
|
-
// The keypress belongs to this call alone: a focus that resolves after the call
|
|
1735
|
-
// was cancelled or timed out must not dispatch into the shared browser, where it
|
|
1736
|
-
// could submit a form nobody is driving anymore.
|
|
1737
1531
|
let callerGone = false;
|
|
1738
1532
|
const sequence = (async () => {
|
|
1739
1533
|
if (options.selector)
|
|
@@ -1759,11 +1553,6 @@ export class BrowserViewManager {
|
|
|
1759
1553
|
}
|
|
1760
1554
|
async agentScreenshot(sessionId, tabId, signal) {
|
|
1761
1555
|
const { session, tab } = this.agentTarget(sessionId, tabId);
|
|
1762
|
-
// The agent reads this image against the CSS-pixel size returned with it, but
|
|
1763
|
-
// the page renders at the browser's launch factor (or Mobile's 3×). That ratio
|
|
1764
|
-
// is applied over this manager's own CDP session, so Playwright still believes
|
|
1765
|
-
// the page is 1×, and its `scale: 'css'` would return device pixels; the
|
|
1766
|
-
// capture is made here instead, scaled down by the ratio actually in effect.
|
|
1767
1556
|
const ratio = tab.emulated ? VIEW_MOBILE_SCALE : session.renderScale;
|
|
1768
1557
|
const capture = (async () => {
|
|
1769
1558
|
const metrics = await tab.cdp.send('Page.getLayoutMetrics').catch(() => undefined);
|
|
@@ -1771,10 +1560,6 @@ export class BrowserViewManager {
|
|
|
1771
1560
|
const clip = visual && Number.isFinite(visual.clientWidth) && visual.clientWidth > 0
|
|
1772
1561
|
? { x: visual.pageX, y: visual.pageY, width: visual.clientWidth, height: visual.clientHeight }
|
|
1773
1562
|
: { x: 0, y: 0, width: session.viewport.width, height: session.viewport.height };
|
|
1774
|
-
// A Mobile page without a meta viewport lays out at ~980 CSS px and the
|
|
1775
|
-
// phone shows it zoomed out to its 390: the visual viewport's scale (0.398
|
|
1776
|
-
// there, measured) is what brings that wider clip back to the size the
|
|
1777
|
-
// agent is told.
|
|
1778
1563
|
const zoom = visual && Number.isFinite(visual.scale) && visual.scale > 0 ? visual.scale : 1;
|
|
1779
1564
|
const shot = await tab.cdp.send('Page.captureScreenshot', { format: 'jpeg', quality: 60, clip: { ...clip, scale: zoom / ratio } });
|
|
1780
1565
|
if (typeof shot?.data !== 'string')
|
|
@@ -1788,12 +1573,8 @@ export class BrowserViewManager {
|
|
|
1788
1573
|
const session = this.sessions.get(sessionId);
|
|
1789
1574
|
if (!session || session.closing)
|
|
1790
1575
|
return;
|
|
1791
|
-
// A teardown that started for an older generation must not close the
|
|
1792
|
-
// replacement that took its id in the meantime.
|
|
1793
1576
|
if (expected !== undefined && session !== expected)
|
|
1794
1577
|
return;
|
|
1795
|
-
// Incognito lasts exactly as long as its browser: once it closes, the next
|
|
1796
|
-
// open returns to the project profile.
|
|
1797
1578
|
if (session.profile === 'incognito')
|
|
1798
1579
|
this.incognito.delete(sessionId);
|
|
1799
1580
|
session.closing = (async () => {
|
|
@@ -1801,11 +1582,7 @@ export class BrowserViewManager {
|
|
|
1801
1582
|
if (session.idleTimer)
|
|
1802
1583
|
clearTimeout(session.idleTimer);
|
|
1803
1584
|
await Promise.all([...session.tabs.values()].map(tab => this.stopScreencast(tab)));
|
|
1804
|
-
// A shared project profile loses only this session's pages; the profile
|
|
1805
|
-
// itself closes when its last session leaves.
|
|
1806
1585
|
await this.disposeBrowser(session);
|
|
1807
|
-
// A new browser may already hold this session id; its pane has content of
|
|
1808
|
-
// its own, so the old generation stays silent.
|
|
1809
1586
|
if (this.sessions.has(sessionId))
|
|
1810
1587
|
return;
|
|
1811
1588
|
this.emit('browser.view', { kind: 'gone', sessionId, ...(reason ? { reason } : {}) });
|
|
@@ -1819,16 +1596,29 @@ export class BrowserViewManager {
|
|
|
1819
1596
|
return result;
|
|
1820
1597
|
}
|
|
1821
1598
|
/**
|
|
1822
|
-
*
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1826
|
-
* minutes for a pane nobody can open.
|
|
1599
|
+
* Close the panel browsers of sessions whose project identity just changed. A profile is chosen once, when the
|
|
1600
|
+
* browser is created, so a task merged into another project would keep browsing on the cookies and logins of the
|
|
1601
|
+
* folder it left. Closing it here costs the open tabs of that one task; the next use opens it on the surviving
|
|
1602
|
+
* project's profile.
|
|
1827
1603
|
*/
|
|
1604
|
+
async rekeyProfiles(sessionIds) {
|
|
1605
|
+
const ids = [...sessionIds];
|
|
1606
|
+
if (ids.length === 0)
|
|
1607
|
+
return;
|
|
1608
|
+
await Promise.all(ids.map(async (id) => await this.launching.get(id)?.catch(() => { })));
|
|
1609
|
+
for (const id of ids) {
|
|
1610
|
+
// An incognito panel browser carries no project state, so there is nothing stale about leaving it open.
|
|
1611
|
+
const session = this.sessions.get(id);
|
|
1612
|
+
if (session === undefined || session.profile === 'incognito')
|
|
1613
|
+
continue;
|
|
1614
|
+
await this.closeSession(id, 'project changed');
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1828
1617
|
async release(sessionId, reason) {
|
|
1829
|
-
// Marked before the close, so a launch finishing in between still sees the
|
|
1830
|
-
// release; the marker is dropped once no launch can still be holding it.
|
|
1831
1618
|
this.released.add(sessionId);
|
|
1619
|
+
const restoring = this.restoring.get(sessionId);
|
|
1620
|
+
if (restoring)
|
|
1621
|
+
restoring.cancelled = true;
|
|
1832
1622
|
this.incognito.delete(sessionId);
|
|
1833
1623
|
try {
|
|
1834
1624
|
await this.closeSession(sessionId, reason);
|
|
@@ -1838,27 +1628,25 @@ export class BrowserViewManager {
|
|
|
1838
1628
|
this.released.delete(sessionId);
|
|
1839
1629
|
}
|
|
1840
1630
|
}
|
|
1841
|
-
/** Engine shutdown: no panel browser outlives the process. */
|
|
1842
1631
|
async close() {
|
|
1843
1632
|
if (this.closed)
|
|
1844
1633
|
return;
|
|
1845
1634
|
this.closed = true;
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1635
|
+
if (this.restartPoll) {
|
|
1636
|
+
clearTimeout(this.restartPoll);
|
|
1637
|
+
this.restartPoll = undefined;
|
|
1638
|
+
}
|
|
1639
|
+
this.pendingRestart.clear();
|
|
1849
1640
|
if (this.installer) {
|
|
1850
1641
|
const { child, finish } = this.installer;
|
|
1851
1642
|
try {
|
|
1852
1643
|
child.kill();
|
|
1853
1644
|
}
|
|
1854
|
-
catch {
|
|
1645
|
+
catch { }
|
|
1855
1646
|
const stopped = { state: 'failed', detail: 'Application is shutting down' };
|
|
1856
1647
|
this.publishRuntime(stopped);
|
|
1857
1648
|
finish(stopped);
|
|
1858
1649
|
}
|
|
1859
|
-
// A launch already in flight is awaited before the last sweep: it inserts its
|
|
1860
|
-
// session while this loop is running, and a browser nobody then visits would
|
|
1861
|
-
// outlive the engine. The wait is bounded because a launch may never settle.
|
|
1862
1650
|
const pending = [...this.launching.values()];
|
|
1863
1651
|
if (pending.length) {
|
|
1864
1652
|
await Promise.race([
|
|
@@ -1867,6 +1655,5 @@ export class BrowserViewManager {
|
|
|
1867
1655
|
]);
|
|
1868
1656
|
}
|
|
1869
1657
|
await Promise.all([...this.sessions.keys()].map(sessionId => this.closeSession(sessionId)));
|
|
1870
|
-
// A launch that landed after the bound closed itself in `ensureSession`.
|
|
1871
1658
|
}
|
|
1872
1659
|
}
|