This example shows how to give an AI assistant in a WPF application a browser
that stays within the limits the application sets. The assistant, Claude,
drives a visible BrowserView while the user watches. The application enforces
the limits in-process through DotNetBrowser handlers, independently of the
model:
- a site allowlist with read-only and read-write sites, covering redirects, frames, and the requests a page loads;
- no downloads, pop-ups, printing, file dialogs, external apps, or permissions;
- human input suppressed while the assistant acts, with Take over and Hand back buttons;
- no typing into password fields: the assistant hands the page to the user to sign in;
- a dialog that shows the exact form data before anything is submitted;
- an audit log of navigations, blocked actions, tool calls, and token usage;
- an incognito profile, so nothing is inherited or kept.
The demo runs against a mock supplier portal served from the application's resources, so the scenario is the same on every machine.
The tutorial is available on the DotNetBrowser blog.
- .NET 8 SDK
- Windows 10 or later
- A DotNetBrowser license key
- An Anthropic API key
GuardedBrowseris a class library with no UI and no model code:BrowserPolicy.csholds the allowed sites and schemes.PolicyEnforcer.cssets the navigation, network, download, pop-up, permission, print, and dialog handlers.InputGate.csdecides whether the user or the assistant holds the keyboard and mouse.SubmitGuard.cscancels form submissions the user has not approved.PageSnapshot.csandsnapshot.jsdescribe the page as a numbered list of interactive elements.BrowserActions.csperforms the assistant's actions with simulated input.AuditLog.csrecords what happens.
AssistantAgentis a class library that connects Claude through the Anthropic C# SDK:BrowserTools.csdefines the tools the model can call.AssistantSession.csruns the tool loop, pauses while the user holds the page, and asks for approval before a form is submitted.SystemPrompt.mdtells the model about the limits.
AgentBrowser.Wpfis the application:MainWindow.xamlshows the browser, the task box, the buttons, and the audit log.ApprovalDialog.xamlshows what the assistant wants to submit.Portal/contains the mock supplier portal and the scheme handler that serves it atdnb://portal/.
Put your DotNetBrowser license key into the dotnetbrowser.license file in the
root directory of this repository. The build copies it to the output directory
of the application.
The Anthropic SDK reads the key from the ANTHROPIC_API_KEY environment
variable. Set it in the terminal you run the example from, or in the run
configuration of your IDE:
$env:ANTHROPIC_API_KEY = "<your_api_key>"From this directory:
dotnet run --project AgentBrowser.WpfOr open AgentBrowser.sln in your IDE and run AgentBrowser.Wpf.
Click Run to start the task shown in the task box. When the assistant
reaches the sign-in page, it hands the page over: sign in with user name
demo and password demo, then click Hand back. Before the order is
placed, the approval dialog shows the form data; click Submit to send it.