Skip to content

Complete example

// Page initialization
async function init() {
// Check environment
if (!SuperSDK.isInApp()) {
console.log('Open this page in the app');
return;
}
// Get environment information
try {
const env = await SuperSDK.getEnv();
console.log('Current WebView ID:', env.webviewId);
console.log('App version:', env.versionName);
} catch (error) {
console.error('Could not read environment information:', error);
}
// Monitor lifecycle
SuperSDK.onForeground((data) => {
console.log('Page active');
refreshData();
});
SuperSDK.onBackground((data) => {
console.log('Page entered background');
pauseVideo();
});
// Listen to broadcast messages
SuperSDK.subscribe('user_logout', () => {
location.reload();
});
}
// Share feature
function shareToFriends() {
SuperSDK.share('Try this app');
}
// Open detail page
function openDetail(id) {
SuperSDK.openPage(`https://example.com/detail/${id}`);
}
// Close the page after completion.
function onComplete() {
// Notify other pages to refresh
SuperSDK.publish('order_created', { orderId: '12345' });
// Close current page
SuperSDK.closePage();
}
init();