> For the complete documentation index, see [llms.txt](https://cloudbrowser.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cloudbrowser.gitbook.io/docs/libraries/.net-client/open.md).

# Open

The following example demonstrates how to request a browser instance, navigate to a webpage, and close the browser:

```csharp
using BrowserService svc = new("YOUR CLOUDBROWSER.AI TOKEN");
        
//Request Cloud Browser AI to open a browser
//using default settings
var rp = await svc.Open().ConfigureAwait(false);

if (rp.Status == ResponseStatus.Succes) {
    Console.WriteLine("Browser requested");
} else { 
    Console.WriteLine("Error requesting browser: {0}", rp.Status.ToString());
    return;
}

var browser = await Puppeteer.ConnectAsync(new ConnectOptions {
    BrowserWSEndpoint = rp.Address,
    DefaultViewport = null,
    AcceptInsecureCerts = true,
    SlowMo = 0
}).ConfigureAwait(continueOnCapturedContext: false);

Console.WriteLine("Browser connected");

var page = (await browser.PagesAsync().ConfigureAwait(false))[0];

await page.GoToAsync("http://www.cloudbrowser.ai").ConfigureAwait(false);
Console.WriteLine("Web visited");

await Task.Delay(5000).ConfigureAwait(false);

//You can close the browser using puppetter or CloudBrowser AI api
//await svc.Close(rp.Address).ConfigureAwait(false);
await browser.CloseAsync().ConfigureAwait(false);

Console.WriteLine("Browser closed");
```

***

#### **Full example**

{% @github-files/github-code-block fullWidth="false" %}

#### **How It Works**

1. **Initialize the Client**:\
   Create an instance of `BrowserService` using your API toke
2. **Request a Browser Instance**:\
   Call `svc.Open()` to request a new browser session from the CloudBrowser.AI service.
3. **Connect with PuppeteerSharp**:\
   Use the WebSocket address provided in the response to connect to the browser instance using `Puppeteer.ConnectAsync()`.
4. **Perform Browser Actions**:\
   Interact with the browser via PuppeteerSharp, such as navigating to a webpage or automating tasks.
5. **Close the Browser**:\
   Either use PuppeteerSharp's `browser.CloseAsync()` or CloudBrowser.AI's `svc.Close()` API to terminate the session.

## Open (with parameters)

The following example demonstrates how to request a browser instance with advanced configuration, including custom browser settings, proxy, and a timeout for keeping the browser open.

* **Label**: Set a custom label for the browser instance.
* **Browser**: Choose the browser type (e.g., Chromium or Chrome).
* **KeepOpen**: Set the timeout in seconds for how long the browser should remain open without a Puppeteer connection.
* **Proxy**: Configure proxy settings (host, port, username, password).

```csharp
using BrowserService svc = new("YOUR CLOUDBROWSER.AI TOKEN");

// Request a Cloud Browser instance with advanced settings
var rp = await svc.Open(new() {
    Label = "MyCustomBrowser",  // Custom label for the browser instance
    // Chromium is supported but we recommend Chrome for best stealth
    Browser = CloudBrowserAiSharp.Browser.Types.SupportedBrowser.Chromium,
    KeepOpen = 10 * 60,  // This browser will close after 10 minutes without Puppeteer connection
    Proxy = new() {
        Host = "IP.0.0.0.1",
        Port = "3000",
        Password = "password",
        Username = "username",
    }
}).ConfigureAwait(false);

```

#### **Full example**

{% embed url="<https://github.com/CloudBrowser-AI/CloudBrowserAiSharp/blob/main/samples/OpenAdvanced.cs/Program.cs>" %}
