Skip to main content
JavaScript Bridge1 min read

JavaScript Bridge Quickstart

Detect whether your website runs inside the app, wait until window.wapp is ready, handle results and errors, and keep your site working in browsers.

Overview

This guide shows the patterns every bridge integration needs: detecting the app, waiting until the bridge is ready, calling methods and falling back to web behavior.

1. Detect the app

javascript
if (window.wapp) {
  showAppOnlyFeatures();
}

Inside the app, wapp.isNativeApp is true and wapp.bridgeVersion holds the bridge version. Your server can detect the app too: the app's user agent contains WebAppStudio/<version>.

2. Wait until the bridge is ready

The app adds window.wapp while the page loads. If your code may run earlier, wait for it:

javascript
function start() {
  // window.wapp is available here
}

if (window.wapp) start();
else window.addEventListener('wapp:ready', start);

Or define a global function; the app calls it when the bridge is ready:

javascript
window.wapp_library_ready = function () {
  start();
};

3. Call a method and handle the result

javascript
const result = await wapp.deviceInfo();
if (result.success) {
  console.log(result.platform, result.appVersion);
} else {
  console.warn(result.code, result.error);
}

Calls also accept a callback function in the parameters, if you prefer callbacks to promises.

4. Keep it working in browsers

Treat the bridge as an enhancement:

javascript
async function share(url) {
  if (window.wapp) {
    const result = await wapp.share.open({ url });
    if (result.success || result.code === 'CANCELLED') return;
  }
  await navigator.clipboard.writeText(url); // web fallback
  showToast('Link copied');
}

5. React, Vue and other frameworks

Access window.wapp only in the browser (for example in useEffect or onMounted), never during server-side rendering:

javascript
import { useEffect, useState } from 'react';

export function useIsNativeApp() {
  const [isApp, setIsApp] = useState(false);
  useEffect(() => {
    if (window.wapp) setIsApp(true);
    else window.addEventListener('wapp:ready', () => setIsApp(true), { once: true });
  }, []);
  return isApp;
}
Note

An npm package with the same API and TypeScript types is being prepared but is not published yet. Use window.wapp directly.

6. Test

The bridge exists only inside the app. Test in a Preview build on a real device after turning on the plugins and permissions you use. Each plugin also has a test page; see Native plugins overview.

Next steps