https://github.com/capacitor-community/privacy-screen
⚡️ Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.
https://github.com/capacitor-community/privacy-screen
android capacitor capacitor-community capacitor-plugin ios
Last synced: about 1 year ago
JSON representation
⚡️ Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.
- Host: GitHub
- URL: https://github.com/capacitor-community/privacy-screen
- Owner: capacitor-community
- License: mit
- Created: 2021-01-16T09:40:39.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-28T21:34:00.000Z (over 1 year ago)
- Last Synced: 2025-05-07T09:44:23.449Z (about 1 year ago)
- Topics: android, capacitor, capacitor-community, capacitor-plugin, ios
- Language: Swift
- Homepage:
- Size: 778 KB
- Stars: 94
- Watchers: 8
- Forks: 26
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-capacitorjs - @capacitor-community/privacy-screen - Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher. (Plugins / Community Plugins)
- awesome-capacitor - Privacy screen - Protects your app from displaying a screenshot in recents screen/App Switcher. (Community plugins)
README

Privacy Screen
@capacitor-community/privacy-screen
Capacitor Privacy Screen Plugin
## Introduction
⚡️ [Capacitor](https://capacitorjs.com/) plugin that protects your app from displaying a screenshot in [Recents screen](https://developer.android.com/guide/components/activities/recents)/[App Switcher](https://support.apple.com/en-us/HT202070).
On **Android**, this plugin sets the [FLAG_SECURE](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#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](https://developer.apple.com/documentation/uikit/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
| Maintainer | GitHub | Social |
| ---------- | ----------------------------------------- | --------------------------------------------- |
| Robin Genz | [robingenz](https://github.com/robingenz) | [@robin_genz](https://twitter.com/robin_genz) |
## Installation
```
npm install @capacitor-community/privacy-screen
npx cap sync
```
## Configuration
These configuration values are available:
| Prop | Type | Description | Default | Since |
| ------------------------ | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
| **`enable`** | boolean | Configure whether the plugin should be enabled from startup. Only available for Android and iOS. | true | |
| **`imageName`** | string | Configure 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" | |
| **`preventScreenshots`** | boolean | Configure whether the plugin should prevent screenshots if enabled. Only available for iOS. | true | 5.2.0 |
### Examples
In `capacitor.config.json`:
```json
{
"plugins": {
"PrivacyScreen": {
"enable": true,
"imageName": "Splashscreen",
"contentMode": "scaleAspectFit",
"preventScreenshots": false
}
}
}
```
In `capacitor.config.ts`:
```ts
///
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](https://github.com/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:
```js
import { PrivacyScreen } from '@capacitor-community/privacy-screen';
const enable = async () => {
await PrivacyScreen.enable();
};
const disable = async () => {
await PrivacyScreen.disable();
};
```
## API
* [`enable()`](#enable)
* [`disable()`](#disable)
* [`addListener('screenRecordingStarted', ...)`](#addlistenerscreenrecordingstarted-)
* [`addListener('screenRecordingStopped', ...)`](#addlistenerscreenrecordingstopped-)
* [`addListener('screenshotTaken', ...)`](#addlistenerscreenshottaken-)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
### enable()
```typescript
enable() => Promise
```
Enables the privacy screen protection.
Only available for Android and iOS.
**Since:** 1.1.0
--------------------
### disable()
```typescript
disable() => Promise
```
Disables the privacy screen protection.
Only available for Android and iOS.
**Since:** 1.1.0
--------------------
### addListener('screenRecordingStarted', ...)
```typescript
addListener(eventName: 'screenRecordingStarted', listenerFunc: () => void) => Promise
```
Called when the screen recording is started.
Only available on iOS for now.
| Param | Type |
| ------------------ | ------------------------------------- |
| **`eventName`** | 'screenRecordingStarted' |
| **`listenerFunc`** | () => void |
**Returns:** Promise<PluginListenerHandle>
**Since:** 3.0.2
--------------------
### addListener('screenRecordingStopped', ...)
```typescript
addListener(eventName: 'screenRecordingStopped', listenerFunc: () => void) => Promise
```
Called when the screen recording is stopped.
Only available on iOS for now.
| Param | Type |
| ------------------ | ------------------------------------- |
| **`eventName`** | 'screenRecordingStopped' |
| **`listenerFunc`** | () => void |
**Returns:** Promise<PluginListenerHandle>
**Since:** 3.0.2
--------------------
### addListener('screenshotTaken', ...)
```typescript
addListener(eventName: 'screenshotTaken', listenerFunc: () => void) => Promise
```
Called when the screenshot is taken.
Only available on iOS for now.
| Param | Type |
| ------------------ | ------------------------------ |
| **`eventName`** | 'screenshotTaken' |
| **`listenerFunc`** | () => void |
**Returns:** Promise<PluginListenerHandle>
**Since:** 3.2.0
--------------------
### removeAllListeners()
```typescript
removeAllListeners() => Promise
```
Remove all listeners for this plugin.
**Since:** 3.0.2
--------------------
### Interfaces
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | () => Promise<void> |
## Changelog
See [CHANGELOG.md](https://github.com/capacitor-community/privacy-screen/blob/main/CHANGELOG.md).
## License
See [LICENSE](https://github.com/capacitor-community/privacy-screen/blob/main/LICENSE).