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
| Event | When | Data | Source |
|---|---|---|---|
ready | The bridge is ready on this page | { version } | Core (also wapp_library_ready()) |
device_shake | The user shook the phone | Haptics | |
share_to_app | Content was shared into your app | { url, text, subject, files, receivedAt } | Share into App |
iap_info_ready | Product information loaded | { products } | In-App Purchases |
iap_purchases | Purchases changed | Purchase list | In-App Purchases |
background_location | New 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.