Shift2App
Home chevron_right JavaScript Bridge
code

JavaScript Bridge

Complete API reference for the shift2appjs object

Introduction

Connecting your website to native features

When your website runs inside Shift2App, a global shift2appjs object is injected, giving you access to 75+ native functions.

How to Use

Basic usage patterns

javascript
// Check if shift2appjs exists
if (typeof shift2appjs !== "undefined") {
    shift2appjs.showToast("Hello!");
}

// Synchronous - returns value immediately
const appInfo = JSON.parse(shift2appjs.getAppInfo());
console.log(appInfo.appName);

// Callback-based - result via callback
shift2appjs.authenticate("onAuthComplete");

function onAuthComplete(success, message) {
    console.log(success ? "Authenticated!" : "Failed: " + message);
}

Function Categories

All 75+ functions organized by purpose

Callback Pattern

How async functions work

warning
Important

Callback functions must be defined in the global scope (on window object) so the native bridge can find them.

javascript
// Define callback globally
window.onRewardEarned = function(success, amount, type) {
    if (success) {
        alert("You earned " + amount + " " + type + "!");
    }
};

// Call the native function with callback name
shift2appjs.showRewardedAd("onRewardEarned");

Best Practices

check_circle
Always check shift2appjs availability

Your website might be viewed in a regular browser.

check_circle
Parse JSON returns

Functions like getAppInfo() return JSON strings. Use JSON.parse().

check_circle
Use global callbacks

Define callback functions on window object for async operations.

dashboard Dashboard menu_book Docs science Playground