Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: improve screenshot protection

Marc Seitz8d187e1e8249
diff --git a/components/view/ScreenProtection.tsx b/components/view/ScreenProtection.tsx
index 432b9f81..45379db0 100644
--- a/components/view/ScreenProtection.tsx
+++ b/components/view/ScreenProtection.tsx
@@ -8,11 +8,77 @@ import { Button } from "@/components/ui/button";
export const ScreenProtector = () => {
const [blockScreen, setBlockScreen] = useState<boolean>(false);
- // Key combinations for screenshot in Windows, Linux, and macOS
- useHotkeys("meta+shift, alt, printscreen", (event) => {
+ // Comprehensive screenshot prevention for all major platforms
+ const handleScreenshotAttempt = (event: KeyboardEvent) => {
setBlockScreen(true);
event.preventDefault();
- });
+ event.stopPropagation();
+ };
+
+ // Windows screenshot shortcuts
+ useHotkeys(
+ [
+ "printscreen", // PrintScreen key
+ "alt+printscreen", // Alt + PrintScreen (active window)
+ "meta+printscreen", // Win + PrintScreen (save to file)
+ "meta+shift+s", // Win + Shift + S (Snipping Tool)
+ "meta+g", // Win + G (Game Bar)
+ ],
+ handleScreenshotAttempt,
+ {
+ preventDefault: true,
+ enableOnFormTags: true,
+ enableOnContentEditable: true,
+ },
+ );
+
+ // macOS screenshot shortcuts
+ useHotkeys(
+ [
+ "meta+shirt",
+ "meta+shift+3", // Cmd + Shift + 3 (full screen)
+ "meta+shift+4", // Cmd + Shift + 4 (selection)
+ "meta+shift+5", // Cmd + Shift + 5 (screenshot utility)
+ "meta+shift+4+space", // Cmd + Shift + 4 + Space (window)
+ ],
+ handleScreenshotAttempt,
+ {
+ preventDefault: true,
+ enableOnFormTags: true,
+ enableOnContentEditable: true,
+ },
+ );
+
+ // Linux screenshot shortcuts
+ useHotkeys(
+ [
+ "shift+printscreen", // Shift + PrintScreen (selection in some Linux distros)
+ "ctrl+alt+printscreen", // Ctrl + Alt + PrintScreen (some Linux distros)
+ ],
+ handleScreenshotAttempt,
+ {
+ preventDefault: true,
+ enableOnFormTags: true,
+ enableOnContentEditable: true,
+ },
+ );
+
+ // Developer tools that could be used for screenshots
+ useHotkeys(
+ [
+ "f12", // F12 (Developer Tools)
+ "ctrl+shift+i", // Ctrl + Shift + I (Developer Tools)
+ "meta+alt+i", // Cmd + Option + I (macOS Developer Tools)
+ "ctrl+shift+c", // Ctrl + Shift + C (Inspect Element)
+ "meta+alt+c", // Cmd + Option + C (macOS Inspect Element)
+ ],
+ handleScreenshotAttempt,
+ {
+ preventDefault: true,
+ enableOnFormTags: true,
+ enableOnContentEditable: true,
+ },
+ );
if (blockScreen) {
return (