Skip to content

Repository files navigation

@rdlabo/capacitor-screenshot-event

npm version License: MIT

Notify your Capacitor app after the user takes a screenshot.

Use the event for post-capture guidance or in-app UI updates (for example a toast or analytics log). The notification arrives after a screenshot is taken; it does not protect or blur content before capture.

Full documentation: https://docs.rdlabo.dev/projects/capacitor-screenshot-event

Install

npm install @rdlabo/capacitor-screenshot-event
npx cap sync

Usage

See ScreenshotEvent to register a listener, start watching, confirm one physical screenshot on a device, then stop and remove the handle.

Register a listener, start watching, take a screenshot on a physical device, then stop watching and remove the handle when leaving or destroying the screen:

import { ScreenshotEvent } from '@rdlabo/capacitor-screenshot-event';
import type { PluginListenerHandle } from '@capacitor/core';

let handle: PluginListenerHandle | undefined;

const start = async () => {
  if (handle) return;
  handle = await ScreenshotEvent.addListener('userDidTakeScreenshot', () => {
    console.log('Screenshot was taken');
  });

  await ScreenshotEvent.startWatchEvent();
};

const stop = async () => {
  await ScreenshotEvent.removeWatchEvent();
  await handle?.remove();
  handle = undefined;
};

Platform notes

  • iOS: Uses the UIApplication.userDidTakeScreenshotNotification notification.
  • Android (8.0.0): Watches FileObserver.CREATE on the fixed path Pictures/Screenshots/ under external storage. Detection depends on screenshots being saved to that directory; it is not a MediaStore change observer and is not guaranteed on every Android device or OEM gallery path.
  • Web: Not supported because browsers do not expose screenshot events.

API

startWatchEvent()

startWatchEvent() => Promise<void>

removeWatchEvent()

removeWatchEvent() => Promise<void>

addListener('userDidTakeScreenshot', ...)

addListener(eventName: 'userDidTakeScreenshot', listenerFunc: () => void) => Promise<PluginListenerHandle>
Param Type
eventName 'userDidTakeScreenshot'
listenerFunc () => void

Returns: Promise<PluginListenerHandle>


Interfaces

PluginListenerHandle

Prop Type
remove () => Promise<void>

Prerelease channels

An open, non-draft pull request can be published to the npm beta dist-tag after its Validation and Package Candidate workflows pass. A repository owner or maintainer must add a comment whose entire body is:

/beta

The request authorizes only the pull request head SHA that existed when the comment was added. The workflow revalidates the owner or maintainer permission and head SHA immediately before publishing. Any new commit requires CI to pass again and a fresh owner or maintainer /beta comment. Fork pull requests are supported. Pull requests that change a release-gating workflow cannot be beta-published until those workflow changes land on main.

Beta versions use <base>-beta.pr<PR number>.sha<12-character SHA>. The candidate is built in a read-only workflow without npm publishing credentials. The privileged release workflow publishes only the validated immutable package artifact with lifecycle scripts disabled. A notification failure cannot invalidate a successful npm publish.

When a pull request is merged into main, it is automatically published to beta only after the required CI and Package Candidate succeed for that exact merge commit. Direct pushes to main do not publish a candidate.

Only npm run release creates a release tag. Stable vX.Y.Z tags publish to npm latest; revision/prerelease tags publish to next. Neither beta nor next publishing changes the npm latest dist-tag.

Maintainers

License

This project is licensed under the MIT License.

About

Notification that user shot screenshot

Resources

Contributing

Security policy

Stars

17 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages