# Customize Window

Once your `Window` instance is initialized, you can control its layout, inject client-side scripts, and construct custom native desktop menus using the built-in API.

### Window Properties

#### Setting the Window Title

Dynamically updates the text displayed in the native OS title bar.

{% code lineNumbers="true" %}

```javascript
mainWindow.on('ready', async () => {
  mainWindow.setTitle("Hello World!");
});
```

{% endcode %}

#### Getting the Window Title

{% code lineNumbers="true" %}

```javascript
mainWindow.on('ready', async () => {
  const title = await mainWindow.getTitle();
});
```

{% endcode %}

#### Resizing the Window

Adjust the viewport dimensions smoothly at runtime. Pass the explicit width and height configurations in pixels.

{% code lineNumbers="true" %}

```javascript
mainWindow.on('ready', async () => {
  // Arguments: (width, height)
  mainWindow.resize(1024, 768);
});
```

{% endcode %}

### User Script Injection

You can inject JavaScript strings or entire files directly into the renderer process container. These scripts run with full privileges as soon as the native DOM environment initializes.

{% code lineNumbers="true" %}

```javascript
mainWindow.on('ready', async () => {
  // Inline Script Injection
  mainWindow.addUserScript("console.log('Hello from the Native Side!')");
  
  // File System Script Injection
  mainWindow.addUserScriptFromFile(`${__dirname}/preload-bundle.js`);
});
```

{% endcode %}

### Swipe Navigation

Enable trackpad or touchscreen swipe to go forward/back.

{% code lineNumbers="true" %}

```javascript
mainWindow.setSwipeNavigation(enabled)
```

{% endcode %}

### macOS Only

#### Set Closable

{% code lineNumbers="true" %}

```javascript
mainWindow.setCloseable(true|false)
```

{% endcode %}

#### Set Resizable&#x20;

{% code lineNumbers="true" %}

```javascript
mainWindow.setResizable(true|false)
```

{% endcode %}

#### Set Minimizable

{% code lineNumbers="true" %}

```javascript
mainWindow.setMinimizable(true|false)
```

{% endcode %}

#### Set Titlebar Visible

{% code lineNumbers="true" %}

```javascript
mainWindow.setTitlebarVisible(true|false)
```

{% endcode %}

#### Set Titlebar Transparent

{% code lineNumbers="true" %}

```javascript
mainWindow.setTitlebarTransparent(true|false)
```

{% endcode %}

#### Content Blockers

For more info, refer to <https://webkit.org/blog/3476/content-blockers-first-look/>

Here is an example ad blocker implementation:

<pre class="language-javascript" data-line-numbers><code class="lang-javascript">googleWindow.on('ready', async () => {

  // Download easylist  
  if(!fs.existsSync(app.userData.getPath("easylist_content_blocker.json"))) {
    const res = await fetch('https://easylist-downloads.adblockplus.org/easylist_content_blocker.json')
    const data = await res.json()
    fs.writeFileSync(app.userData.getPath("easylist_content_blocker.json"), JSON.stringify(data, null, 2))
  }
  
<strong>  await googleWindow.addToContentBlocker({
</strong><strong>    file: app.userData.getPath("easylist_content_blocker.json"),
</strong><strong>    // json: {...},
</strong><strong>    // url: "https://.....",
</strong><strong>    reload:true, // Reload the page when the content blocker is applied
</strong><strong>    clearExisting:true // Clear any existing blockers first
</strong><strong>  })
</strong>
   await googleWindow.loadURL("https://www.google.com")

   console.log("Google window loaded with content blocker rules applied.")
  
})
</code></pre>


---

# 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/customize-window.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.
