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
// 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
App Information
getAppInfo() getConfig()
UI Functions
showToast() vibrate() copyToClipboard()
Local Storage
setItem() getItem() removeItem()
Device Information
getDeviceInfo() getBatteryLevel() getNetworkStatus()
Push Notifications
getFCMToken() registerFCMToken() showNotification()
Advertisements
showBannerAd() showInterstitialAd() showRewardedAd()
Biometric Auth
isBiometricAvailable() authenticate()
Navigation & Sharing
openUrl() shareContent() goBack()
Callback Pattern
How async functions work
Important
Callback functions must be defined in the global scope (on window object) so the native bridge can find them.
// 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
Always check shift2appjs availability
Your website might be viewed in a regular browser.
Parse JSON returns
Functions like getAppInfo() return JSON strings. Use JSON.parse().
Use global callbacks
Define callback functions on window object for async operations.