.NET Selenium (C#)

Browserless now supports the .NET Selenium library provided by OpenQA! Similar to all our selenium integrations, you can specify your authorization token by specifying an additional capability of browserless:token. Note that this is not a capability that Chrome understands natively, and will throw an error, so you must specify true as your 3rd argument.

Here's a full example:

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Chrome;

namespace BrowserlessSelenium
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver;
            ChromeOptions options = new ChromeOptions();

            // Set launch args similar to puppeteer's for best performance
            options.AddArgument("--disable-background-timer-throttling");
            options.AddArgument("--disable-backgrounding-occluded-windows");
            options.AddArgument("--disable-breakpad");
            options.AddArgument("--disable-component-extensions-with-background-pages");
            options.AddArgument("--disable-dev-shm-usage");
            options.AddArgument("--disable-extensions");
            options.AddArgument("--disable-features=TranslateUI,BlinkGenPropertyTrees");
            options.AddArgument("--disable-ipc-flooding-protection");
            options.AddArgument("--disable-renderer-backgrounding");
            options.AddArgument("--enable-features=NetworkService,NetworkServiceInProcess");
            options.AddArgument("--force-color-profile=srgb");
            options.AddArgument("--hide-scrollbars");
            options.AddArgument("--metrics-recording-only");
            options.AddArgument("--mute-audio");
            options.AddArgument("--headless");
            options.AddArgument("--no-sandbox");

            // Note we set our token here, with `true` as a third arg
            options.AddAdditionalOption("browserless:token", "YOUR-API-TOKEN");

            driver = new RemoteWebDriver(
              new Uri("https://chrome.browserless.io/webdriver"), options.ToCapabilities()
            );

            driver.Navigate().GoToUrl("https://example.com");
            Console.WriteLine(driver.Title);

            // Always call `quit` to ensure your session cleans up properly and you're not charged for unused time
            driver.Quit();
        }
    }
}

This will simply log out the Title from the Example website, however it'll give you a great starting place for using .NET alongside browserless.

Be sure to let us know if you have questions or issues.

Ready to try benefits of Browserless?