C# headless browser automation without requiring browser installation

I need to create automated web interactions in my C# application that can handle JavaScript execution, locate elements using XPath selectors, and simulate user actions like clicking and typing. The main challenge is that I want to distribute this as a standalone executable without forcing users to install additional browsers or drivers.

I’ve explored Selenium which works great for automation tasks, but it needs Chrome or Firefox to be installed on the target machine for headless operation. I also checked out CefSharp which bundles the browser engine directly into the app, but it lacks advanced element selection capabilities and doesn’t offer the same level of functionality as Selenium.

What I’m looking for: Are there any C# libraries or frameworks that provide comprehensive headless browser automation (similar to Selenium’s features) while being completely self-contained? I want to ship a single executable that doesn’t depend on external browser installations.

Selenium Grid with dockerized Chrome is probably overkill, but I’ve seen teams bundle portable Chrome builds directly. Playwright-dotnet is another option - it handles browser binaries automatically. Just set PLAYWRIGHT_BROWSERS_PATH to ship browsers with your exe. It’s heavier than PuppeteerSharp but has solid XPath support and better debugging tools.

Try HtmlAgilityPack with a custom WebView2 setup. WebView2 runs headless and comes built into Windows 10/11, so you won’t hit browser dependency issues with most users. Just create a borderless WebView2 control that handles JavaScript and user interactions invisibly. Element selection’s the tricky bit, but you can inject custom JavaScript for XPath queries and event simulation. I built a data scraping tool this way last year - worked great for basic automation. Kept the executable small since WebView2’s already on target machines. Only downsides: Windows-only, and older systems need WebView2 runtime installed separately.

I had the same problem when building an app that needed to automate web stuff. PuppeteerSharp worked great since it lets you bundle a portable Chromium version. Sure, PuppeteerSharp usually downloads Chromium on its own, but you can manually pack a Chromium version with your app. Just set the ExecutablePath in your config and your app runs standalone - users don’t need to install any browsers. The only catch is file size - mine was around 200MB because of the Chromium binaries. But users just extract and run, so it’s pretty smooth overall.