
Copyguard-js is a lightweight JavaScript utility that blocks copying, pasting, cutting, and right-clicking to protect web content from unauthorized access.
Features:
- Copy Protection: Blocks Ctrl+C and Cmd+C keyboard combinations across all browsers.
- Paste Prevention: Disables Ctrl+V and Cmd+V to prevent content insertion into protected areas.
- Cut Blocking: Prevents Ctrl+X and Cmd+X operations that could remove and copy content simultaneously.
- Context Menu Disabling: Removes right-click functionality to prevent access to browser copy options.
- Violation Callbacks: Optional onViolation handler for logging or custom responses to blocked actions.
- Zero Dependencies: Pure JavaScript implementation without external library requirements.
How to use it:
1. Install and import Copyguard into your project.
# NPM $ npm install copyguard-js
import Copyguard from 'copyguard-js';
2. Or directly load the copyguard.min.js script from dist folder.
<script src="/dist/copyguard.min.js"></script>
3. Enable all protections by default.
Copyguard.enable();
4. Enable/disable protections.
Copyguard.enable({
blockCopy: true,
blockPaste: true,
blockCut: true,
blockRightClick: false,
});5. Trigger a function when blocked action occurs. This callback receives the action type ('copy', 'paste', 'cut', 'contextmenu') as an argument. Defaults to null.
Copyguard.enable({
onViolation(type) {
// `${type.toUpperCase()} was blocked.`;
}
});6. Remove all event listeners and disables protection mechanisms.
Copyguard.disable();
FAQs
Q: Does this actually prevent content from being copied?
A: No client-side solution can truly prevent determined users from copying content. This blocks standard user interactions but won’t stop someone viewing source, using developer tools, or taking screenshots.
Q: Will this negatively impact accessibility?
A: Absolutely. Blocking copy, paste, and context menu functionality can create significant barriers for users who rely on assistive technologies like screen readers or need to copy text for translation or other purposes. You must weigh the need for content protection against the impact on user experience and accessibility. I would not recommend using this on a public-facing site where accessibility is a primary concern.







