@capacitor-community/privacy-screen

中文文档
8.0.0发布于 2026/04/28MITTypeScriptESM + CJS零依赖近 30 天下载 8.7万

Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.

原始使用文档
文档目录19 节
  1. Privacy Screen
  2. Introduction
  3. Using the Camera Plugin
  4. Maintainers
  5. Installation
  6. Configuration
  7. Examples
  8. Demo
  9. Usage
  10. API
  11. enable()
  12. disable()
  13. addListener('screenRecordingStarted', ...)
  14. addListener('screenRecordingStopped', ...)
  15. addListener('screenshotTaken', ...)
  16. removeAllListeners()
  17. Interfaces
  18. Changelog
  19. License

[!WARNING] This plugin is in maintenance mode. It will only receive critical bug fixes and security updates. New features will not be added. Please consider using the official Capacitor Privacy Screen Plugin instead, which is available since Capacitor 7.


Privacy Screen

@capacitor-community/privacy-screen

Capacitor Privacy Screen Plugin


Introduction

⚡️ Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.

On Android, this plugin sets the FLAG_SECURE flag to treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.
On iOS, this plugin hides the webview window when the app is no longer active and loses focus (UIApplicationWillResignActiveNotification) so that a gray screen is shown instead. It also prevents screenshots (a black screen will be captured).

Using the Camera Plugin

Disabling screenshots can interfere with plugins that hide the WebView like the Camera plugin. To avoid issues call disable before using a plugin and then enable after you are finished.

Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

npm install @capacitor-community/privacy-screen
npx cap sync

Configuration

These configuration values are available:

PropTypeDescriptionDefaultSince
enablebooleanConfigure whether the plugin should be enabled from startup. Only available for Android and iOS.true
imageNamestringConfigure whether the plugin should display a custom image from assets instead of a default background gray for the privacy screen. Only available for iOS.""
contentMode'center' | 'scaleToFill' | 'scaleAspectFit' | 'scaleAspectFill'Configure the content mode of displayed image. Only available for iOS."center"
preventScreenshotsbooleanConfigure whether the plugin should prevent screenshots if enabled. Only available for iOS.true5.2.0

Examples

In capacitor.config.json:

{
  "plugins": {
    "PrivacyScreen": {
      "enable": true,
      "imageName": "Splashscreen",
      "contentMode": "scaleAspectFit",
      "preventScreenshots": false
    }
  }
}

In capacitor.config.ts:

/// <reference types="@capacitor-community/privacy-screen" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    PrivacyScreen: {
      enable: true,
      imageName: "Splashscreen",
      contentMode: "scaleAspectFit",
      preventScreenshots: false,
    },
  },
};

export default config;

Demo

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

Usage

The plugin only needs to be installed. The protection is enabled by default.
However, you have the option to enable/disable the protection:

import { PrivacyScreen } from '@capacitor-community/privacy-screen';

const enable = async () => {
  await PrivacyScreen.enable();
};

const disable = async () => {
  await PrivacyScreen.disable();
};

API

enable()

enable() => Promise<void>

Enables the privacy screen protection.

Only available for Android and iOS.

Since: 1.1.0


disable()

disable() => Promise<void>

Disables the privacy screen protection.

Only available for Android and iOS.

Since: 1.1.0


addListener('screenRecordingStarted', ...)

addListener(eventName: 'screenRecordingStarted', listenerFunc: () => void) => Promise<PluginListenerHandle>

Called when the screen recording is started.

Only available on iOS for now.

ParamType
eventName'screenRecordingStarted'
listenerFunc() => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.2


addListener('screenRecordingStopped', ...)

addListener(eventName: 'screenRecordingStopped', listenerFunc: () => void) => Promise<PluginListenerHandle>

Called when the screen recording is stopped.

Only available on iOS for now.

ParamType
eventName'screenRecordingStopped'
listenerFunc() => void

Returns: Promise<PluginListenerHandle>

Since: 3.0.2


addListener('screenshotTaken', ...)

addListener(eventName: 'screenshotTaken', listenerFunc: () => void) => Promise<PluginListenerHandle>

Called when the screenshot is taken.

Only available on iOS for now.

ParamType
eventName'screenshotTaken'
listenerFunc() => void

Returns: Promise<PluginListenerHandle>

Since: 3.2.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 3.0.2


Interfaces

PluginListenerHandle

PropType
remove() => Promise<void>

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capacitor-community/privacy-screen 共发布 41 个版本,首次发布于 2021/01/22;过去 12 个月发布了 2 个版本。

版本发布日期距今
8.0.0latest2026/04/286 个月前
6.1.02026/04/087 个月前
6.0.02025/01/291.8 年前
5.2.1-dev.11d7af3.1738003749dev2025/01/281.8 年前
5.2.12024/08/162 年前
5.2.02024/08/122 年前

关于 @capacitor-community/privacy-screen 的常见问题

@capacitor-community/privacy-screen 是什么?

Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.

如何安装 @capacitor-community/privacy-screen?

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

@capacitor-community/privacy-screen 支持 TypeScript 吗?

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

@capacitor-community/privacy-screen 支持 ESM 还是 CommonJS?

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

@capacitor-community/privacy-screen 可以商用吗?

@capacitor-community/privacy-screen 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-community/privacy-screen 的下载量有多少?

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

@capacitor-community/privacy-screen 还在维护吗?

最新版本 8.0.0 发布于 2026/04/28(6 个月前);至今共发布 41 个版本,其中过去 12 个月发布了 2 个;首次发布于 2021/01/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。