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
| Plugin | Web status | Notes |
|---|---|---|
@napacitor/device | Full | UA/vendor based; platform is web |
@napacitor/battery | Full | Battery Status API (navigator.getBattery); throws where unsupported |
@napacitor/connectivity | Full | navigator.onLine + online/offline events |
@napacitor/dialog | Full | Native browser alert/confirm/prompt |
@napacitor/email | Full | mailto: links |
@napacitor/haptics | Full | Vibration API; silent no-op where unsupported |
@napacitor/preferences | Full | localStorage with key prefixing |
@napacitor/sms | Full | sms: links |
@napacitor/phone-dialer | Full | tel: links |
@napacitor/app | Partial | Lifecycle mapped to visibilitychange; exitApp() throws |
@napacitor/app-info | Partial | openSettings() throws |
@napacitor/app-launcher | Partial | openApp() throws (no package launching in browsers) |
@napacitor/browser | Partial | open/close via window.open; browser events unsupported |
@napacitor/clipboard | Partial | Text only; image write throws |
@napacitor/geolocation | Partial | getCurrentPosition works; permission methods are stubs |
@napacitor/motion | Partial | Accelerometer/gyroscope via DeviceMotionEvent; magnetometer/barometer throw |
@napacitor/share | Partial | Web Share API; throws where navigator.share is missing |
@napacitor/action-sheet | Native only | Throws in the browser |
@napacitor/app-actions | Native only | Throws in the browser |
@napacitor/file-viewer | Native only | Throws in the browser |
@napacitor/flashlight | Native only | Throws 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!