Drel/Docs/Bridge API
Reference · native actions

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
1App identityThe page was opened as an ordinary URL, not from a registered application.
2Exact declarationThe signed manifest's capabilities_v2 does not declare that action for that origin.
3Origin matchThe page origin is not in the declared origin list, compared exactly (scheme://host:port).
4Foreground gestureNo recent user touch event consumed the call (blocks background automation).
5Grant ledgerNo stored grant covers this gateway, app, origin, and action tuple.
6Native promptThe user cancels or rejects the native permission sheet.
Declaration is not consent. A manifest entry is an allowlist. It never substitutes for the user's decision, and it never widens what a page can reach.

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
hapticappSessionBrief tactile feedback following a user tap.
vibrateappSessionBrief, bounded vibration.
shareappSessionOpens the native iOS share sheet; the user inspects content and picks the destination.
fullscreenappSessionHides host chrome while keeping a host-owned edge return control visible.
clipboardalwaysReads or writes the system clipboard behind a native reason prompt.
locationalwaysReads the current position behind an explicit permission prompt.
addToHomeScreenappSessionAdds 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.