Skip to main content

Using Napacitor in a Web Project

Napacitor runs anywhere a modern browser does: in the browser, plugins transparently fall back to their web implementations (web.ts) with the same API surface, so the same code runs during development, in the native app, and in any web deployment.

This page states exactly which plugins support the web, based on a review of each plugin's web.ts.

Browser Support​

Napacitor core and plugins build for ES2017. This newer JavaScript syntax is supported in all modern browsers, but will not work in IE11 without additional JavaScript transformations, e.g. with Babel.

Plugins with web support perform feature detection and throw exceptions if a browser does not support a particular Web API.

Web support matrix​

PluginWeb statusNotes
@napacitor/deviceFullUA/vendor based; platform is web
@napacitor/batteryFullBattery Status API (navigator.getBattery); throws where unsupported
@napacitor/connectivityFullnavigator.onLine + online/offline events
@napacitor/dialogFullNative browser alert/confirm/prompt
@napacitor/emailFullmailto: links
@napacitor/hapticsFullVibration API; silent no-op where unsupported
@napacitor/preferencesFulllocalStorage with key prefixing
@napacitor/smsFullsms: links
@napacitor/phone-dialerFulltel: links
@napacitor/appPartialLifecycle mapped to visibilitychange; exitApp() throws
@napacitor/app-infoPartialopenSettings() throws
@napacitor/app-launcherPartialopenApp() throws (no package launching in browsers)
@napacitor/browserPartialopen/close via window.open; browser events unsupported
@napacitor/clipboardPartialText only; image write throws
@napacitor/geolocationPartialgetCurrentPosition works; permission methods are stubs
@napacitor/motionPartialAccelerometer/gyroscope via DeviceMotionEvent; magnetometer/barometer throw
@napacitor/sharePartialWeb Share API; throws where navigator.share is missing
@napacitor/action-sheetNative onlyThrows in the browser
@napacitor/app-actionsNative onlyThrows in the browser
@napacitor/file-viewerNative onlyThrows in the browser
@napacitor/flashlightNative onlyThrows in the browser

Unsupported methods reject with a NapacitorException carrying code NOT_IMPLEMENTED (see the Web API reference). Guard with Napacitor.isPluginAvailable(name) or try/catch where behavior differs per platform.

Installation​

If you're already building with Napacitor for a native platform, there are no additional installation steps!

Otherwise, see the Installation guide before continuing.

Using Napacitor as a Module​

Most commonly, apps will be using a framework with a build system that supports importing JavaScript modules. By importing from @napacitor/core, or by importing a plugin, the Napacitor JavaScript runtime will be loaded with your app. In the browser, window.NapacitorNative is absent, so the web runtime is installed and plugin calls are dispatched to the registered web implementations.

Using Napacitor as a Script Include​

This option is not available. Use a JavaScript module bundler.

Going Live​

When you're ready to publish your web app and share it with the world, just upload the contents of your web assets directory.

That will contain everything you need to run your app!