# Struct `kurogane::BrowserHandle`

```rust
pub struct BrowserHandle { /* private fields */ }
```

A browser of the running application.

The handle names the browser by its [`BrowserId`] and looks it up on each
call. Once the browser has closed, or once [`AppInstance::shutdown`] has
begun, the calls that would reach it do nothing and its queries answer
false, or an empty URL.

## Threads

Usable from any thread, as CEF allows for a browser in the browser
process. [`set_bounds`](https://kurogane-rs.org/docs/api/app/browserhandle.md#method.set_bounds) and
[`has_devtools`](https://kurogane-rs.org/docs/api/app/browserhandle.md#method.has_devtools) are the exceptions. They run only on
the thread that started the application (CEF's UI thread) and panic
elsewhere.

[`AppInstance::shutdown`]: https://kurogane-rs.org/docs/api/app/appinstance.md#method.shutdown
[`BrowserId`]: https://kurogane-rs.org/docs/api/windows/browserid.md
[Self::set_bounds]: https://kurogane-rs.org/docs/api/app/browserhandle.md#method.set_bounds
[Self::has_devtools]: https://kurogane-rs.org/docs/api/app/browserhandle.md#method.has_devtools

## Methods

### `id`

```rust
pub fn id(&self) -> BrowserId
```

The id of the browser this handle names.

### `close`

```rust
pub fn close(&self, force: bool)
```

Closes the browser.

With `force` false the page's unload handlers run first and may cancel
the close. The call does not wait. The browser is gone once CEF has
finished closing it. A browser embedded in the application's own
window closes without asking that window to close.

### `set_bounds`

```rust
pub fn set_bounds(&self, bounds: BrowserBounds)
```

Moves and resizes a browser made by
[`AppInstance::create_child_browser`] inside its parent window.

`bounds` are in the parent's coordinates, as at creation (see
[`BrowserBounds`]); a width or height below one counts as one. On
Windows and Linux Chromium places such a browser once and does not
follow its parent. The application calls this whenever the browser's
place changes (on every resize for a browser that fills its window).
On macOS the browser stretches with its parent by itself and this
places it anywhere.

Does nothing for any other browser and nothing once the browser has
closed.

#### Panics

Off the thread that started the application (CEF's UI thread). The
browser's native window is moved only there.

[`AppInstance::create_child_browser`]: https://kurogane-rs.org/docs/api/app/appinstance.md#method.create_child_browser
[`BrowserBounds`]: https://kurogane-rs.org/docs/api/app/browserbounds.md

### `notify_move_or_resize_started`

```rust
pub fn notify_move_or_resize_started(&self)
```

Tells the browser that the window hosting it is about to move or
resize. CEF uses this on Windows and Linux only.

### `navigate`

```rust
pub fn navigate(&self, url: &str)
```

Navigate the main frame to the given URL.

### `reload`

```rust
pub fn reload(&self)
```

Reload the current page.

### `reload_ignore_cache`

```rust
pub fn reload_ignore_cache(&self)
```

Reload the current page, ignoring cached content.

### `go_back`

```rust
pub fn go_back(&self)
```

Navigate back in history, if possible.

### `go_forward`

```rust
pub fn go_forward(&self)
```

Navigate forward in history, if possible.

### `can_go_back`

```rust
pub fn can_go_back(&self) -> bool
```

Returns true if the browser can go back.

### `can_go_forward`

```rust
pub fn can_go_forward(&self) -> bool
```

Returns true if the browser can go forward.

### `is_loading`

```rust
pub fn is_loading(&self) -> bool
```

Returns true if the browser is currently loading.

### `url`

```rust
pub fn url(&self) -> String
```

Returns the current URL of the main frame.

### `execute_javascript`

```rust
pub fn execute_javascript(&self, code: &str, script_url: &str, start_line: i32)
```

Execute JavaScript in the main frame.

### `show_devtools`

```rust
pub fn show_devtools(&self)
```

Open DevTools for this browser.

### `close_devtools`

```rust
pub fn close_devtools(&self)
```

Close DevTools if open.

### `has_devtools`

```rust
pub fn has_devtools(&self) -> bool
```

Returns true if DevTools is currently open for this browser.

#### Panics

Off the thread that started the application (CEF's UI thread). CEF
answers this only there.

## Trait implementations

- `impl Debug for BrowserHandle`

Source: https://github.com/0x48piraj/kurogane/blob/584c586118ee53cc04604007ee038557bd859092/kurogane/src/runtime.rs#L908
