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

# Bubble plugin

> Call the JavaScript Bridge from your Bubble app.

## Setup

To get started, install the Median Bubble plugin in the Bubble app editor via **Plugins → Add Plugins → Median Plugin**.

Drag the "**Median Plugin**" element from the "**Elements**" section and drop it on the page that requires access to the Median JavaScript Bridge. This element initializes the JavaScript Bridge library so that commands can be executed on page load as shown in the following section.

[Median JavaScript Bridge Plugin on Bubble](https://bubble.io/plugin/gonative-javascript-bridge-1662164388589x419660551052853250)

> [!TIP]
>
> **Developer Demo**
>
> Display our demo page in your app to test during development [Demo Bubble app](https://gonative-test-site.bubbleapps.io/version-test)

## Execute command on page load

To execute a Median JavaScript Bridge command on page load, click the "**Median Plugin**" element that you just dropped on the page and insert your desired JavaScript into the text input captioned "**Median Library Ready Custom Script**" as shown below:

![Median Library Ready Custom Script field on the Median Plugin element in Bubble](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/359eb70-on-page-load.png?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=f4c3271e11ff842ca3436b3168740d25)

Median on page load JavaScript

## Execute command as a workflow/action

Suppose you want to set the device brightness to 80% when a user taps a button. To accomplish this, drag a button from the "**Elements**" section on your page and change its name to "Set Brightness" or as desired:

![Set Brightness button added to a page in the Bubble editor](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/4c888bc-create-button.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=92276468c53c5d76399b2eda9cdde0e0)

Create a button

Once the button is created, click "Start/Edit workflow" and you will see the following page:

![New workflow for the button click event in Bubble](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/bad5d2e-workflow.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=a65248d000d2a5aa7e6e656a33f60036)

Create a new workflow

To assign a Median JavaScript Bridge command to the click event of this button, click on "**Click here to add an action**" to view the list of various actions. Select **Plugins → Median Screen Brightness** as shown below:

![Median Screen Brightness action in the Bubble Plugins action list](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/835a59b-choose-action.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=139f1cf76fd24dc4a9529c972f356b92)

Select action

The final step in configuring a workflow/action is to modify the action as required. In this example, set the Brightness value to 0.8 and set the "**Restore on navigation**" field to "**no**" as shown below:

![Median Screen Brightness action with Brightness set to 0.8](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/a091060-set-brightness.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=d871ec6417f05358e4baa6f6b634f7ee)

Set brightness

When a user taps this button within your app, the Median Bubble plugin runs the corresponding Median JavaScript command and set the screen brightness to 80%.

### Dynamic value

You can also assign a dynamic value to the brightness field so that it takes the value of an element as its input.

The dynamic value can be a text input, a slider, or any one of the elements from which a value can be read. For instance, to set the dynamic value as a slider value, drag and drop a **"Slider Input"** element from the **"Elements"** section to your page. Since the acceptable brightness values in Median apps are between 0 and 1, set the min and max values of the slider element to 0 and 1 respectively, and set the "Step" to 0.1 as shown below:

![Slider Input element with min 0, max 1, and step 0.1](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/bec3d6b-slider-config.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=7cb82218ee065cedddec5a0f225c1fe0)

Slider config

Once the Slider Input element is configured, go to the **"Workflow"** section and create a new event to trigger when your slider's value is changed. Choose the "An input's value is changed" option and then select your slider element:

![An input's value is changed event selected for the slider in Bubble](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/82548af-slider-event.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=395c938e6d9098706d92c878ae94f8a7)

Slider value changed event

Now add an action to the slider and select **Plugins → Median Screen Brightness**. If you click on the **"Brightness"** field, you will see the option **"Insert dynamic data"** as shown below:

![Insert dynamic data option on the Brightness field](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/0342804-slider-dynamic-data.png?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=e8ad8c1e66d455c1c0adb361059800f6)

Slider dynamic data

After clicking the option, you will see a list of all elements that you have in your page. Select your slider element and then choose **"This SliderInput's value"** to read the element's value.

![Brightness field set to This SliderInput's value](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/062fde7-slider-action.png?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=e3e3709ecc50c360cb5f242a5e52c09f)

Slider action

Once this action is configured, your app will read the brightness value from the slider input when setting the brightness level.

## Execute custom JavaScript

To access advanced Median JavaScript Bridge functions in a custom script, you can use any plugin that enables JavaScript execution. For instance, you can run any Median JavaScript commands via the “[Toolbox plugin](https://bubble.io/plugin/toolbox-1488796042609x768734193128308700)” which allows you to run JavaScript as a workflow.

Once the plugin is installed, select an element and click **"Start/Edit workflow"**. Create an action, choose **Plugins → Run JavaScript**, and add your desired JavaScript to run as shown below:

![Run JavaScript action from the Toolbox plugin in a Bubble workflow](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/d00c9bf-toolbox.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=f45bf287b7a11d69ca521a1882b086b9)

Toolbox JavaScript

This plugin can also be used to run AJAX HTTP requests to send data returned from your app via the JavaScript Bridge to your servers or request data from your servers to pass it to your app via the JavaScript Bridge.

## Process returned data

> [!NOTE]
>
> **Returned data variable**
>
> All the data that Median returns from the app can be accessed in your custom callback script by the variable named "data".
>
> For example:

```javascript JavaScript theme={null}
document.getElementById("contacts_output").value = JSON.stringify(data);
```

Some Median JavaScript commands return data from the device. For example, the Native Contacts plugin function to retrieve contacts from the user's address book: `median.contacts.getAll()`. This function returns a JSON object containing the user's contact list that you can send to your server via AJAX calls or pass to one of Bubble's elements such as the "Multiline Input" as seen in the following example.

First, you will need to enable the ID Attribute in your elements by going to **Settings → General** and checking the option "Expose the option to add an ID attribute to HTML elements". Now, drag the multiline input element to your page, double-click it and set its ID Attribute (at the very bottom) to a unique string (such as `contacts_output`).

Note: Since this ID Attribute will be used to identify a unique element in a given page, it has to be a unique string.

Once complete, go to your Workflow section, then open the "Median Native Contacts" action you want to read the data from, and paste the custom callback script as shown below. Replace `contacts_output` with the ID Attribute of your multiline input element. This script will set the value of the element with the ID Attribute `contacts_output` (in our case, the Multiline Input) to the "stringified" JSON object that the Native Contacts plugin returned.

![Custom callback script in the Median Native Contacts action](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/688548e-id-attribute.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=5333f0e817d302bb0e293e4cf47d57e7)

Median Native Contacts: ID Attribute

## Supported commands

The following JavaScript Bridge commands are supported within the Bubble plugin via drag-and-drop actions:

* [Set Screen Brightness](https://docs.median.co/docs/screen-brightness.md)
* [Set Status Bar](https://docs.median.co/docs/status-bar.md)
* [Download file / image](https://docs.median.co/docs/download-file.md)
* [Share Page](https://docs.median.co/docs/prompt-share-dialogue.md)
* [QR / Barcode Scanner](https://docs.median.co/docs/qr-barcode-scanner.md)
* [Device Info](https://docs.median.co/docs/device-info.md)
* [Set Navigation Titles](https://docs.median.co/docs/dynamic-titles.md)
* [Set Sidebar Items](https://docs.median.co/docs/dynamic-menu-items.md)
* [Set Tab bar Items](https://docs.median.co/docs/dynamic-tab-menu.md)
* [Set Navigation Levels](https://docs.median.co/docs/auto-new-windows.md)
* [OneSignal Info and Set / Remove External User ID](https://docs.median.co/docs/identifying-targeting-users.md)
* [OneSignal Show Tags UI](https://docs.median.co/docs/identifying-targeting-users.md#method-2-web-ui-and-javascript)
* [Native Contacts](https://docs.median.co/docs/native-contacts.md)
* [Firebase Analytics - Set User and Log Events](https://docs.median.co/docs/firebase-analytics.md)
* [Send Facebook Events](https://docs.median.co/docs/facebook.md)
* [iOS ATT consent Request / Get Status](https://docs.median.co/docs/apple-att.md)
* [Show/Hide iOS Contextual Navigation Toolbar](https://docs.median.co/docs/contextual-navigation-toolbar.md)
* [Social Login Server-side Redirect functions](https://docs.median.co/docs/social-login-server-side-redirects.md)
* [Social Login JavaScript Callback functions](https://docs.median.co/docs/social-login-javascript-callbacks.md)

## Demo app


## Related topics

- [Native plugins overview](https://docs.median.co/docs/native-plugins-overview.md)
- [Adjust](https://docs.median.co/docs/adjust.md)
- [Integrations](https://docs.median.co/docs/integrations.md)


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