π Bridge OverviewΒΆ
Clera apps run inside a browser or WebView. The bridge is what connects your JavaScript to native device capabilities: camera, location, clipboard, and more.
You write one API call. Clera routes it to the right place depending on where the app is running.
π§ How it worksΒΆ
When you call a hardware method like app.hardware.camera(), the runtime:
Checks the current environment
Sends a request to the active bridge adapter (native or browser)
The adapter resolves or rejects the returned Promise
All hardware methods return Promises. Always use try/catch or .catch() to handle the case where the user denies permission, cancels, or is on an unsupported device.
π Bridge environmentsΒΆ
Clera detects the environment automatically at boot:
Environment |
How it is detected |
|---|---|
|
Standard web browser (default) |
|
Browser in standalone display mode |
|
|
|
|
|
|
|
|
Read the active environment at any time:
app.bridge.env; // "browser" | "pwa" | "native-ios" | "native-android" | "simulator" | "preview"
simulator and preview use the same browser implementations as browser and pwa. They are development environments only.
π Browser fallbacksΒΆ
Every hardware capability has a browser fallback using standard Web APIs. This means you can develop and test all hardware features in a desktop browser before deploying to a device.
Capability |
Browser implementation |
|---|---|
|
Web Vibration API |
|
Clipboard API |
|
Web Share API (falls back to clipboard if unavailable) |
|
|
|
Geolocation API |
|
|
|
Anchor element download |
π€ Checking capabilitiesΒΆ
Before using a capability, you can check whether it is available in the current environment:
app.capabilities;
// {
// "hardware.vibrate": true,
// "hardware.clipboard": true,
// "hardware.share": true,
// "hardware.camera": true,
// "hardware.location": true,
// "hardware.files.pick": true,
// "hardware.files.save": true
// }
hardware.camera, hardware.files.pick, and hardware.files.save are always true because file input and anchor download are universally available. The others depend on the current environment and browser support.
β οΈ Error handlingΒΆ
All capabilities return Promises. Always handle rejections:
try {
const photo = await app.hardware.camera();
showPhoto(photo.uri);
} catch (error) {
showError("Camera not available: " + error.message);
}
The user may deny permission, cancel the picker, or be on a device that does not support the feature. An unhandled rejection will surface as an uncaught Promise error.
π± Native packagingΒΆ
Clera apps run inside iOS and Android WebViews. Use Clera Studio or Clera Packager to build and package your app for native distribution.
If you are writing your app in .clera files, Clera Studio handles transpilation automatically as part of the build process. You do not need to run the transpiler separately before packaging.