{ "id": "csharp/aspire.hosting.browsers/browserlogsbuilderextensions/methods#withbrowserlogs", "name": "WithBrowserLogs(IResourceBuilder, string?, string?, BrowserUserDataMode?)", "language": "csharp", "kind": "member", "url": "https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browserlogsbuilderextensions/methods#withbrowserlogs-iresourcebuilder-t-string-string-browseruserdatamode", "parentId": "csharp/aspire.hosting.browsers/browserlogsbuilderextensions/methods", "memberGroup": "methods", "content": "# BrowserLogsBuilderExtensions Methods\n\n- Package: [Aspire.Hosting.Browsers](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers.md)\n- Type: [BrowserLogsBuilderExtensions](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browserlogsbuilderextensions.md)\n- Kind: `Methods`\n- Members: `1`\n\nExtension methods for adding tracked browser log resources to browser-based application resources.\n\n\n\n\n## WithBrowserLogs(IResourceBuilder, string?, string?, BrowserUserDataMode?)\n\n> **Experimental:** ASPIREBROWSERLOGS001 - [Learn more](https://aspire.dev/diagnostics/aspirebrowserlogs001/)\n\n- Name: `WithBrowserLogs(IResourceBuilder, string?, string?, BrowserUserDataMode?)`\n- Modifiers: `extension`\n- Returns: `IResourceBuilder`\n- Source: [GitHub](https://github.com/microsoft/aspire/blob/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62/src/Aspire.Hosting.Browsers/BrowserLogsBuilderExtensions.cs#L122-L289)\n\nAdds a child resource that can open the application's primary browser endpoint in a tracked browser session, surface browser diagnostics, and capture screenshots.\n\n```csharp\npublic static class BrowserLogsBuilderExtensions\n{\n public static IResourceBuilder WithBrowserLogs(\n this IResourceBuilder builder,\n string? browser = null,\n string? profile = null,\n BrowserUserDataMode? userDataMode = null)\n {\n // ...\n }\n}\n```\n\n## Parameters\n\n- `builder` (`IResourceBuilder`)\n The resource builder.\n- `browser` (`string?`) `optional`\n The browser to launch. When not specified, the tracked browser uses the configured value from `Aspire:Hosting:BrowserLogs` and otherwise prefers an installed `\"msedge\"` browser in shared user data mode, an installed `\"chrome\"` browser in isolated user data mode, and finally falls back to `\"chrome\"`. Supported values include logical browser names such as `\"msedge\"` and `\"chrome\"`, or an explicit browser executable path.\n- `profile` (`string?`) `optional`\n Optional Chromium profile name or directory name to use. Only valid when the effective user data mode is [BrowserUserDataMode.Shared](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browseruserdatamode/fields.md). When not specified, the tracked browser uses the configured value from `Aspire:Hosting:BrowserLogs` if present.\n- `userDataMode` ([BrowserUserDataMode?](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browseruserdatamode.md)) `optional`\n Optional [BrowserUserDataMode](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browseruserdatamode.md) that selects whether the tracked browser launches against a persistent Aspire-managed user data directory shared across all AppHosts on the machine ( [BrowserUserDataMode.Shared](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browseruserdatamode/fields.md), the default) or a per-AppHost persistent user data directory ( [BrowserUserDataMode.Isolated](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browseruserdatamode/fields.md)). Both modes use Aspire-managed paths under `%LocalAppData%\\Aspire\\BrowserData` on Windows (or platform equivalents); the user's normal browser profile is never used. When not specified, the tracked browser uses the configured value from `Aspire:Hosting:BrowserLogs` and otherwise defaults to [BrowserUserDataMode.Shared](https://aspire.dev/reference/api/csharp/aspire.hosting.browsers/browseruserdatamode/fields.md).\n\n## Returns\n\n`IResourceBuilder` -- A reference to the original `ApplicationModel.IResourceBuilder`1` for further chaining.\n\n## Remarks\n\nThis method adds a child browser logs resource beneath the parent resource represented by `builder`. The child resource exposes a dashboard command that launches a Chromium-based browser in a tracked mode, attaches to the browser's debugging protocol, forwards browser console, error, exception, and network output to the child resource's console log stream, and can capture screenshots as command artifacts.\n\nThe tracked browser session uses the [Chrome DevTools Protocol (CDP)](https://chromedevtools.github.io/devtools-protocol/) to subscribe to browser runtime, log, page, and network events.\n\nThe parent resource must expose at least one HTTP or HTTPS endpoint. HTTPS endpoints are preferred over HTTP endpoints when selecting the browser target URL.\n\nBrowser, profile, and user data mode settings can also be supplied from configuration using `Aspire:Hosting:BrowserLogs:Browser`, `Aspire:Hosting:BrowserLogs:Profile`, and `Aspire:Hosting:BrowserLogs:UserDataMode`, or scoped to a specific resource with `Aspire:Hosting:BrowserLogs:{ResourceName}:Browser`, `Aspire:Hosting:BrowserLogs:{ResourceName}:Profile`, and `Aspire:Hosting:BrowserLogs:{ResourceName}:UserDataMode`. Explicit method arguments override configuration.\n\n## Examples\n\nAdd tracked browser logs for a web front end:\n\n```csharp\nvar builder = DistributedApplication.CreateBuilder(args);\n\nbuilder.AddProject(\"web\")\n .WithExternalHttpEndpoints()\n .WithBrowserLogs();\n```\n\n## ATS metadata\n\n### ATS export\n\n- Available to Polyglot AppHosts through the Aspire Type System.\n" }