🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@capacitor-community/privacy-screen

Package Overview
Dependencies
Maintainers
42
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor-community/privacy-screen

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

6.0.0
latest
Source
npm
Version published
Maintainers
42
Created
Source


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.

Keywords

capacitor

FAQs

Package last updated on 28 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts