A lightweight JavaScript utility to block copying, pasting, cutting, and right-clicking.
copyguard-js provides a simple, framework-free way to prevent users from copying content, opening the context menu, or pasting into inputs. It can be used to secure form fields, protect sensitive data, or discourage content scraping.
- 🔒 Block
Ctrl+C(Copy),Ctrl+V(Paste),Ctrl+X(Cut) - 🖱️ Disable right-click (context menu)
- 🧠 Optional
onViolationcallback for custom behavior/logging - 🪶 Zero dependencies
npm install copyguard-jsThen in your JavaScript:
import Copyguard from 'copyguard-js';
Copyguard.enable({
blockCopy: true,
blockPaste: true,
blockCut: true,
blockRightClick: true,
onViolation: (type) => {
console.warn(`Blocked: ${type}`);
}
});<script src="https://unpkg.com/copyguard-js@latest/dist/copyguard.min.js"></script>
<script>
Copyguard.enable({
onViolation: (type) => {
alert(`🚫 ${type} blocked`);
}
});
</script>Copyguard.enable({
blockCopy: true,
blockPaste: true,
blockCut: true,
blockRightClick: true,
onViolation: (action) => {
console.log(`User tried to: ${action}`);
}
});
// To disable protection:
Copyguard.disable();View a demo at: https://coreyadam8.github.io/copyguard
MIT License © Corey Adam