> ## Documentation Index
> Fetch the complete documentation index at: https://docs.embeddables.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How To: Run custom code when the Embeddable loads

> Running JS code on first load, e.g. to run a function or add an event listener

![](https://mintcdn.com/embeddables/f00lqPv7EEUt_xOC/images/how-to/add-action.gif?s=27644d26bba142407ae9ad96b985a5d0)

Adding a custom code Action to run when the Embeddable first loads

**1. Add a Trigger for on first load**

* Open the Logic card.
* Switch to the Triggers tab.
* Add a new Trigger.
* Select `When "Flow" Is "Loaded"`.

**2. Create a custom code Action**

* Click "Create New Action".
* Give it a name.
* Hit Apply.

**3. Write your custom code**

* Add whatever custom JS you like inside the `output()` function.
* The first argument of `output()` is the User Data, and the other arguments
  are [described here](https://docs.embeddables.com/guides/custom-code.md).
* The code will execute on the frontend, in the main window environment,
  so has access to window functions and variables.

> [card] [Learn more about Custom Code](https://docs.embeddables.com/guides/custom-code.md)
>
> Read more about writing Custom Code in Embeddables, including all the
> available arguments passed in to the function.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.