Bridge API Reference
Drel can invoke native actions on your page's behalf — but only what an Ed25519-signed manifest explicitly declares and the user allows. This is not a general, unrestricted JavaScript-to-native bridge.
The authorization chain
Every controlled action passes six security checks before any native handler runs. A failure at any step fails closed, never crashes the app.
| # | Check | Fails when |
|---|---|---|
| 1 | App identity | The page was opened as an ordinary URL, not from a registered application. |
| 2 | Exact declaration | The signed manifest's capabilities_v2 does not declare that action for that origin. |
| 3 | Origin match | The page origin is not in the declared origin list, compared exactly (scheme://host:port). |
| 4 | Foreground gesture | No recent user touch event consumed the call (blocks background automation). |
| 5 | Grant ledger | No stored grant covers this gateway, app, origin, and action tuple. |
| 6 | Native prompt | The user cancels or rejects the native permission sheet. |
Declared actions (Manifest v2)
Seven actions are exposed in Drel 1.5.0. Each must be declared in the signed manifest with a purpose ID, an origin list, and a scope.
| Action | Scope | What it does |
|---|---|---|
haptic | appSession | Brief tactile feedback following a user tap. |
vibrate | appSession | Brief, bounded vibration. |
share | appSession | Opens the native iOS share sheet; the user inspects content and picks the destination. |
fullscreen | appSession | Hides host chrome while keeping a host-owned edge return control visible. |
clipboard | always | Reads or writes the system clipboard behind a native reason prompt. |
location | always | Reads the current position behind an explicit permission prompt. |
addToHomeScreen | appSession | Adds the registered app shortcut to the Drel home screen. |
Manifest declaration format
Declared in the parent manifest under capabilities_v2:
{
"action": "clipboard",
"origins": ["https://app.example.com"],
"purposeId": "paste-order-number",
"purpose": "把订单号粘贴到表单里",
"scope": "always"
}
Not available
Camera scanning, photo library, Bluetooth, microphone, speech synthesis, contacts, motion sensors, file import/export, and generic device control are rejected before dispatch. The Drel host policy blocks them even though the underlying SDK contains handler code for other hosts.
Calling an action
const bridgeAvailable = typeof window.BarkBridge?.call === 'function';
if (bridgeAvailable) {
try {
const result = await window.BarkBridge.call('clipboard', { action: 'read' });
if (result?.success) {
input.value = result.data;
}
} catch (error) {
// Fall back to manual paste or browser fallback
}
}
Always write the fallback. A page that breaks when the bridge is missing is not a valid Drel app — it must also work in a plain browser.
Runtime detection
const runtime = window.DrelRuntime; const isInstalledOffline = runtime?.isOfflinePackage === true; const bridgeVersion = Number(runtime?.bridgeVersion ?? 0);
Feature-detect; do not sniff the user agent string. The app version is not an authorization level.
Live interactive demo
The Action Demo fixture exercises every declared action, including the authorization prompt and the revocation path.