Detect features

Check whether a feature is switched on in this app build before you show its UI.

Check one feature

Ask whether this build has a feature switched on. has is true only then — the right check before you show the UI.

import { createBdkNative } from "@bdk/native/browser";

const bdk = createBdkNative();

if (await bdk.capabilities.has("media")) {
  showPhotoPicker();
}

Read the full map

Read every feature this build reports — enabled, available, and config per id — plus platform and the app version. Pass timeoutMs to wait that many milliseconds. get resolves null when the answer isn't known: a plain browser, an older app build, or a slow start. null is not off.

Don't treat null as off. Wait for bdk.ready() and call get again.

let caps = await bdk.capabilities.get();

if (!caps) {
  await bdk.ready(3000);
  caps = await bdk.capabilities.get();
}

if (!caps) {
  // Still unknown — not off.
} else {
  const media = caps.features.media;
  console.log(caps.platform, caps.app?.versionName, media);
}

Interpret the states

enabled, available, and a null map are three different answers.

  • Missing from features, or enabled is not true — not in this build. Hide the UI.
  • enabled is true and available is false — in this build, but unusable on this device right now.
  • get() returned null — unknown. Don't treat it as off. Wait for bdk.ready() and try again.

When a feature is off

A call to a switched-off feature resolves ok: false with code: "common/feature_disabled". Branch on !result.ok. Each feature page names its id.

In a plain browser the call resolves ok: false with a code such as common/feature_disabled. Branch on !result.ok.

const result = await bdk.media.pickPhotos();

if (!result.ok) {
  if (result.code === "common/feature_disabled") {
    // This build doesn't have it.
    return;
  }
  console.error(result.code, result.message);
  return;
}