# Actions

Once your `Window` instance is initialized, you can trigger native OS commands, manipulate window visibility, navigate web history, and interact directly with the underlying render engine.

### **Displaying a Native Alert**

Triggers a blocking, native operating system dialog box displaying the specified message.

{% code lineNumbers="true" %}

```javascript
mainWindow.alert("Changes saved successfully!");
```

{% endcode %}

### **Opening Developer Tools**

Spawns the built-in web debugging and inspection panel for the window's current render process.

{% code lineNumbers="true" %}

```javascript
mainWindow.openDevTools();
```

{% endcode %}

### **Capturing the Page**

Requests a visual screenshot or snapshot of the current web contents rendered inside the window frame.

{% code lineNumbers="true" %}

```javascript
mainWindow.capturePage();
```

{% endcode %}

### Window State & Visibility

**Closing the Window**

Destroys or terminates the current window instance, sending a teardown signal to the native renderer.

{% code lineNumbers="true" %}

```javascript
mainWindow.close();
```

{% endcode %}

### **Showing and Hiding the Window**

Toggles the visibility of the window on the desktop without destroying its underlying memory state or socket connection.

{% code lineNumbers="true" %}

```javascript
// Make the window invisible
mainWindow.hide();

// Bring the window back into view
mainWindow.show();
```

{% endcode %}

### Is Visible

{% code lineNumbers="true" %}

```javascript
const vis = await mainWindow.isVisible();
```

{% endcode %}

### **Focusing the Window**

Forces focus or brings the native desktop window to the foreground of the operating system window hierarchy.

{% code lineNumbers="true" %}

```javascript
mainWindow.focus();
```

{% endcode %}

### Viewport & Display Control

### **Toggling Fullscreen**

Switches the window back and forth between standard windowed mode and standard fullscreen display mode.

{% code lineNumbers="true" %}

```javascript
mainWindow.toggleFullscreen();
```

{% endcode %}

#### **Entering Fullscreen Explicitly**

Forces the window frame to expand and take over the entire desktop display area.

{% code lineNumbers="true" %}

```javascript
mainWindow.goFullscreen();
```

{% endcode %}

#### **Exiting Fullscreen Explicitly**

Forces the window out of fullscreen layout, returning it to its normal bounded dimensions.

{% code lineNumbers="true" %}

```javascript
mainWindow.exitFullscreen();
```

{% endcode %}

### Browser History & Navigation

#### **Going Back**

Navigates backward to the previous page in the window's internal browsing history chain.

{% code lineNumbers="true" %}

```javascript
const canGoBack = await mainWindow.canGoBack()

if (canGoBack) {
  mainWindow.goBack();
}
```

{% endcode %}

#### **Going Forward**

Navigates forward to the next page in the window's internal browsing history chain.

{% code lineNumbers="true" %}

```javascript
const canGoForward = await mainWindow.canGoForward()

if (canGoForward) {
  mainWindow.goForward();
}
```

{% endcode %}

#### **Reloading the Page**

Refreshes and re-evaluates the currently loaded URL or local file resource.

{% code lineNumbers="true" %}

```javascript
mainWindow.reload();
```

{% endcode %}

### Show Notification

{% code lineNumbers="true" %}

```javascript
mainWindow.showNotification(title, body, options?)
```

{% endcode %}

### Set Bounds

{% code lineNumbers="true" %}

```javascript
mainWindow.setBounds(x,y,width,height)
```

{% endcode %}

#### Get Bounds

{% code lineNumbers="true" %}

```javascript
await mainWindow.getBounds()
```

{% endcode %}

### Evaluate JavaScript

Evaluate some JavaScript in the renderer process and return the result back to the main process.

{% code lineNumbers="true" %}

```javascript
await mainWindow.evaluateJavaScript("console.log('hi')")
```

{% endcode %}

### Print Page

Show the OS print dialogue for the current page. Similar to `window.print()`

{% code lineNumbers="true" %}

```javascript
mainWindow.print()
```

{% endcode %}

### Set User Agent

Set a custom user agent string for the window.

{% code lineNumbers="true" %}

```javascript
mainWindow.setUserAgent("userAgent")
```

{% endcode %}

#### Get User Agent

{% code lineNumbers="true" %}

```javascript
await mainWindow.getUserAgent()
```

{% endcode %}

### Prompt

Prompt for a value. Similar to `window.prompt()`

{% code lineNumbers="true" %}

```javascript
await mainWindow.prompt("title", "defaultValue")
```

{% endcode %}

### Example

Here in a combined example to set the user agent to a user-provided one.

{% code lineNumbers="true" %}

```javascript
  const userAgent = await mainWindow.prompt("Enter a new user agent string:", "My Custom User Agent/1.0")
  if(!userAgent) return mainWindow.alert("No user agent entered. User agent change cancelled.")
  mainWindow.setUserAgent(userAgent)
  const res = await mainWindow.evaluateJavaScript(`document.documentElement.innerHTML += "<h1>Current User Agent:</h1><p>" + navigator.userAgent + "</p>"; navigator.userAgent;`)
  console.log("New User Agent:", res.result)
```

{% endcode %}

### Set Style Of

{% code lineNumbers="true" %}

```javascript
await mainWindow.setStyleOf("#selector", { styles_here }) 
```

{% endcode %}

#### Remove

{% code lineNumbers="true" %}

```javascript
await mainWindow.removeStyleOf("#selector") 
```

{% endcode %}

### Set Attribute Of

{% code lineNumbers="true" %}

```javascript
await mainWindow.setAttributeOf("#selector", "attribute", "value") 
```

{% endcode %}

#### Remove

{% code lineNumbers="true" %}

```javascript
await mainWindow.removeAttributeOf("#selector", "attribute") 
```

{% endcode %}

### onClick

Set a client-side button's onclick to send a IPC message back over `channel`. Set `replace` to true to set `#selector.onclick` and false to use `#selector.addEventListener`

{% code lineNumbers="true" %}

```javascript
await mainWindow.onClick("#selector", "channel", { replace: true })
```

{% endcode %}

#### Remove onClick

{% code lineNumbers="true" %}

```javascript
await mainWindow.removeOnClick("#selector")
```

{% endcode %}


---

# 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://positronjs.gitbook.io/v1/commands/actions.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.
