block-inspect
v1.3.1
Published
A simple JavaScript utility to deter users from opening browser developer tools (inspect element) and disable context menus, selection, and copy/paste on a website.
Downloads
32
Maintainers
Readme
block-inspect
A lightweight, zero-dependency JavaScript utility to deter users from inspecting your website using browser developer tools, right-click, or clipboard interactions.
⚠️ Note: Possible to bypass this using advanced measures.
Features
- ❌ Disable right-click context menu
- ❌ Block DevTools shortcuts (F12, Ctrl+Shift+I/J/U, Cmd+Opt+I/J/U, etc.)
- ❌ Optional: Block copy, cut, paste
- ❌ Optional: Disable text selection
- 🔁 New: Redirect page if DevTools are opened (URL or
"back") - ✅ Optional callback on inspection attempts
- ✅ Whitelist specific key combos (e.g., "Ctrl+R" for refresh)
- ✅ Dynamic enable/disable
- ✅ No dependencies
Installation
npm install block-inspect
Usage
ES Modules
import blockInspect from 'block-inspect';
// Default
blockInspect();
// Custom options
blockInspect({
disableContextMenu: true,
disableDevToolsShortcut: true,
disableSelection: true,
disableCopy: true,
disableCut: true,
disablePaste: true,
allowedKeys: ['Ctrl+R', 'Meta+R', 'F5'],
onInspectAttempt: () => {
alert('Inspect attempt blocked!');
},
// Redirect if DevTools open or shortcut is blocked:
// - Use a URL to redirect to another page
// - Or use "back" to navigate to previous page
redirectOnInspect: 'https://example.com/warning.html'
// redirectOnInspect: 'back',
});
Stop, Resume, Update
blockInspect.stop(); // Disable
blockInspect.isActive(); // Check status
blockInspect.updateOptions({ disablePaste: false }); // Modify while active
