> For the complete documentation index, see [llms.txt](https://docs.pixiebrix.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pixiebrix.com/developing-mods/developer-concepts/types-of-mods/trigger/working-with-custom-events.md).

# Working with Custom Events

{% hint style="info" %}
[Release 1.7.0](/release-notes/release-notes-archive/release-1.7.0.md) in June 2022 introduced support for Custom Events.
{% endhint %}

Custom Events can be used to define your own custom Triggers, and control when a Sidebar Panel mod refreshes.

PixieBrix uses the [DOM Event API](https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events) standard. Therefore, custom events can be used to communicate bi-directionally with the host page.

### Emitting/Dispatching a Custom Event

To emit a custom event, use the [Emit a Custom Event](https://www.pixiebrix.com/marketplace/fcd0a884-fb83-4d82-a1c4-932287ae79f4/emit-a-custom-event/) brick. The brick takes two inputs:

* `eventName`: a unique name for the event. The name should be globally unique
* `data`: an optional data payload

PixieBrix dispatches the event on the root document of the frame.

### Running a Trigger on a Custom Event

To run a trigger on a Custom Event, choose “Custom Event” from the Trigger dropdown and configure the trigger:

* Custom Event: the name of the event. Should match the `eventName` in your use of Emit a Custom Event (see Emitting/Dispatching a Custom Event above)
* Element: an *optional* selector controlling the elements on which to listen for the event. Use when running triggers for events from the host page. The Emit a Custom Event brick emits events on the document itself.

<figure><img src="/files/ARdN7sp8DClF2Chrktne" alt=""><figcaption></figcaption></figure>

If the event includes data, that data will be available to the Trigger mod bricks as `@input.event`

If the event includes data, that data will be available to the Trigger mod bricks as `@input.event`

<figure><img src="/files/pQDTdzw4zILVm6rDf9vG" alt=""><figcaption></figcaption></figure>

### Refreshing a Sidebar Panel on Custom Event

Custom Events can also be used to control Sidebar Panel updates. To configure a Sidebar Panel to update on a custom event, choose “Custom Event” from the Panel Refresh > Trigger dropdown.

Then, configure the event to listen for:

* Custom Event: the name of the event. Should match the `eventName` in your use of Emit a Custom Event (see Emitting/Dispatching a Custom Event above)

<figure><img src="/files/e3qsna7s4grK5h8NkNCc" alt=""><figcaption></figcaption></figure>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.pixiebrix.com/developing-mods/developer-concepts/types-of-mods/trigger/working-with-custom-events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
