Skip to main content
JavaScript Bridge1 min read

JavaScript Bridge Events

Listen for events from your app with wapp.on, window events or global functions: ready, device shake, shared content, purchases and background location.

Overview

Method calls return their result as a promise. Some things happen on the app's side without your page asking: the user shakes the phone, shares a link into your app, or a purchase completes. These arrive as events.

Three ways to listen

javascript
// 1. wapp.on returns a function that stops listening
const stop = wapp.on('device_shake', (data) => openFeedbackForm());
stop();

// 2. A window event named wapp:<event>; the data is in event.detail
window.addEventListener('wapp:device_shake', (event) => openFeedbackForm(event.detail));

// 3. A global function named wapp_<event>
function wapp_device_shake(data) {
  openFeedbackForm();
}

Window events are handy in React or Vue components, where you add and remove listeners with the component's lifecycle.

Events

EventWhenDataSource
readyThe bridge is ready on this page{ version }Core (also wapp_library_ready())
device_shakeThe user shook the phoneHaptics
share_to_appContent was shared into your app{ url, text, subject, files, receivedAt }Share into App
iap_info_readyProduct information loaded{ products }In-App Purchases
iap_purchasesPurchases changedPurchase listIn-App Purchases
background_locationNew location points{ locations }Background Location

Plugin events need the plugin turned on and included in the app build.

Delivery

Events that happen before your page can take them, for example content shared while the app was closed, are kept and delivered once your page has loaded.

Next steps