• Version 5.7.1
  • Published
  • 291 kB
  • 1 dependency
  • MIT license


npm i @capacitor/core
yarn add @capacitor/core
pnpm add @capacitor/core


Capacitor: Cross-platform apps with JavaScript and the web



variable Capacitor

const Capacitor: CapacitorGlobal;

    variable CapacitorCookies

    const CapacitorCookies: CapacitorCookiesPlugin;

      variable CapacitorHttp

      const CapacitorHttp: CapacitorHttpPlugin;

        variable CapacitorPlatforms

        const CapacitorPlatforms: CapacitorPlatformsInstance;
        • Deprecated

          Set CapacitorCustomPlatform on the window object prior to runtime executing in the web app instead

        variable Plugins

        const Plugins: PluginRegistry;
        • Deprecated

          Provided for backwards compatibility for Capacitor v2 plugins. Capacitor v3 plugins should import the plugin directly. This "Plugins" export is deprecated in v3, and will be removed in v4.

        variable registerPlugin

        const registerPlugin: RegisterPlugin;

          variable WebView

          const WebView: WebViewPlugin;


            function addPlatform

            addPlatform: (name: string, platform: CapacitorPlatform) => void;
            • Deprecated

              Set CapacitorCustomPlatform on the window object prior to runtime executing in the web app instead

            function buildRequestInit

            buildRequestInit: (options: HttpOptions, extra?: RequestInit) => RequestInit;
            • Build the RequestInit object based on the options passed into the initial request

              Parameter options

              The Http plugin options

              Parameter extra

              Any extra RequestInit values

            function registerWebPlugin

            registerWebPlugin: (plugin: WebPlugin) => void;
            • Provided for backwards compatibility. Use the registerPlugin() API instead, and provide the web plugin as the "web" implmenetation. For example

              export const Example = registerPlugin('Example', { web: () => import('./web').then(m => new m.Example()) })


              Deprecated in v3, will be removed from v4.

            function setPlatform

            setPlatform: (name: string) => void;
            • Deprecated

              Set CapacitorCustomPlatform on the window object prior to runtime executing in the web app instead


            class CapacitorException

            class CapacitorException extends Error {}


              constructor(message: string, code?: ExceptionCode, data?: ExceptionData);

                property code

                readonly code?: ExceptionCode;

                  property data

                  readonly data?: ExceptionData;

                    property message

                    readonly message: string;

                      class WebPlugin

                      class WebPlugin implements Plugin {}
                      • Base class web plugins should extend.


                      constructor(config?: WebPluginConfig);

                        property config

                        config?: WebPluginConfig;
                        • Deprecated

                          WebPluginConfig deprecated in v3 and will be removed in v4.

                        property listeners

                        protected listeners: { [eventName: string]: ListenerCallback[] };

                          property windowListeners

                          protected windowListeners: { [eventName: string]: WindowListenerHandle };

                            method addListener

                            addListener: (
                            eventName: string,
                            listenerFunc: ListenerCallback
                            ) => Promise<PluginListenerHandle> & PluginListenerHandle;

                              method hasListeners

                              protected hasListeners: (eventName: string) => boolean;

                                method notifyListeners

                                protected notifyListeners: (eventName: string, data: any) => void;

                                  method registerWindowListener

                                  protected registerWindowListener: (
                                  windowEventName: string,
                                  pluginEventName: string
                                  ) => void;

                                    method removeAllListeners

                                    removeAllListeners: () => Promise<void>;

                                      method unavailable

                                      protected unavailable: (msg?: string) => CapacitorException;

                                        method unimplemented

                                        protected unimplemented: (msg?: string) => CapacitorException;


                                          interface CancellableCallback

                                          interface CancellableCallback {}
                                          • CancellableCallback is a simple wrapper that a method will return to make it easy to cancel any repeated callback the method might have set up. For example: a geolocation watch.


                                          property cancel

                                          cancel: (...args: any[]) => any;
                                          • The cancel function for this method


                                          interface CapacitorGlobal

                                          interface CapacitorGlobal {}

                                            property addListener

                                            addListener?: (
                                            pluginName: string,
                                            eventName: string,
                                            callback: PluginCallback
                                            ) => PluginListenerHandle;
                                            • Add a listener for a plugin event.

                                            property convertFileSrc

                                            convertFileSrc: (filePath: string) => string;
                                            • Utility function to convert a file path into a usable src depending on the native WebView implementation value and environment.

                                            property DEBUG

                                            DEBUG?: boolean;

                                              property Exception

                                              Exception: typeof CapacitorException;
                                              • The Exception class used when generating plugin Exceptions from bridge calls.

                                              property getPlatform

                                              getPlatform: () => string;
                                              • Gets the name of the platform, such as android, ios, or web.

                                              property isLoggingEnabled

                                              isLoggingEnabled?: boolean;

                                                property isNative

                                                isNative?: boolean;
                                                • Deprecated

                                                  Use isNativePlatform() instead

                                                property isNativePlatform

                                                isNativePlatform: () => boolean;
                                                • Boolean if the platform is native or not. android and ios would return true, otherwise false.

                                                property isPluginAvailable

                                                isPluginAvailable: (name: string) => boolean;
                                                • Used to check if a platform is registered and available.

                                                property platform

                                                platform?: string;
                                                • Deprecated

                                                  Use getPlatform() instead

                                                property pluginMethodNoop

                                                pluginMethodNoop: (
                                                target: any,
                                                key: PropertyKey,
                                                pluginName: string
                                                ) => Promise<never>;
                                                • Called when a plugin method is not available. Defaults to console logging a warning. Provided for backwards compatibility.


                                                  Deprecated in v3, will be removed from v4

                                                property Plugins

                                                Plugins: PluginRegistry;
                                                • Deprecated

                                                  Plugins should be imported instead. Deprecated in v3 and Capacitor.Plugins property definition will not be exported in v4.

                                                property registerPlugin

                                                registerPlugin: RegisterPlugin;

                                                  property removeListener

                                                  removeListener?: (
                                                  pluginName: string,
                                                  callbackId: string,
                                                  eventName: string,
                                                  callback: PluginCallback
                                                  ) => void;
                                                  • Remove a listener to a plugin event.

                                                  interface HttpHeaders

                                                  interface HttpHeaders {}

                                                    index signature

                                                    [key: string]: string;

                                                      interface HttpOptions

                                                      interface HttpOptions {}

                                                        property connectTimeout

                                                        connectTimeout?: number;
                                                        • How long to wait for the initial connection.

                                                        property data

                                                        data?: any;
                                                        • Note: On Android and iOS, data can only be a string or a JSON. FormData, Blob, ArrayBuffer, and other complex types are only directly supported on web or through enabling CapacitorHttp in the config and using the patched window.fetch or XMLHttpRequest.

                                                          If you need to send a complex type, you should serialize the data to base64 and set the headers["Content-Type"] and dataType attributes accordingly.

                                                        property dataType

                                                        dataType?: 'file' | 'formData';
                                                        • This is used if we've had to convert the data from a JS type that needs special handling in the native layer

                                                        property disableRedirects

                                                        disableRedirects?: boolean;
                                                        • Sets whether automatic HTTP redirects should be disabled

                                                        property headers

                                                        headers?: HttpHeaders;

                                                          property method

                                                          method?: string;

                                                            property params

                                                            params?: HttpParams;

                                                              property readTimeout

                                                              readTimeout?: number;
                                                              • How long to wait to read additional data. Resets each time new data is received

                                                              property responseType

                                                              responseType?: HttpResponseType;
                                                              • This is used to parse the response appropriately before returning it to the requestee. If the response content-type is "json", this value is ignored.

                                                              property shouldEncodeUrlParams

                                                              shouldEncodeUrlParams?: boolean;
                                                              • Use this option if you need to keep the URL unencoded in certain cases (already encoded, azure/firebase testing, etc.). The default is _true_.

                                                              property url

                                                              url: string;

                                                                property webFetchExtra

                                                                webFetchExtra?: RequestInit;
                                                                • Extra arguments for fetch when running on the web

                                                                interface HttpParams

                                                                interface HttpParams {}

                                                                  index signature

                                                                  [key: string]: string | string[];

                                                                    interface HttpResponse

                                                                    interface HttpResponse {}

                                                                      property data

                                                                      data: any;

                                                                        property headers

                                                                        headers: HttpHeaders;

                                                                          property status

                                                                          status: number;

                                                                            property url

                                                                            url: string;

                                                                              interface Plugin

                                                                              interface Plugin {}

                                                                                method addListener

                                                                                addListener: (
                                                                                eventName: string,
                                                                                listenerFunc: (...args: any[]) => any
                                                                                ) => Promise<PluginListenerHandle>;

                                                                                  method removeAllListeners

                                                                                  removeAllListeners: () => Promise<void>;

                                                                                    interface PluginConfig

                                                                                    interface PluginConfig {}
                                                                                    • Deprecated

                                                                                    property id

                                                                                    id: string;

                                                                                      property name

                                                                                      name: string;

                                                                                        interface PluginListenerHandle

                                                                                        interface PluginListenerHandle {}

                                                                                          property remove

                                                                                          remove: () => Promise<void>;

                                                                                            interface PluginRegistry

                                                                                            interface PluginRegistry {}
                                                                                            • Deprecated

                                                                                            index signature

                                                                                            [pluginName: string]: {
                                                                                            [prop: string]: any;

                                                                                              interface PluginResultData

                                                                                              interface PluginResultData {}

                                                                                                index signature

                                                                                                [key: string]: any;

                                                                                                  interface PluginResultError

                                                                                                  interface PluginResultError {}

                                                                                                    property message

                                                                                                    message: string;

                                                                                                      interface WebPluginConfig

                                                                                                      interface WebPluginConfig {}
                                                                                                      • Deprecated

                                                                                                        Deprecated in v3, removing in v4.

                                                                                                      property name

                                                                                                      readonly name: string;
                                                                                                      • Deprecated

                                                                                                        Deprecated in v3, removing in v4.

                                                                                                      property platforms

                                                                                                      platforms?: string[];
                                                                                                      • Deprecated

                                                                                                        Deprecated in v3, removing in v4.

                                                                                                      interface WebViewPath

                                                                                                      interface WebViewPath {}

                                                                                                        property path

                                                                                                        path: string;

                                                                                                          interface WebViewPlugin

                                                                                                          interface WebViewPlugin extends Plugin {}
                                                                                                          • ****** WEB VIEW PLUGIN *******

                                                                                                          method getServerBasePath

                                                                                                          getServerBasePath: () => Promise<WebViewPath>;

                                                                                                            method persistServerBasePath

                                                                                                            persistServerBasePath: () => Promise<void>;

                                                                                                              method setServerAssetPath

                                                                                                              setServerAssetPath: (options: WebViewPath) => Promise<void>;

                                                                                                                method setServerBasePath

                                                                                                                setServerBasePath: (options: WebViewPath) => Promise<void>;


                                                                                                                  enum ExceptionCode

                                                                                                                  enum ExceptionCode {
                                                                                                                  Unimplemented = 'UNIMPLEMENTED',
                                                                                                                  Unavailable = 'UNAVAILABLE',

                                                                                                                    member Unavailable

                                                                                                                    Unavailable = 'UNAVAILABLE'
                                                                                                                    • API is not available.

                                                                                                                      This means the API can't be used right now because: - it is currently missing a prerequisite, such as network connectivity - it requires a particular platform or browser version

                                                                                                                    member Unimplemented

                                                                                                                    Unimplemented = 'UNIMPLEMENTED'
                                                                                                                    • API is not implemented.

                                                                                                                      This usually means the API can't be used because it is not implemented for the current platform.

                                                                                                                    Type Aliases

                                                                                                                    type CallbackID

                                                                                                                    type CallbackID = string;
                                                                                                                    • Deprecated

                                                                                                                    type ClearCookieOptions

                                                                                                                    type ClearCookieOptions = Omit<HttpCookie, 'key' | 'value'>;

                                                                                                                      type DeleteCookieOptions

                                                                                                                      type DeleteCookieOptions = Omit<HttpCookie, 'value'>;

                                                                                                                        type HttpResponseType

                                                                                                                        type HttpResponseType = 'arraybuffer' | 'blob' | 'json' | 'text' | 'document';

                                                                                                                          type ISODateString

                                                                                                                          type ISODateString = string;
                                                                                                                          • Deprecated

                                                                                                                          type ListenerCallback

                                                                                                                          type ListenerCallback = (err: any, ...args: any[]) => void;

                                                                                                                            type PermissionState

                                                                                                                            type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';

                                                                                                                              type PluginCallback

                                                                                                                              type PluginCallback = (data: PluginResultData, error?: PluginResultError) => void;

                                                                                                                                type PluginImplementations

                                                                                                                                type PluginImplementations = {
                                                                                                                                [platform: string]: (() => Promise<any>) | any;
                                                                                                                                • A map of plugin implementations.

                                                                                                                                  Each key should be the lowercased platform name as recognized by Capacitor, e.g. 'android', 'ios', and 'web'. Each value must be an instance of a plugin implementation for the respective platform.

                                                                                                                                type SetCookieOptions

                                                                                                                                type SetCookieOptions = HttpCookie & HttpCookieExtras;

                                                                                                                                  Package Files (8)

                                                                                                                                  Dependencies (1)

                                                                                                                                  Dev Dependencies (10)

                                                                                                                                  Peer Dependencies (0)

                                                                                                                                  No peer dependencies.


                                                                                                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@capacitor/core.

                                                                                                                                  • Markdown
                                                                                                                                  • HTML
                                                                                                                                    <a href="https://www.jsdocs.io/package/@capacitor/core"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>