# Source: https://docs.replit.com/extensions/api/background.md

# Background Script API

> Learn how to use background scripts to run persistent code in your Replit extension from startup until the workspace closes.

Background scripts are loaded when the Replit App opens. They remain permanently loaded until the extension is uninstalled or you close the workspace.

Background scripts are written in a "background page", which is an "invisible" iFrame context that renders no UI.

You can add a background page to your extension by adding the following field to your [Manifest](/extensions/api/manifest) file:

```json  theme={null}
{
  "background": {
    "page": "/path/to/background.html"
  }
}
```

The path points to a page in your extension bundle. We load it as an invisible iframe element; if you render any UI elements, they will not be visible to users. (To render UI, you want to create tools instead).

Here's an example extension that makes use of the background script:

<Card href="https://replit.com/@util/background-script-example#README.md" title="Background Script Example" description="A simple example of a background script." icon="paperclip" horizontal={true} />