# WithBrowserLogs

- Module: [Aspire.Hosting.Browsers](/reference/api/go/aspire.hosting.browsers.md)
- Version: `17.0.0-preview.1.26567.5`
- Kind: `method`
- Defined on: `ResourceWithEndpoints`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Adds a child resource that can open the application's primary browser endpoint in a tracked browser session, surface browser diagnostics, and capture screenshots.

## Remarks

This 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.
The tracked browser session uses the Chrome DevTools
Protocol (CDP) to subscribe to browser runtime, log, page, and network events.
The parent resource must expose at least one HTTP or HTTPS endpoint. HTTPS endpoints are preferred over HTTP
endpoints when selecting the browser target URL.
Browser, 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.

## Definition

```go
func (ResourceWithEndpoints) WithBrowserLogs(options ...*WithBrowserLogsOptions) ResourceWithEndpoints
```

## Parameters

- `options` (`...*WithBrowserLogsOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithBrowserLogsOptions` argument.

- `Browser` (`*string`) -- 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.
- `Profile` (`*string`) -- Optional Chromium profile name or directory name to use. Only valid when the effective user data mode is `Shared`. When not specified, the tracked browser uses the configured value from `Aspire:Hosting:BrowserLogs` if present.
- `UserDataMode` ([`*BrowserUserDataMode`](/reference/api/go/aspire.hosting.browsers/browseruserdatamode.md)) -- Optional `BrowserUserDataMode` that selects whether the tracked browser launches against a persistent Aspire-managed user data directory shared across all AppHosts on the machine (`Shared`, the default) or a per-AppHost persistent user data directory (`Isolated`). 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 `Shared`.

## Returns

`ResourceWithEndpoints` -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- `CSharpAppResource`
- `ContainerResource`
- `DotnetToolResource`
- `ExecutableResource`
- `ProjectResource`
