Free Use Bible API
Guide
Reference
SDKs
Seed Bible
GitHub
Support
  • English
  • Afrikaans
  • አማርኛ
  • العربية
  • বাংলা
  • Deutsch
  • Español
  • Français
  • Hausa
  • हिन्दी
  • Bahasa Indonesia
  • Italiano
  • 日本語
  • Português
  • Русский
  • Kiswahili
  • اردو
  • 简体中文
  • isiZulu
Guide
Reference
SDKs
Seed Bible
GitHub
Support
  • English
  • Afrikaans
  • አማርኛ
  • العربية
  • বাংলা
  • Deutsch
  • Español
  • Français
  • Hausa
  • हिन्दी
  • Bahasa Indonesia
  • Italiano
  • 日本語
  • Português
  • Русский
  • Kiswahili
  • اردو
  • 简体中文
  • isiZulu
  • Seed Bible
  • Guides
    • Developer Guide
    • Extension API
    • Security Model
  • API Reference (v1.18.0)
    • seed-bible/extensions
      • Classes

        • SandboxError
      • Interfaces

        • SandboxBook
        • SandboxChapter
        • SandboxChapterRef
        • SandboxChatMessage
        • SandboxChatRequest
        • SandboxCommentary
        • SandboxCommentaryBook
        • SandboxCommentaryChapter
        • SandboxCommentaryProfile
        • SandboxContext
        • SandboxDataset
        • SandboxDatasetBook
        • SandboxDatasetChapter
        • SandboxDatasetReference
        • SandboxDiscoverRequest
        • SandboxExtensionDefinition
        • SandboxFootnote
        • SandboxFriend
        • SandboxHighlight
        • SandboxNote
        • SandboxPaneHandle
        • SandboxPaneOptions
        • SandboxPlayback
        • SandboxPortalHandle
        • SandboxPortalOptions
        • SandboxProfile
        • SandboxReadingEvent
        • SandboxReadingPosition
        • SandboxReference
        • SandboxSave
        • SandboxSearchQuery
        • SandboxSearchResult
        • SandboxSearchResults
        • SandboxSelectedVerse
        • SandboxSessionParticipant
        • SandboxSharedSession
        • SandboxToolHandle
        • SandboxToolItemOptions
        • SandboxToolOptions
        • SandboxToolSelectContext
        • SandboxTranslation
        • SandboxVerseRef
        • SandboxViewProps
      • Type Aliases

        • SandboxCasualOSPattern
        • SandboxChapterContent
        • SandboxDiscoverResult
        • SandboxExtension
        • SandboxIcon
        • SandboxJsonValue
        • SandboxPermission
        • SandboxTitle
      • Variables

        • SANDBOX_PERMISSION_INFO
        • SANDBOX_PERMISSIONS
      • Functions

        • createSandboxClient
        • defineExtension
      • Unexported types
        • Interfaces

          • ChapterRef
          • SandboxInit
          • SandboxPermissionInfo
          • SandboxState
        • Type Aliases

          • SandboxErrorCode
          • SandboxFrameMode
          • SandboxPanePlacement
          • ToolFlag
    • seed-bible/extensions/testing
      • Interfaces

        • TestCall
        • TestHost
        • TestHostOptions
        • TestPane
      • Type Aliases

        • TestAnswer
      • Functions

        • createTestHost
      • Unexported types
        • Interfaces

          • SandboxCapture
          • SandboxMethods
          • SandboxToolDefinition
          • SandboxToolItem
        • Type Aliases

          • SandboxMethod
          • SandboxToolPatch
          • SandboxToolSurface
    • seed-bible/components
      • Interfaces

        • BottomSheetExpansion
        • BottomSheetProps
        • MaterialIconProps
        • PortalComponentHandle
        • PortalComponentProps
        • SearchBarProps
        • TranslationListProps
      • Type Aliases

        • ButtonProps
        • ButtonShape
        • ButtonSize
        • ButtonTone
        • ButtonVariant
        • CasualOSPattern
        • CloseButtonLook
        • CloseButtonSize
        • ContextMenuTriggerProps
        • ContextMenuWithButtonProps
        • IconButtonLook
        • IconButtonProps
        • IconButtonSize
        • SkeletonShape
      • Variables

        • AddIcon
        • AddTab
        • AiChatIcon
        • AiIcon
        • ApologistIcon
        • AskIcon
        • BibleIcon
        • BookmarkIcon
        • BookOutlineIcon
        • BurgerMenuIcon
        • CalendarStarIcon
        • ChatParticipantsIcon
        • ClientLogo
        • ColorSelect
        • CommunityIcon
        • CopyIcon
        • DiscordIcon
        • DonateIcon
        • DualScreenIcon
        • EditIcon
        • Eraser
        • ExtensionsIcon
        • FiltersIcon
        • FolderIcon
        • FormatLine
        • GoPrivateIcon
        • HighlightIcon
        • InfoSettingsIcon
        • JoinSession
        • LoadSpace
        • MarginIcon
        • MarginXIcon
        • MarginYIcon
        • MaterialIcon
        • MenuDown
        • MenuIcon
        • MinusIcon
        • MoreIcon
        • OpenFolderIcon
        • Panal
        • Panel1
        • Panel2
        • Panel3
        • Panel3Row
        • Panel4
        • Panel4Row
        • Playlist
        • PortalComponent
        • QuadScreenIcon
        • SbTabsIcon
        • SelectedIcon
        • SelectionUIIcon
        • SettingsIcon
        • ShareIcon
        • SingleScreenIcon
        • Space
        • SpaceDefaultIcon
        • SplitScreenIcon
        • StarIcon
        • StartSessionIcon
        • SupportIcon
        • T
        • TabsIcon
        • ThemeIcon
        • ThreeScreenIcon
        • TickIcon
        • TodayIcon
        • ToolbarIcon
        • UserAvatar
      • Functions

        • BottomSheet
        • Button
        • CloseButton
        • ContextMenuItem
        • ContextMenuWithButton
        • ExpandableText
        • IconButton
        • InstallAppsIcon
        • PlaylistLinkContent
        • SafariIcon
        • ScriptureLineHeightIcon
        • SearchBar
        • SeedBibleIcon
        • SeedBibleWordmark
        • Skeleton
        • SkeletonContainer
        • StopIcon
        • TranslationList
        • TranslationViewModeMenu
        • useDragReorder
      • Unexported types
        • Interfaces

          • Translation
          • TranslationLanguageGroup
          • UseDragReorderOptions
        • Type Aliases

          • CloseButtonProps
          • SvgIconProps
          • TranslationViewMode

Seed Bible extension API (v1.18.0) / seed-bible/extensions / SandboxContext

Interface: SandboxContext

The API a sandboxed extension uses to reach Seed Bible, handed to main and to every view as sb.

Each method sends a message to the app, which checks it against the permissions the user granted, so nearly all of them return a promise that rejects with a SandboxError when refused. Values that change while the extension runs are signals: read .value, inside a component or an effect, to follow them.

Some calls are marked "Main code only": they reject with invalid_request when called from a view. Some are marked "Only right after the user interacts with this extension": call them from a tool's onSelect or a click in one of your views, or they reject with invalid_request.

Full reference: docs/extension-api.md in the seed-bible repository.

Properties

app

app: {
  isMobile: ReadonlySignal<boolean>;
  toast: (message: string) => Promise<void>;
};

The app itself.

isMobile

isMobile: ReadonlySignal<boolean>;

Whether the app is in its phone layout.

toast

toast: (message: string) => Promise<void>;

Shows a short message (1–300 characters), prefixed with this extension's name.

Parameters
ParameterType
messagestring
Returns

Promise<void>


audio

audio: {
  narrators: (ref: ChapterRef) => Promise<string[]>;
  pause: () => Promise<void>;
  play: (url: string) => Promise<{
    finished: boolean;
  }>;
  playback: ReadonlySignal<SandboxPlayback | null>;
  playNarration: (
    ref: ChapterRef & {
      reader?: string;
    },
  ) => Promise<{
    finished: boolean;
  }>;
  readAloud: (
    ref: ChapterRef & {
      fromVerse?: number;
      toVerse?: number;
    },
  ) => Promise<{
    finished: boolean;
  }>;
  resume: () => Promise<void>;
  seek: (position: number) => Promise<void>;
  stop: () => Promise<void>;
};

The app's audio player: what's played here shows in the reader's playback controls for the tab in view, where the user can pause, scrub and stop it, and it pauses whatever else the app was playing. One thing at a time; playing another replaces it. Needs audio:playback.

Starting or resuming playback only works right after the user interacts with this extension. Each play… resolves when playback ends: finished is false if it was stopped (by stop(), the user, something else playing there, or the tab closing) rather than played to the end. Calls reject with unavailable when no reader is open to play in.

narrators

narrators: (ref: ChapterRef) => Promise<string[]>;

Who has recorded narration for a chapter; empty when no one has.

Parameters
ParameterType
refChapterRef
Returns

Promise<string[]>

pause

pause: () => Promise<void>;

Pauses what this extension is playing.

Returns

Promise<void>

play

play: (url: string) => Promise<{
  finished: boolean;
}>;

An audio file from one of the manifest's network hosts (https:).

Parameters
ParameterType
urlstring
Returns

Promise<{ finished: boolean; }>

playback

playback: ReadonlySignal<SandboxPlayback | null>;

What this extension is playing; null when nothing is.

playNarration

playNarration: (
  ref: ChapterRef & {
    reader?: string;
  },
) => Promise<{
  finished: boolean;
}>;

The app's recorded narration of a chapter, by reader (see narrators), or the first there is. Rejects with not_found when the chapter has none; fall back to readAloud.

Parameters
ParameterType
refChapterRef & { reader?: string; }
Returns

Promise<{ finished: boolean; }>

readAloud

readAloud: (
  ref: ChapterRef & {
    fromVerse?: number;
    toVerse?: number;
  },
) => Promise<{
  finished: boolean;
}>;

Reads a chapter, or verses fromVerse to toVerse of it, with the app's text-to-speech.

Parameters
ParameterType
refChapterRef & { fromVerse?: number; toVerse?: number; }
Returns

Promise<{ finished: boolean; }>

resume

resume: () => Promise<void>;

Resumes it. Only right after the user interacts with this extension.

Returns

Promise<void>

seek

seek: (position: number) => Promise<void>;

Seconds, or for readAloud, a verse index.

Parameters
ParameterType
positionnumber
Returns

Promise<void>

stop

stop: () => Promise<void>;

Stops what this extension is playing; its play… resolves unfinished.

Returns

Promise<void>


bible

bible: {
  books: (ref: { translationId: string }) => Promise<{
    books: SandboxBook[];
    translation: SandboxTranslation;
  }>;
  chapter: (ref: {
    bookId: string;
    chapter: number;
    translationId: string;
  }) => Promise<SandboxChapter>;
  commentaries: () => Promise<SandboxCommentary[]>;
  commentaryBooks: (ref: { commentaryId: string }) => Promise<{
    books: SandboxCommentaryBook[];
    commentary: SandboxCommentary;
  }>;
  commentaryChapter: (ref: {
    bookId: string;
    chapter: number;
    commentaryId: string;
  }) => Promise<SandboxCommentaryChapter>;
  commentaryProfile: (ref: {
    commentaryId: string;
    profileId: string;
  }) => Promise<
    SandboxCommentaryProfile & {
      content: string[];
    }
  >;
  commentaryProfiles: (ref: {
    commentaryId: string;
  }) => Promise<SandboxCommentaryProfile[]>;
  datasetBooks: (ref: { datasetId: string }) => Promise<{
    books: SandboxDatasetBook[];
    dataset: SandboxDataset;
  }>;
  datasetChapter: (ref: {
    bookId: string;
    chapter: number;
    datasetId: string;
  }) => Promise<SandboxDatasetChapter>;
  datasets: () => Promise<SandboxDataset[]>;
  search: (query: SandboxSearchQuery) => Promise<SandboxSearchResults>;
  translations: () => Promise<SandboxTranslation[]>;
};

Public Bible text, commentaries and datasets from the Free Use Bible API. Needs no permission.

Translations the user has downloaded are read from their device, so with no connection translations, books and chapter still answer for those. Commentaries and datasets always need a connection. A call that can't be answered rejects with unavailable.

books

books: (ref: { translationId: string }) => Promise<{
  books: SandboxBook[];
  translation: SandboxTranslation;
}>;

A translation's books, in its order.

Parameters
ParameterType
ref{ translationId: string; }
ref.translationIdstring
Returns

Promise<{ books: SandboxBook[]; translation: SandboxTranslation; }>

chapter

chapter: (ref: {
  bookId: string;
  chapter: number;
  translationId: string;
}) => Promise<SandboxChapter>;

A chapter: each verse as plain text in verses, and headings, breaks and footnotes in content and footnotes for laying it out.

Parameters
ParameterType
ref{ bookId: string; chapter: number; translationId: string; }
ref.bookIdstring
ref.chapternumber
ref.translationIdstring
Returns

Promise<SandboxChapter>

Example
const { verses, next } = await sb.bible.chapter({
  translationId: "BSB",
  bookId: "JHN",
  chapter: 3,
});

commentaries

commentaries: () => Promise<SandboxCommentary[]>;

Every commentary available.

Returns

Promise<SandboxCommentary[]>

commentaryBooks

commentaryBooks: (ref: { commentaryId: string }) => Promise<{
  books: SandboxCommentaryBook[];
  commentary: SandboxCommentary;
}>;

The books a commentary covers.

Parameters
ParameterType
ref{ commentaryId: string; }
ref.commentaryIdstring
Returns

Promise<{ books: SandboxCommentaryBook[]; commentary: SandboxCommentary; }>

commentaryChapter

commentaryChapter: (ref: {
  bookId: string;
  chapter: number;
  commentaryId: string;
}) => Promise<SandboxCommentaryChapter>;

A commentary's notes on a chapter.

Parameters
ParameterType
ref{ bookId: string; chapter: number; commentaryId: string; }
ref.bookIdstring
ref.chapternumber
ref.commentaryIdstring
Returns

Promise<SandboxCommentaryChapter>

commentaryProfile

commentaryProfile: (ref: {
  commentaryId: string;
  profileId: string;
}) => Promise<
  SandboxCommentaryProfile & {
    content: string[];
  }
>;

One of those articles, as paragraphs of plain text.

Parameters
ParameterType
ref{ commentaryId: string; profileId: string; }
ref.commentaryIdstring
ref.profileIdstring
Returns

Promise<SandboxCommentaryProfile & { content: string[]; }>

commentaryProfiles

commentaryProfiles: (ref: {
  commentaryId: string;
}) => Promise<SandboxCommentaryProfile[]>;

A commentary's articles about people, places and topics.

Parameters
ParameterType
ref{ commentaryId: string; }
ref.commentaryIdstring
Returns

Promise<SandboxCommentaryProfile[]>

datasetBooks

datasetBooks: (ref: { datasetId: string }) => Promise<{
  books: SandboxDatasetBook[];
  dataset: SandboxDataset;
}>;

The books a dataset covers.

Parameters
ParameterType
ref{ datasetId: string; }
ref.datasetIdstring
Returns

Promise<{ books: SandboxDatasetBook[]; dataset: SandboxDataset; }>

datasetChapter

datasetChapter: (ref: {
  bookId: string;
  chapter: number;
  datasetId: string;
}) => Promise<SandboxDatasetChapter>;

A dataset's entries for a chapter.

Parameters
ParameterType
ref{ bookId: string; chapter: number; datasetId: string; }
ref.bookIdstring
ref.chapternumber
ref.datasetIdstring
Returns

Promise<SandboxDatasetChapter>

Example
const { verses } = await sb.bible.datasetChapter({
  datasetId: "open-cross-ref",
  bookId: "JHN",
  chapter: 3,
});

datasets

datasets: () => Promise<SandboxDataset[]>;

Every dataset available, such as cross-references.

Returns

Promise<SandboxDataset[]>

search

search: (query: SandboxSearchQuery) => Promise<SandboxSearchResults>;

Finds verses in a translation by words or by reference, a page at a time, best match first. Needs a connection.

Parameters
ParameterType
querySandboxSearchQuery
Returns

Promise<SandboxSearchResults>

Example
const { results, found } = await sb.bible.search({
  translationId: "BSB",
  query: "living water",
  bookId: "JHN",
});

translations

translations: () => Promise<SandboxTranslation[]>;

Every translation the user can pick from. Offline, the ones the app already knows about, with downloaded marking those that can be read.

Returns

Promise<SandboxTranslation[]>


chats

chats: {
  registerProvider: (provider: {
    id: string;
    name: string;
    respond: (
      request: SandboxChatRequest,
    ) => string | Promise<string | null> | null;
    shared?: boolean;
  }) => Promise<{
    unregister: () => Promise<void>;
  }>;
};

A chat participant. Needs chat:respond; shared: true also needs chat:shared. Main code only.

registerProvider

registerProvider: (provider: {
  id: string;
  name: string;
  respond: (
    request: SandboxChatRequest,
  ) => string | Promise<string | null> | null;
  shared?: boolean;
}) => Promise<{
  unregister: () => Promise<void>;
}>;

Adds a participant the user can add to their chats. It only sees the chats it's added to. respond has 60 seconds to answer; past that, or if it throws, it says nothing that time.

Parameters
ParameterTypeDescription
provider{ id: string; name: string; respond: (request: SandboxChatRequest) => string | Promise<string | null> | null; shared?: boolean; }-
provider.idstringUnique within this extension.
provider.namestringShown as the participant's name; up to 100 characters.
provider.respond(request: SandboxChatRequest) => string | Promise<string | null> | nullReturns the reply (one whole message, up to 20,000 characters shown), or null to stay quiet. Gets the last 100 text messages.
provider.shared?booleanMay be added to chats with other people. Needs chat:shared.
Returns

Promise<{ unregister: () => Promise<void>; }>


clipboard

clipboard: {
  writeText: (text: string) => Promise<void>;
};

Needs clipboard:write. Only right after the user interacts with this extension.

writeText

writeText: (text: string) => Promise<void>;

Copies up to 100,000 characters of text.

Parameters
ParameterType
textstring
Returns

Promise<void>


devices

devices: {
  recordAudio: (options?: { maxSeconds?: number }) => Promise<Blob | null>;
  takePhoto: () => Promise<Blob | null>;
};

The microphone and camera, through a dialog the host shows: the user sees which extension is asking, presses the button themselves, and the extension gets only the result. Only right after the user interacts with this extension, one dialog at a time. Each resolves null if the user cancels, and rejects with unavailable if the device can't be used.

recordAudio

recordAudio: (options?: { maxSeconds?: number }) => Promise<Blob | null>;

Needs device:microphone. At most maxSeconds (default 60, up to 300).

Parameters
ParameterType
options?{ maxSeconds?: number; }
options.maxSeconds?number
Returns

Promise<Blob | null>

takePhoto

takePhoto: () => Promise<Blob | null>;

Needs device:camera. A JPEG.

Returns

Promise<Blob | null>


discover

discover: {
  registerProvider: (provider: {
    description: string;
    discover: (
      request: SandboxDiscoverRequest,
    ) => SandboxDiscoverResult[] | Promise<SandboxDiscoverResult[]>;
    id: string;
    onSelect?: (resultId: string) => void;
    title: string;
  }) => Promise<{
    unregister: () => Promise<void>;
  }>;
};

Content for the Discover panel. Registering needs reading:position, since a provider is told which chapter is open. Main code only.

registerProvider

registerProvider: (provider: {
  description: string;
  discover: (
    request: SandboxDiscoverRequest,
  ) => SandboxDiscoverResult[] | Promise<SandboxDiscoverResult[]>;
  id: string;
  onSelect?: (resultId: string) => void;
  title: string;
}) => Promise<{
  unregister: () => Promise<void>;
}>;

Adds a provider the Discover panel asks for results whenever it needs them. discover must answer within 5 seconds with up to 50 results; otherwise, or if it throws, the provider shows nothing that time.

Parameters
ParameterTypeDescription
provider{ description: string; discover: (request: SandboxDiscoverRequest) => | SandboxDiscoverResult[] | Promise<SandboxDiscoverResult[]>; id: string; onSelect?: (resultId: string) => void; title: string; }-
provider.descriptionstringUp to 300 characters.
provider.discover(request: SandboxDiscoverRequest) => | SandboxDiscoverResult[] | Promise<SandboxDiscoverResult[]>Returns results for the chapter in request, as data.
provider.idstringUnique within this extension.
provider.onSelect?(resultId: string) => voidCalled with a content result's id when the user picks it. Not a user interaction, so open a pane from it rather than a dialog.
provider.titlestringUp to 100 characters.
Returns

Promise<{ unregister: () => Promise<void>; }>


extensionId

extensionId: string;

The id Seed Bible knows this extension by: the folder its bundle is hosted in, #, and the id from extension.json, like https://example.com/extensions/#verse-art.


friends

friends: {
  list: () => Promise<SandboxFriend[]>;
};

Needs friends:read. Empty when signed out. Ids are pseudonymous like identity: a friend's id here is their own identity in this extension.

list

list: () => Promise<SandboxFriend[]>;
Returns

Promise<SandboxFriend[]>


highlights

highlights: {
  add: (
    ref: ChapterRef & {
      colorId: string;
      verses: number[];
    },
  ) => Promise<void>;
  colors: () => Promise<string[]>;
  list: (ref: ChapterRef) => Promise<SandboxHighlight[]>;
  remove: (
    ref: ChapterRef & {
      verses: number[];
    },
  ) => Promise<void>;
};

Reading needs highlights:read; adding and removing, highlights:write.

add

add: (
  ref: ChapterRef & {
    colorId: string;
    verses: number[];
  },
) => Promise<void>;

Highlights 1–200 verses in one of colors(); any other colorId rejects with invalid_request. Needs highlights:write.

Parameters
ParameterType
refChapterRef & { colorId: string; verses: number[]; }
Returns

Promise<void>

colors

colors: () => Promise<string[]>;

The highlight color ids the current theme has, for add's colorId. Needs no permission.

Returns

Promise<string[]>

list

list: (ref: ChapterRef) => Promise<SandboxHighlight[]>;

The chapter's highlights. Needs highlights:read.

Parameters
ParameterType
refChapterRef
Returns

Promise<SandboxHighlight[]>

remove

remove: (
  ref: ChapterRef & {
    verses: number[];
  },
) => Promise<void>;

Removes the highlight from those verses. Needs highlights:write.

Parameters
ParameterType
refChapterRef & { verses: number[]; }
Returns

Promise<void>


history

history: {
  list: (range: {
    from: number;
    to: number;
  }) => Promise<SandboxReadingEvent[]>;
};

Needs reading:history. Times in ms since the epoch, at most a year apart.

list

list: (range: { from: number; to: number }) => Promise<SandboxReadingEvent[]>;

The chapters the user read between from and to, one event per sitting, up to 5,000.

Parameters
ParameterType
range{ from: number; to: number; }
range.fromnumber
range.tonumber
Returns

Promise<SandboxReadingEvent[]>

Example
const lastWeek = await sb.history.list({
  from: Date.now() - 7 * 24 * 60 * 60 * 1000,
  to: Date.now(),
});

i18n

i18n: {
  direction: ReadonlySignal<"ltr" | "rtl">;
  language: ReadonlySignal<string>;
  t: (
    key: string,
    defaultValue?: string,
    values?: Record<string, string | number>,
  ) => string;
};

The extension's own translations, from extension.json.

direction

direction: ReadonlySignal<"ltr" | "rtl">;

The current language's text direction. Already set on <html>.

language

language: ReadonlySignal<string>;

The app's current language code, like "en" or "es".

t

t: (
  key: string,
  defaultValue?: string,
  values?: Record<string, string | number>,
) => string;

Looks key up in this extension's own extension.json translations for the current language (falling back to en, then defaultValue, then key), and fills {{name}} placeholders from values.

Parameters
ParameterType
keystring
defaultValue?string
values?Record<string, string | number>
Returns

string

Example
sb.i18n.t("found", "Found {{count}} verses", { count: 3 });

identity

identity: ReadonlySignal<string | null>;

An id for the signed-in user that's the same every time for this extension but different for every extension, and isn't their real id. Null when signed out. Needs no permission. A friend's or session participant's id is that person's identity in this extension.


modals

modals: {
  alert: (dialog: { message: string; title: string }) => Promise<void>;
  open: (dialog: {
    props?: SandboxJsonValue;
    title: string;
    view: string;
  }) => Promise<void>;
};

Dialogs, titled with the extension's name. Only right after the user interacts with this extension, one at a time (limit_exceeded otherwise). Each resolves when it's closed.

alert

alert: (dialog: { message: string; title: string }) => Promise<void>;

A message (up to 2,000 characters) with an OK button.

Parameters
ParameterType
dialog{ message: string; title: string; }
dialog.messagestring
dialog.titlestring
Returns

Promise<void>

open

open: (dialog: {
  props?: SandboxJsonValue;
  title: string;
  view: string;
}) => Promise<void>;

One of your views, shown with surface: "modal".

Parameters
ParameterType
dialog{ props?: SandboxJsonValue; title: string; view: string; }
dialog.props?SandboxJsonValue
dialog.titlestring
dialog.viewstring
Returns

Promise<void>


notes

notes: {
  create: (note: {
    bookId: string;
    chapter: number;
    text: string;
    verses?: number[];
  }) => Promise<{
    id: string;
  }>;
  delete: (note: {
    bookId: string;
    chapter: number;
    id: string;
  }) => Promise<void>;
  list: (ref: { bookId: string; chapter: number }) => Promise<SandboxNote[]>;
  update: (note: {
    bookId: string;
    chapter: number;
    id: string;
    text: string;
  }) => Promise<void>;
};

Reading needs notes:read; writing, notes:write. Notes are plain text here. An extension can only change or delete the notes it added. Writing needs the user to be signed in (unavailable otherwise).

create

create: (note: {
  bookId: string;
  chapter: number;
  text: string;
  verses?: number[];
}) => Promise<{
  id: string;
}>;

Adds a note (1–10,000 characters) on verses, or the whole chapter without them, marked as this extension's. Blank lines become paragraphs. Needs notes:write.

Parameters
ParameterType
note{ bookId: string; chapter: number; text: string; verses?: number[]; }
note.bookIdstring
note.chapternumber
note.textstring
note.verses?number[]
Returns

Promise<{ id: string; }>

delete

delete: (note: {
  bookId: string;
  chapter: number;
  id: string;
}) => Promise<void>;

Deletes a note this extension added, with the same rules as update. Needs notes:write.

Parameters
ParameterType
note{ bookId: string; chapter: number; id: string; }
note.bookIdstring
note.chapternumber
note.idstring
Returns

Promise<void>

list

list: (ref: { bookId: string; chapter: number }) => Promise<SandboxNote[]>;

The chapter's notes; empty when signed out. Needs notes:read.

Parameters
ParameterType
ref{ bookId: string; chapter: number; }
ref.bookIdstring
ref.chapternumber
Returns

Promise<SandboxNote[]>

update

update: (note: {
  bookId: string;
  chapter: number;
  id: string;
  text: string;
}) => Promise<void>;

Replaces the text of a note this extension added. permission_denied for anyone else's note; not_found if it isn't in that chapter. Needs notes:write.

Parameters
ParameterType
note{ bookId: string; chapter: number; id: string; text: string; }
note.bookIdstring
note.chapternumber
note.idstring
note.textstring
Returns

Promise<void>


panes

panes: {
  close: (paneId: string) => Promise<void>;
  open: (options: SandboxPaneOptions) => Promise<SandboxPaneHandle>;
};

Panes (the app's windows) showing one of your views. The host draws the frame: title, close button and a badge with the extension's name. At most 5 open at once, portals included.

close

close: (paneId: string) => Promise<void>;

Closes one of this extension's panes; not_found if it isn't open.

Parameters
ParameterType
paneIdstring
Returns

Promise<void>

open

open: (options: SandboxPaneOptions) => Promise<SandboxPaneHandle>;

Opens one of your views in a pane. Opening with the id of a pane that's already open replaces its content instead of opening another. Rejects with limit_exceeded past 5 open panes.

Parameters
ParameterType
optionsSandboxPaneOptions
Returns

Promise<SandboxPaneHandle>


permissions

permissions: {
  granted: ReadonlySignal<
    readonly (
      | "reading:position"
      | "reading:selection"
      | "reading:navigate"
      | "reading:history"
      | "highlights:read"
      | "highlights:write"
      | "notes:read"
      | "notes:write"
      | "saves:read"
      | "saves:write"
      | "profile:read"
      | "chat:respond"
      | "chat:shared"
      | "friends:read"
      | "session:read"
      | "audio:playback"
      | "clipboard:write"
      | "embed:casualos"
      | "device:microphone"
      | "device:camera"
    )[]
  >;
  has: (
    permission:
      | "reading:position"
      | "reading:selection"
      | "reading:navigate"
      | "reading:history"
      | "highlights:read"
      | "highlights:write"
      | "notes:read"
      | "notes:write"
      | "saves:read"
      | "saves:write"
      | "profile:read"
      | "chat:respond"
      | "chat:shared"
      | "friends:read"
      | "session:read"
      | "audio:playback"
      | "clipboard:write"
      | "embed:casualos"
      | "device:microphone"
      | "device:camera",
  ) => boolean;
  optional: readonly (
    | "reading:position"
    | "reading:selection"
    | "reading:navigate"
    | "reading:history"
    | "highlights:read"
    | "highlights:write"
    | "notes:read"
    | "notes:write"
    | "saves:read"
    | "saves:write"
    | "profile:read"
    | "chat:respond"
    | "chat:shared"
    | "friends:read"
    | "session:read"
    | "audio:playback"
    | "clipboard:write"
    | "embed:casualos"
    | "device:microphone"
    | "device:camera"
  )[];
  request: (
    permissions:
      | "reading:position"
      | "reading:selection"
      | "reading:navigate"
      | "reading:history"
      | "highlights:read"
      | "highlights:write"
      | "notes:read"
      | "notes:write"
      | "saves:read"
      | "saves:write"
      | "profile:read"
      | "chat:respond"
      | "chat:shared"
      | "friends:read"
      | "session:read"
      | "audio:playback"
      | "clipboard:write"
      | "embed:casualos"
      | "device:microphone"
      | "device:camera"
      | (
          | "reading:position"
          | "reading:selection"
          | "reading:navigate"
          | "reading:history"
          | "highlights:read"
          | "highlights:write"
          | "notes:read"
          | "notes:write"
          | "saves:read"
          | "saves:write"
          | "profile:read"
          | "chat:respond"
          | "chat:shared"
          | "friends:read"
          | "session:read"
          | "audio:playback"
          | "clipboard:write"
          | "embed:casualos"
          | "device:microphone"
          | "device:camera"
        )[],
  ) => Promise<boolean>;
};

What the user has granted, and a way to ask for optional permissions.

granted

granted: ReadonlySignal<
  readonly (
    | "reading:position"
    | "reading:selection"
    | "reading:navigate"
    | "reading:history"
    | "highlights:read"
    | "highlights:write"
    | "notes:read"
    | "notes:write"
    | "saves:read"
    | "saves:write"
    | "profile:read"
    | "chat:respond"
    | "chat:shared"
    | "friends:read"
    | "session:read"
    | "audio:playback"
    | "clipboard:write"
    | "embed:casualos"
    | "device:microphone"
    | "device:camera"
  )[]
>;

What the user has granted so far, including what those imply (highlights:write includes highlights:read).

has

has: (
  permission:
    | "reading:position"
    | "reading:selection"
    | "reading:navigate"
    | "reading:history"
    | "highlights:read"
    | "highlights:write"
    | "notes:read"
    | "notes:write"
    | "saves:read"
    | "saves:write"
    | "profile:read"
    | "chat:respond"
    | "chat:shared"
    | "friends:read"
    | "session:read"
    | "audio:playback"
    | "clipboard:write"
    | "embed:casualos"
    | "device:microphone"
    | "device:camera",
) => boolean;

Whether permission is granted right now. Check it when a feature runs, not once at startup: the user can change optional permissions in Settings (which restarts the extension).

Parameters
ParameterType
permission| "reading:position" | "reading:selection" | "reading:navigate" | "reading:history" | "highlights:read" | "highlights:write" | "notes:read" | "notes:write" | "saves:read" | "saves:write" | "profile:read" | "chat:respond" | "chat:shared" | "friends:read" | "session:read" | "audio:playback" | "clipboard:write" | "embed:casualos" | "device:microphone" | "device:camera"
Returns

boolean

optional

optional: readonly (
  | "reading:position"
  | "reading:selection"
  | "reading:navigate"
  | "reading:history"
  | "highlights:read"
  | "highlights:write"
  | "notes:read"
  | "notes:write"
  | "saves:read"
  | "saves:write"
  | "profile:read"
  | "chat:respond"
  | "chat:shared"
  | "friends:read"
  | "session:read"
  | "audio:playback"
  | "clipboard:write"
  | "embed:casualos"
  | "device:microphone"
  | "device:camera"
)[];

What extension.json lists under optionalPermissions.

request

request: (
  permissions:
    | "reading:position"
    | "reading:selection"
    | "reading:navigate"
    | "reading:history"
    | "highlights:read"
    | "highlights:write"
    | "notes:read"
    | "notes:write"
    | "saves:read"
    | "saves:write"
    | "profile:read"
    | "chat:respond"
    | "chat:shared"
    | "friends:read"
    | "session:read"
    | "audio:playback"
    | "clipboard:write"
    | "embed:casualos"
    | "device:microphone"
    | "device:camera"
    | (
        | "reading:position"
        | "reading:selection"
        | "reading:navigate"
        | "reading:history"
        | "highlights:read"
        | "highlights:write"
        | "notes:read"
        | "notes:write"
        | "saves:read"
        | "saves:write"
        | "profile:read"
        | "chat:respond"
        | "chat:shared"
        | "friends:read"
        | "session:read"
        | "audio:playback"
        | "clipboard:write"
        | "embed:casualos"
        | "device:microphone"
        | "device:camera"
      )[],
) => Promise<boolean>;

Asks the user for one or more of the extension's optionalPermissions, and resolves true if all of them are granted. Resolves true without asking when they already are, and false without asking if the user already declined one of them since the page loaded.

The user is only asked right after they interact with this extension (by selecting one of its tools, or inside one of its panes), so call it from the click handler of the feature that needs it. Otherwise it rejects with an invalid_request SandboxError, as it does for a permission not listed under optionalPermissions.

Parameters
ParameterType
permissions| "reading:position" | "reading:selection" | "reading:navigate" | "reading:history" | "highlights:read" | "highlights:write" | "notes:read" | "notes:write" | "saves:read" | "saves:write" | "profile:read" | "chat:respond" | "chat:shared" | "friends:read" | "session:read" | "audio:playback" | "clipboard:write" | "embed:casualos" | "device:microphone" | "device:camera" | ( | "reading:position" | "reading:selection" | "reading:navigate" | "reading:history" | "highlights:read" | "highlights:write" | "notes:read" | "notes:write" | "saves:read" | "saves:write" | "profile:read" | "chat:respond" | "chat:shared" | "friends:read" | "session:read" | "audio:playback" | "clipboard:write" | "embed:casualos" | "device:microphone" | "device:camera")[]
Returns

Promise<boolean>

Example
onSelect: async () => {
  if (await sb.permissions.request("clipboard:write")) {
    await sb.clipboard.writeText("John 3:16");
  }
}

portals

portals: {
  open: (options: SandboxPortalOptions) => Promise<SandboxPortalHandle>;
};

CasualOS grid and map portals (ao.bot patterns), each in a pane the host draws. Needs embed:casualos. The pattern runs on ao.bot, outside the sandbox.

open

open: (options: SandboxPortalOptions) => Promise<SandboxPortalHandle>;

Opens a portal in a pane. Counts toward the 5 open panes.

Parameters
ParameterType
optionsSandboxPortalOptions
Returns

Promise<SandboxPortalHandle>

Example
const portal = await sb.portals.open({
  pattern: { name: "my-pattern" },
  portalType: "map",
  placement: "side",
  title: "Map",
});
portal.onMessage((message) => console.log(message));

profile

profile: {
  get: () => Promise<SandboxProfile | null>;
};

Needs profile:read. Null when signed out. Includes the user's real account id; to tell users apart without it, use identity.

get

get: () => Promise<SandboxProfile | null>;
Returns

Promise<SandboxProfile | null>


reading

reading: {
  open: (ref: SandboxVerseRef) => Promise<void>;
  position: ReadonlySignal<SandboxReadingPosition | null>;
  selection: ReadonlySignal<SandboxSelectedVerse[]>;
};

What the user is reading.

open

open: (ref: SandboxVerseRef) => Promise<void>;

Moves the reader to a book and chapter, scrolled to verse if given. Needs reading:navigate.

Parameters
ParameterType
refSandboxVerseRef
Returns

Promise<void>

position

position: ReadonlySignal<SandboxReadingPosition | null>;

The passage in the reader in view; any field is null before something is open. Null unless reading:position is granted.

selection

selection: ReadonlySignal<SandboxSelectedVerse[]>;

The verses the user has selected. Empty unless reading:selection is granted.


saves

saves: {
  add: (
    save: ChapterRef & {
      categories?: string[];
      verse?: number | [number, number];
    },
  ) => Promise<void>;
  list: () => Promise<SandboxSave[]>;
  remove: (id: string) => Promise<void>;
};

Reading needs saves:read; writing, saves:write and a signed-in user.

add

add: (
  save: ChapterRef & {
    categories?: string[];
    verse?: number | [number, number];
  },
) => Promise<void>;

Saves a chapter, a verse or an inclusive [start, end] range, in up to 10 categories. Needs saves:write; unavailable when signed out.

Parameters
ParameterType
saveChapterRef & { categories?: string[]; verse?: number | [number, number]; }
Returns

Promise<void>

list

list: () => Promise<SandboxSave[]>;

Every save (bookmark) the user has. Needs saves:read.

Returns

Promise<SandboxSave[]>

remove

remove: (id: string) => Promise<void>;

Removes a save by its id; not_found if there isn't one. Needs saves:write; unavailable when signed out.

Parameters
ParameterType
idstring
Returns

Promise<void>


sensitive

sensitive: {
  fetch: (request: {
    body?: unknown;
    method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
    proxy?: string;
    url: string;
  }) => Promise<{
    body: string;
    contentType: string | null;
    ok: boolean;
    status: number;
  }>;
};

Requests that carry the user's sensitive settings, through the hosts the manifest's sensitive section declares. The values never reach the extension.

fetch

fetch: (request: {
  body?: unknown;
  method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
  proxy?: string;
  url: string;
}) => Promise<{
  body: string;
  contentType: string | null;
  ok: boolean;
  status: number;
}>;

Sends an https: request to a host the manifest's sensitive section declares, with the user's sensitive values filled in by the server. Resolves for any HTTP status, like fetch; body is the response text, up to 1 MB (limit_exceeded past that). Rejects with unavailable when it can't be sent; the message starts with why (signed_out, not_set, unknown_destination, ambiguous_destination, invalid_url or request_failed).

Parameters
ParameterTypeDescription
request{ body?: unknown; method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD"; proxy?: string; url: string; }-
request.body?unknownSent as JSON; a string is sent as-is. Ignored for GET and HEAD.
request.method?"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD"Defaults to GET.
request.proxy?stringWhich sensitive entry to use, if several declare the URL's host.
request.urlstring-
Returns

Promise<{ body: string; contentType: string | null; ok: boolean; status: number; }>

Example
const response = await sb.sensitive.fetch({
  url: "https://api.example.com/v1/lookup",
  method: "POST",
  body: { reference: "JHN 3:16" },
});
const data = response.ok ? JSON.parse(response.body) : null;

session

session: {
  current: ReadonlySignal<SandboxSharedSession | null>;
};

The shared reading session open in the current tab, kept up to date. Null when there isn't one, and always null without session:read.

current

current: ReadonlySignal<SandboxSharedSession | null>;

settings

settings: {
  get: (key: string) => Promise<string | number | boolean | null>;
  registerPanel: (view: string) => Promise<void>;
};

This extension's own (non-sensitive) settings from extension.json.

get

get: (key: string) => Promise<string | number | boolean | null>;

The setting's current value: the user's own, else the active Customization's default, else its default in extension.json, else null. Always null for a sensitive setting or an undeclared key. Not pushed on change, so read it again when you need it.

Parameters
ParameterType
keystring
Returns

Promise<string | number | boolean | null>

registerPanel

registerPanel: (view: string) => Promise<void>;

Shows one of your views as this extension's settings, on its Settings tab in Settings → Extensions, with surface: "settings". Calling it again replaces the panel. Main code only.

Parameters
ParameterType
viewstring
Returns

Promise<void>


storage

storage: {
  get: <T>(key: string) => Promise<T | null>;
  keys: () => Promise<string[]>;
  remove: (key: string) => Promise<void>;
  set: (key: string, value: SandboxJsonValue) => Promise<void>;
};

A small key/value store of this extension's own, kept by the host. A sandboxed frame has no localStorage of its own. At most 256 KB in all (limit_exceeded past that); keys up to 200 characters. Synced to the user's account while they're signed in (the later write to a key wins), kept on the device while signed out, and deleted on uninstall. Needs no permission. Don't keep secrets here: use sensitive settings.

get

get: <T>(key: string) => Promise<T | null>;

The value stored under key, or null if there isn't one.

Type Parameters
Type ParameterDefault type
T extends SandboxJsonValueSandboxJsonValue
Parameters
ParameterType
keystring
Returns

Promise<T | null>

keys

keys: () => Promise<string[]>;

Every key that's set.

Returns

Promise<string[]>

remove

remove: (key: string) => Promise<void>;

Removes key; does nothing if it isn't set.

Parameters
ParameterType
keystring
Returns

Promise<void>

set

set: (key: string, value: SandboxJsonValue) => Promise<void>;

Stores any JSON value under key, replacing what was there.

Parameters
ParameterType
keystring
valueSandboxJsonValue
Returns

Promise<void>


tools

tools: {
  registerBelowReaderTool: (
    tool: SandboxToolOptions,
  ) => Promise<SandboxToolHandle>;
  registerQuickTool: (tool: SandboxToolOptions) => Promise<SandboxToolHandle>;
  registerToolbarTool: (
    tool: SandboxToolOptions,
  ) => Promise<SandboxToolHandle>;
  registerVerseToolbarTool: (
    tool: SandboxToolOptions,
  ) => Promise<SandboxToolHandle>;
};

Buttons in the app's toolbars. Main code only. At most 20 per extension (limit_exceeded past that).

registerBelowReaderTool

registerBelowReaderTool: (
  tool: SandboxToolOptions,
) => Promise<SandboxToolHandle>;

A button below the chapter text.

Parameters
ParameterType
toolSandboxToolOptions
Returns

Promise<SandboxToolHandle>

registerQuickTool

registerQuickTool: (tool: SandboxToolOptions) => Promise<SandboxToolHandle>;

A compact icon in the row above the reader.

Parameters
ParameterType
toolSandboxToolOptions
Returns

Promise<SandboxToolHandle>

registerToolbarTool

registerToolbarTool: (tool: SandboxToolOptions) => Promise<SandboxToolHandle>;

A button in the reader's main toolbar.

Parameters
ParameterType
toolSandboxToolOptions
Returns

Promise<SandboxToolHandle>

registerVerseToolbarTool

registerVerseToolbarTool: (
  tool: SandboxToolOptions,
) => Promise<SandboxToolHandle>;

A button in the toolbar shown when the user selects verses. Its onSelect gets the selection if reading:selection is granted.

Parameters
ParameterType
toolSandboxToolOptions
Returns

Promise<SandboxToolHandle>

Example

await sb.tools.registerToolbarTool({
  id: "art",
  title: { key: "make-art", defaultValue: "Make art" },
  icon: { material: "palette" },
  onSelect: () =>
    void sb.panes.open({ view: "art", placement: "side", title: "Art" }),
});
Prev
SandboxCommentaryProfile
Next
SandboxDataset