Web/PWA Plugin Guide
Napacitor has a web/native compatibility layer, making it easy to build plugins that work when running natively as well as when running in the browser. The web implementation is a plain class implementing your plugin interface — no base class is required.
The Web Implementation
src/web.ts:
import type { EchoPlugin } from './definitions';
export class EchoWeb implements EchoPlugin {
async echo(options: { value: string }) {
console.log('ECHO', options);
return options;
}
}
src/index.ts wires the class via registerPlugin's web option (dynamic import keeps the web code out of native bundles):
import { registerPlugin } from '@napacitor/core';
import type { EchoPlugin } from './definitions';
const Echo = registerPlugin<EchoPlugin>('Echo', {
web: () => import('./web').then((m) => new m.EchoWeb()),
});
export * from './definitions';
export { Echo };
When the app runs in a browser, Echo.echo(...) dispatches to EchoWeb; in the MAUI host, it crosses the bridge to your C# implementation.
Calling Other Web APIs
For functionality only available in the browser, implement it directly in EchoWeb using standard Web APIs (Battery Status, Screen Orientation, Clipboard, etc.). For example, the Battery plugin's web implementation wraps navigator.getBattery() and rejects with a plain Error when the API is missing.
Native-only Methods
If a method has no meaningful web implementation, do not define it on the web class — or throw. Calls that reach the native bridge with no implementation reject with a NapacitorException carrying code NOT_IMPLEMENTED. Apps can guard with Napacitor.isPluginAvailable() or try/catch (see the Web API reference).
Permissions
If your plugin needs browser permissions, use the standard Web permission flows (navigator.permissions, navigator.geolocation, etc.) in EchoWeb. Napacitor core does not add a permission abstraction of its own; keep permission APIs on the interface so native and web stay in sync:
export interface PermissionStatus {
location: 'prompt' | 'granted' | 'denied';
}
export interface EchoPlugin {
checkPermissions(): Promise<PermissionStatus>;
requestPermissions(): Promise<PermissionStatus>;
}