# RemoteDesktop

The following example demonstrates how to request a browser instance, connect to it via Puppeteer, start a remote desktop session, and then stop the remote desktop session.

```javascript
const svc = new BrowserService(cloudBrowserToken);

const rp = await svc.open();

if (rp.status !== ResponseStatus.SUCCESS || rp.address == null) {
    console.log(`Error requesting browser: ${rp.status}`);
    return;
}
console.log("Browser requested");

const rmt = await svc.startRemoteDesktop(rp.address);
console.log("Remote desktop address:");
console.log(
    `https://browser.cloudbrowser.ai${obtainId(rp.address)}/${rmt.password}`
);
await new Promise((resolve) => setTimeout(resolve, 5000));
await svc.stopRemoteDesktop(rp.address);
```

***

#### F**ull example**

{% embed url="<https://github.com/CloudBrowser-AI/CloudBrowserAiNodeJS/blob/main/samples/remote-desktop/src/index.ts>" %}

This code initializes a browser session, starts a remote desktop session for that browser, and then stops the remote desktop after a short delay. Here’s a breakdown:

#### **1. Browser Session Initialization**

* A `BrowserService` instance is created using `cloudBrowserToken` for authentication.
* The `svc.open()` method is called to request a browser session. If the request fails or the WebSocket endpoint (`rp.address`) is not provided, an error message is logged, and the script terminates.
* If successful, it logs that the browser has been requested.

#### **2. Starting a Remote Desktop Session**

* The `svc.startRemoteDesktop(rp.address)` method is used to enable a remote desktop interface for the browser session. The `rmt.password` is generated for secure access.
* The script constructs and logs a URL to access the remote desktop session using the browser's ID (`obtainId(rp.address)`) and password.

#### **3. Delay and Stop Remote Desktop**

* The script pauses for 5 seconds using `setTimeout`, allowing interaction with the remote desktop session during this time.
* After the delay, the `svc.stopRemoteDesktop(rp.address)` method is called to terminate the remote desktop session.


---

# 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/node.js-client/remotedesktop.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.
