# Get

The following example demonstrates how to request a browser instance, navigate to a webpage, disconnect the browser, retrieve details about all active browsers, and close them.

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

// Request a new browser instance
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;
}

// Connect to the browser using PuppeteerSharp
var browser = await Puppeteer.ConnectAsync(new () {
    BrowserWSEndpoint = rp.Address,
    DefaultViewport = null,
    AcceptInsecureCerts = true,
    SlowMo = 0
}).ConfigureAwait(continueOnCapturedContext: false);
Console.WriteLine("Browser connected");

// Navigate to a webpage
var page = (await browser.PagesAsync().ConfigureAwait(false))[0];
await page.GoToAsync("http://www.cloudbrowser.ai").ConfigureAwait(false);
Console.WriteLine("Web visited");

// Disconnect the browser
browser.Disconnect();
Console.WriteLine("Browser disconnected");

// Retrieve the list of all active browsers
var rpGet = await svc.Get().ConfigureAwait(false);

// Print details of all active browsers
Console.WriteLine("Label | Address | Started On | VNC Opened | VNC Pass");
foreach (var b in rpGet.Browsers) {
    Console.WriteLine("{0} | {1} | {2} | {3} | {4}", b.Label, b.Address, b.StartedOn, b.VNCPass != null, b.VNCPass);
    await svc.Close(b.Address).ConfigureAwait(false); // Close each browser
}
```

***

#### F**ull example**

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

#### **How It Works**

1. **Initialize the Client**:\
   Create an instance of `BrowserService` using your API token.
2. **Request a Browser Instance**:\
   Call `svc.Open()` to request a new browser session. The response will contain a WebSocket address (`rp.Address`) to connect to the browser instance.
3. **Connect to the Browser with Puppeteer**:\
   Use PuppeteerSharp to connect to the browser instance using the WebSocket address provided by the `Open` method.
4. **Navigate to a Webpage**:\
   Interact with the browser by navigating to a specified URL (e.g., "<http://www.cloudbrowser.ai>").
5. **Disconnect the Browser**:\
   Use `browser.Disconnect()` to disconnect from the browser session via PuppeteerSharp.
6. **Retrieve Active Browsers**:\
   Call `svc.Get()` to get a list of all active browser sessions, including their details like label, address, start time, and VNC credentials.
7. **Close Active Browsers**:\
   Loop through the list of active browsers and close each one by calling `svc.Close()` for each browser's address.

***

This approach allows you to automate browser interaction, retrieve information about active sessions, and close them as needed, all through the CloudBrowser.AI API.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cloudbrowser.gitbook.io/docs/libraries/.net-client/get.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
