@capacitor-firebase/functions

中文文档
8.6.0发布于 2026/10/31Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4706

Capacitor plugin for Firebase Cloud Functions on Android, iOS, and Web.

原始使用文档
文档目录28 节
  1. Use Cases
  2. Compatibility
  3. Guides
  4. Installation
  5. Android
  6. iOS
  7. Configuration
  8. Demo
  9. Usage
  10. Call a function by name
  11. Call a function by URL
  12. Use the Cloud Functions emulator
  13. API
  14. callByName(...)
  15. callByUrl(...)
  16. useEmulator(...)
  17. Interfaces
  18. Type Aliases
  19. FAQ
  20. What is the difference between callByName and callByUrl ?
  21. What data types can I pass to a callable function?
  22. How do I test my functions locally?
  23. Why do I get a SwiftPM package identity collision on iOS?
  24. Can I use this plugin with Ionic, React, Vue or Angular?
  25. Related Plugins
  26. Newsletter
  27. Changelog
  28. License

Capacitor Firebase Cloud Functions Plugin

Unofficial Capacitor plugin for Firebase Cloud Functions.[^1]

Use Cases

The Firebase Cloud Functions plugin is typically used to run backend logic from your Capacitor app without managing your own server, for example:

  • Serverless backend logic: Call callable Cloud Functions by name to run trusted server-side code from your app.
  • Structured data exchange: Pass strings, numbers, booleans, arrays, and objects to a function and process the returned result.
  • Custom domains and regions: Call functions that are deployed in a specific region or hosted on a custom domain by their URL.
  • Local development: Test your functions against the Cloud Functions emulator before deploying them to production.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated

Guides

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-firebase/functions` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capacitor-firebase/functions
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS).

Android

Variables

If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:

  • $firebaseFunctionsVersion version of com.google.firebase:firebase-functions (default: 22.1.0)

This can be useful if you encounter dependency conflicts with other plugins in your project.

iOS

Swift Package Manager

Add the following to your capacitor.config.json (or capacitor.config.ts) to avoid a SwiftPM package identity collision:

{
  "experimental": {
    "ios": {
      "spm": {
        "packageOptions": {
          "@capacitor-firebase/functions": {
            "symlink": true
          }
        }
      }
    }
  }
}

Attention: SPM packageOptions support requires Capacitor CLI 8.4.0+.

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-firebase-plugin-demo

Usage

The following examples show how to call Cloud Functions by name or by URL and how to connect to the Cloud Functions emulator.

Call a function by name

Call a callable Cloud Function by its name. You can pass strings, numbers, booleans, arrays, and objects as data and receive the result of the function in the data property. Use the region option if your function is not deployed in the default region:

import { FirebaseFunctions } from '@capacitor-firebase/functions';

const callByName = async () => {
    const { data } = await FirebaseFunctions.callByName({
        name: 'helloWorld',
        data: {
            string: 'Hello World!',
            number: 123,
            boolean: true,
            array: [1, 2, 3],
            object: {
                key: 'value'
            }
        }
    });
    return data;
};

Call a function by URL

If your callable function is hosted on a custom domain or you prefer to address it directly, call it by its URL:

import { FirebaseFunctions } from '@capacitor-firebase/functions';

const callByUrl = async () => {
    const { data } = await FirebaseFunctions.callByUrl({
        url: 'https://us-central1-YOUR_PROJECT_ID.cloudfunctions.net/helloWorld',
        data: {
            string: 'Hello World!',
            number: 123,
            boolean: true,
            array: [1, 2, 3],
            object: {
                key: 'value'
            }
        }
    });
    return data;
};

Use the Cloud Functions emulator

During development, you can instrument your app to talk to the local Cloud Functions emulator. When using an Android emulator device, 10.0.2.2 is the special IP address to connect to the localhost of the host computer. Note that on Android, the cleartext traffic must be allowed, which is not intended for use in production:

import { FirebaseFunctions } from '@capacitor-firebase/functions';

const useEmulator = async () => {
  await FirebaseFunctions.useEmulator({
    host: '10.0.2.2',
    port: 9001,
  });
};

API

callByName(...)

callByName<RequestData = unknown, ResponseData = unknown>(options: CallByNameOptions<RequestData>) => Promise<CallByNameResult<ResponseData>>

Call a callable function by name.

ParamType
optionsCallByNameOptions<RequestData>

Returns: Promise<CallByNameResult<ResponseData>>

Since: 6.1.0


callByUrl(...)

callByUrl<RequestData = unknown, ResponseData = unknown>(options: CallByUrlOptions<RequestData>) => Promise<CallByUrlResult<ResponseData>>

Call a callable function by URL.

ParamType
optionsCallByUrlOptions<RequestData>

Returns: Promise<CallByUrlResult<ResponseData>>

Since: 6.1.0


useEmulator(...)

useEmulator(options: UseEmulatorOptions) => Promise<void>

Instrument your app to talk to the Cloud Functions emulator.

On Android, the cleartext traffic must be allowed. On the Capacitor configuration:

{
  server: {
    cleartext: true
  }
}

The cleartext traffic is not intended for use in production.

ParamType
optionsUseEmulatorOptions

Since: 6.1.0


Interfaces

CallResult

PropTypeDescriptionSince
dataResponseDataThe result of the callable function.6.1.0

CallByNameOptions

PropTypeDescriptionSince
namestringThe name of the callable function.6.1.0
regionstringThe region of the callable function.6.1.0

CallByUrlOptions

PropTypeDescriptionSince
urlstringThe URL of the callable function.6.1.0

UseEmulatorOptions

PropTypeDescriptionDefaultSince
hoststringThe emulator host without any port or scheme. Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer.6.1.0
portnumberThe emulator port.50016.1.0
regionOrCustomDomainstringThe region the callable functions are located in or a custom domain hosting the callable functions.

Type Aliases

CallByNameResult

CallResult<ResponseData>

CallByUrlResult

CallResult<ResponseData>

FAQ

What is the difference between callByName and callByUrl?

The callByName(...) method calls a callable function by its name and, optionally, its region. The callByUrl(...) method calls a callable function by its full URL instead, which is useful if the function is hosted on a custom domain.

What data types can I pass to a callable function?

You can pass strings, numbers, booleans, arrays, and nested objects as data to a callable function. The result of the function is returned in the data property of the call result.

How do I test my functions locally?

Use the useEmulator(...) method to instrument your app to talk to the local Cloud Functions emulator, as shown in the usage example above. When testing on an Android emulator device, use 10.0.2.2 as the host to reach the localhost of the host computer. Keep in mind that on Android, the cleartext traffic must be allowed for this, which is not intended for use in production.

Why do I get a SwiftPM package identity collision on iOS?

This is a known issue when using the plugin with Swift Package Manager. Add the symlink package option for @capacitor-firebase/functions to your Capacitor configuration as described in the Installation section. Note that SPM packageOptions support requires Capacitor CLI 8.4.0 or later.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.

版本与发布记录

@capacitor-firebase/functions 共发布 26 个版本,首次发布于 2024/06/19;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.6.0latest2026/10/319 天前
8.5.22026/09/171 个月前
8.5.12026/09/022 个月前
8.5.02026/08/312 个月前
8.4.02026/08/122 个月前
8.3.02026/06/045 个月前

其他发布通道:dev → 8.0.1-dev.66db168.1770636703。

关于 @capacitor-firebase/functions 的常见问题

@capacitor-firebase/functions 是什么?

Capacitor plugin for Firebase Cloud Functions on Android, iOS, and Web.

如何安装 @capacitor-firebase/functions?

在项目目录运行 npm install @capacitor-firebase/functions,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-firebase/functions 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-firebase/functions 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-firebase/functions 可以商用吗?

@capacitor-firebase/functions 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-firebase/functions 的下载量有多少?

根据 npm 官方下载统计,@capacitor-firebase/functions 在 2026/10/09 – 2026/11/07 这 30 天内被下载 4,706 次,日均约 157 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-firebase/functions 还在维护吗?

最新版本 8.6.0 发布于 2026/10/31(9 天前);至今共发布 26 个版本,其中过去 12 个月发布了 14 个;首次发布于 2024/06/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。