> For the complete documentation index, see [llms.txt](https://docs.hbwrapper.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hbwrapper.com/customization.md).

# Customization

This section details how to customize the Header Bidding wrapper using custom scripts and modules, for Prebid 10 and later.

**In plain terms:** beyond the settings in [Configuration](/configuration.md), you can add your own JavaScript that becomes part of the wrapper build. This is for developers who need behaviour that settings alone can't express. If you're not writing code, you can skip this page.

**Two ways to reach the wrapper — and when to use each:**

* **From a custom script built into the wrapper** (this page): read the global variable name from the config, since the script runs inside the wrapper's own environment. That's the `var pbjs = window[config.globalVar]` pattern shown below.
* **From a snippet on the publisher's page** (see [Public API](/public-api.md)): just use the global variable directly by name — `pbjs` by default, or whatever your site sets in `config.globalVar`.

Both approaches talk to the same object; they only differ in how they get a reference to it. Neither uses the old `$$PREBID_GLOBAL$$` macro, which was removed in Prebid 10.

Overview

* Write modular scripts using the `custom_[name].js` convention
* Use the configured wrapper global from `config.json` instead of the deprecated `$$PREBID_GLOBAL$$` macro
* Prefer queueing code that interacts with the wrapper API

**CRITICAL:** From [7.22.0](/release-notes.md), a throw while a `custom_*.js` file is loading no longer takes down the wrapper — but **that custom script is skipped**. Always wrap wrapper API calls (`getUserInfo`, `getConfig`, `setConfig`, `aliasBidder`, `onEvent`, and similar) in `pbjsInstance.cmd.push(function() { ... })`. Do not call them at the top of the file. Failed scripts log `[wrapper] custom script failed: <filename>` in the console.

## Custom Script Files

Custom script/modules files can be loaded and concatenated to the core code. For the file to be parsed it needs to have the name with following syntax: `custom_[filename].js`

e.g.: `custom_interstitial.js`

It will always start with `custom_` and the code needs to be written in javascript.

Any valid javascript is allowed.

Can import any module.

Must reference the Prebid instance via the wrapper configuration instead of the `$$PREBID_GLOBAL$$` macro (removed in Prebid 10).

### Accessing the Prebid Global (Prebid 10+)

Custom scripts run inside the wrapper environment. To access the Prebid instance in a way that is compatible with Prebid 10 and later, read the wrapper configuration and create a local reference:

```javascript
var config = require('./config.json');
var pbjsInstance = window[config.globalVar] || {};
pbjsInstance.cmd = pbjsInstance.cmd || [];
```

You can then safely queue commands on `pbjsInstance.cmd`, for example to define an alias:

```javascript
var config = require('./config.json');
var pbjsInstance = window[config.globalVar] || {};
pbjsInstance.cmd = pbjsInstance.cmd || [];

pbjsInstance.cmd.push(function() {
    pbjsInstance.aliasBidder('improvedigital', 'weborama');
});
```

### Executing Code After Page Load

Import `docReady` from `_utils.js` to run code after the DOM is ready. It is not attached to `window`.

```javascript
import { docReady } from '../_utils.js';

docReady(function() {
    // DOM is ready
});
```

### Including Source Files

You can import modules from the `src` directory into your custom scripts. However, because of the build process, the relative path to these files will be one level deeper than it appears in the source tree. For example, to import `utils.js` from the `src` folder, you would use `../utils.js`.

### Example

Here is an example of a custom script that uses `docReady` from `_utils.js`, an import from the `src` directory, and the wrapper configuration to access the Prebid instance:

```javascript
import { logMessage, logError } from '
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hbwrapper.com/customization.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
