Skip to content

WIP: Add tracked browser logs and network capture#16310

Draft
davidfowl wants to merge 5 commits intomainfrom
spike/browser-console-logs-poc
Draft

WIP: Add tracked browser logs and network capture#16310
davidfowl wants to merge 5 commits intomainfrom
spike/browser-console-logs-poc

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

@davidfowl davidfowl commented Apr 19, 2026

Description

Adds WithBrowserLogs(...) to Aspire.Hosting so browser-capable resources can attach a child *-browser-logs resource that opens tracked Chromium sessions and streams browser activity back into the dashboard log stream.

This draft includes:

  • the child browser-logs resource and tracked-browser command;
  • multi-session tracking with unique session IDs plus aggregated dashboard properties and health;
  • browser console, error, and exception capture;
  • browser network request lifecycle capture from Chromium CDP Network.* events;
  • explicit connection diagnostics for setup failures, disconnects, reconnect attempts, and reconnect exhaustion;
  • AspireExport support so withBrowserLogs(...) is emitted in the polyglot AppHost generators while the child resource remains excluded from manifest publishing;
  • a runtime split so orchestration, per-browser lifecycle, websocket transport, and event projection can be tested independently.

Browser connection architecture

Ignoring the Aspire-specific resource wiring, the browser side is a small Chromium DevTools Protocol client:

  1. Launch Chromium with a fresh user-data dir and --remote-debugging-port=0.
  2. Wait for the DevToolsActivePort file to discover the actual debug endpoint.
  3. Connect the browser websocket transport.
  4. Create and attach to a target session.
  5. Enable the Runtime, Log, Page, and Network domains.
  6. Navigate to the requested URL.
  7. Project console, error, exception, and request lifecycle events into log lines.
  8. Reconnect to the existing target on transient disconnects, or tear the session down if recovery fails.

Internally those responsibilities are now split across BrowserLogsSessionManager, BrowserLogsRunningSession, ChromeDevToolsConnection, BrowserLogsProtocol, BrowserEventLogger, and BrowserConnectionDiagnosticsLogger.

Validation

Validation included targeted Aspire.Hosting.Tests coverage for resource wiring, session behavior, protocol parsing, request formatting, and diagnostics logging, focused ATS/codegen coverage for the exported capability, and live playground/BrowserTelemetry runs confirming real [network.*] and browser log lines in web-browser-logs via aspire resource web-browser-logs open-tracked-browser.

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 19, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16310

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16310"

Add a child browser logs resource that can launch tracked Chromium sessions, stream console and network request events, and expose the builder through polyglot export.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl davidfowl force-pushed the spike/browser-console-logs-poc branch from 5c31105 to eab2c02 Compare April 19, 2026 17:36
@davidfowl davidfowl changed the title Add tracked browser logs and network capture WIP: Add tracked browser logs and network capture Apr 19, 2026
Add typed CDP protocol parsing, preserve connection failure reasons in resource logs, and strengthen reconnect handling for tracked browser sessions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found (1 security, 2 bugs, 1 race condition, 1 formatting).

"--no-default-browser-check",
"--new-window",
"--allow-insecure-localhost",
"--ignore-certificate-errors",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--allow-insecure-localhost on line 1035 already covers the local development use case. Adding --ignore-certificate-errors additionally disables certificate validation for all sites in the tracked browser, which could expose users to MITM attacks if they navigate away from localhost. Consider removing this flag.

Comment thread src/Aspire.Hosting/BrowserLogsSessionManager.cs Outdated
Comment thread src/Aspire.Hosting/BrowserLogsSessionManager.cs Outdated

foreach (var (_, resourceState) in _resourceStates)
{
resourceState.Lock.Dispose();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisposeAsync stops all sessions (line 192-195) then disposes all Lock instances here. However, StartCompletionObserver (line 153) launches a fire-and-forget ObserveCompletionAsync that calls HandleSessionCompletedAsync, which acquires this Lock (line 211). After session.StopAsync() returns, the observer's continuation may still be pending, causing an ObjectDisposedException here. While the ObserveCompletionAsync catch block (line 1246) swallows it, this race could mask real errors.

Comment thread src/Aspire.Hosting/BrowserLogsBuilderExtensions.cs Outdated
mitchdenny and others added 3 commits April 20, 2026 09:24
Fix indentation of <remarks> block in BrowserLogsBuilderExtensions.cs to
match surrounding XML doc tags.

Thread TimeProvider through RunningSession and its factory so timeout
calculations in WaitForBrowserEndpointAsync and TryReconnectAsync use the
injected provider instead of TimeProvider.System/DateTime.UtcNow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract the running-session lifecycle, CDP websocket transport, and event/diagnostic logging into focused files so the browser connection layers can be tested in isolation. Also add targeted comments describing the browser and CDP quirks these layers handle.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the global certificate-bypass flag from tracked browser launches and make session-manager disposal wait for completion observers without publishing shutdown updates through torn-down services.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 72 recordings uploaded (commit 3fefe17)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24642063830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants