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
npm install @rdlabo/capacitor-screenshot-event
npx cap syncSee 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;
};- iOS: Uses the
UIApplication.userDidTakeScreenshotNotificationnotification. - Android (8.0.0): Watches
FileObserver.CREATEon the fixed pathPictures/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.
startWatchEvent() => Promise<void>removeWatchEvent() => Promise<void>addListener(eventName: 'userDidTakeScreenshot', listenerFunc: () => void) => Promise<PluginListenerHandle>| Param | Type |
|---|---|
eventName |
'userDidTakeScreenshot' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
| Prop | Type |
|---|---|
remove |
() => Promise<void> |
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.
This project is licensed under the MIT License.