@wrnexus/mobile
SSR-safe compatibility access to Capacitor plugins.
bun add @wrnexus/mobile@0.2.15SSR-safe access to Capacitor plugins from WRNexusJS browser code.
wrnexus mobile add @capacitor/camera
import { Camera } from "@capacitor/camera";
import { mobile } from "@wrnexus/mobile";
if (mobile.isNative()) {
mobile.registerPlugin("Camera", Camera);
const photo = await mobile.invoke("Camera", "getPhoto", { resultType: "uri" });
}
isNative() is false and platform() is web during SSR. plugin() returns undefined when unavailable; requirePlugin() and invoke() throw an actionable MobileUnavailableError.
Import and register Capacitor packages only from browser-owned code. Do not import them in server routes, SSR helpers, or other Bun-only modules.
Complete TypeScript API
This declaration is generated from the exact published package and lists its exported functions, classes, interfaces, and types.
export { native } from '@wrnexus/native';
/** @wrnexus/mobile — SSR-safe access to Capacitor's native bridge. */
type MobilePlatform = "ios" | "android" | "web" | string;
interface CapacitorBridge {
isNativePlatform?: () => boolean;
getPlatform?: () => MobilePlatform;
Plugins?: Record<string, unknown>;
}
declare class MobileUnavailableError extends Error {
constructor(message?: string);
}
/** Register a plugin imported by browser-only application code. */
declare function registerPlugin<T extends object>(name: string, instance: T): T;
/** True only inside a native Capacitor iOS or Android WebView. SSR-safe. */
declare function isNative(): boolean;
/** Current Capacitor platform, falling back to `web` during SSR and in browsers. */
declare function platform(): MobilePlatform;
/** Return an injected Capacitor plugin, or undefined when it is unavailable. */
declare function plugin<T extends object>(name: string): T | undefined;
/** Require an installed native plugin and produce a useful error when absent. */
declare function requirePlugin<T extends object>(name: string): T;
/** Invoke a plugin method without importing native code into an SSR module. */
declare function invoke<TResult = unknown>(pluginName: string, method: string, options?: unknown): Promise<TResult>;
/** Run native behavior when available, with an optional SSR/web fallback. */
declare function whenNative<T>(native: () => T | Promise<T>, fallback?: () => T | Promise<T>): Promise<T | undefined>;
declare const mobile: {
isNative: typeof isNative;
platform: typeof platform;
registerPlugin: typeof registerPlugin;
plugin: typeof plugin;
requirePlugin: typeof requirePlugin;
invoke: typeof invoke;
whenNative: typeof whenNative;
};
export { type CapacitorBridge, type MobilePlatform, MobileUnavailableError, invoke, isNative, mobile, platform, plugin, registerPlugin, requirePlugin, whenNative };
Examples
Copy-ready examples taken from this package's published documentation.
Example 1
wrnexus mobile add @capacitor/cameraExample 2
import { Camera } from "@capacitor/camera";
import { mobile } from "@wrnexus/mobile";
if (mobile.isNative()) {
mobile.registerPlugin("Camera", Camera);
const photo = await mobile.invoke("Camera", "getPhoto", { resultType: "uri" });
}