Skip to main content
hylid-bridge is an npm package for Native Mini Programs that are launched from a foreign native app container (cross-app launch). It provides a normalized my.* API layer that works consistently regardless of which host app is running the Mini Program.
This package is only needed for cross-app launch scenarios — when your Native Mini Program is opened from a different native app. Standard Mini Apps running inside the Rebell SuperApp do not require hylid-bridge: the my object is injected automatically by the SuperApp runtime.

When to Use hylid-bridge

ScenarioUse hylid-bridge?
Native Mini App in Rebell SuperAppNo — my.* available natively
H5 Mini App in Rebell SuperAppVia CDN <script> tag (not this npm package)
Native Mini App launched cross-app (from a partner app)Yes — install via npm

Installation

npm install hylid-bridge --save

Usage

Import the specific APIs you need directly from the package:
import { alert, appEnv, getAppIdSync } from 'hylid-bridge'

Page({
  onLoad() {
    alert({ content: 'Hello from Mini Program!' })
  }
})

Handling Platform Differences

When running cross-app, not all JSAPIs are available on every host platform. Use appEnv to detect the runtime and branch accordingly:
import { appEnv, getAppIdSync, alert } from 'hylid-bridge'

Page({
  onLoad() {
    if (appEnv.platform === 'alipay') {
      const { appId } = getAppIdSync();
      console.log('Running on Alipay, App ID:', appId);
    } else {
      alert({ content: 'Some features may not be available on this platform' });
    }
  }
})

Supported APIs

  • alert - Show alert dialog
  • confirm - Show confirmation dialog
  • showToast - Show toast message
  • showLoading - Show loading indicator
  • hideLoading - Hide loading indicator
  • showActionSheet - Show action sheet
  • setStorage - Store data
  • getStorage - Retrieve data
  • removeStorage - Remove data
  • clearStorage - Clear all data
  • getLocation - Get current location
  • openLocation - Open location in map
  • chooseLocation - Choose a location
  • request - Make HTTP requests
  • uploadFile - Upload files
  • downloadFile - Download files
  • getSystemInfo - Get system information
  • getNetworkType - Get network type
  • scan - Scan QR codes
  • tradePay - Process payments
  • signContract - Sign contracts

Requirements

Applications using the JS bridge in cross-app scenarios may need to:
  • Request specific permissions from host platforms
  • Whitelist domains for API calls
  • Handle cases where certain APIs are not available on the host platform

Domain Whitelisting

{
  "networkTimeout": {
    "request": 30000,
    "downloadFile": 30000
  },
  "request": {
    "whitelist": [
      "https://api.yourdomain.com"
    ]
  }
}

Error Handling

Always implement error handling — cross-app environments may not support every API:
import { request } from 'hylid-bridge'

async function fetchData() {
  try {
    const res = await request({
      url: 'https://api.example.com/data',
      method: 'GET'
    });
    return res.data;
  } catch (error) {
    console.error('Bridge API error:', error);
    if (error.code === 'NOT_SUPPORTED') {
      // API not available on this host platform
    }
  }
}

Next Steps

JSAPI Overview

Learn about all available JSAPIs

JSAPI Reference

Complete API reference