detect-devtools
v1.0.7
Published
![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white) ![JavaScript](https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black) ![Bun](https://img.shields.
Downloads
8
Readme
🔍 DETECT-DEVTOOLS
A lightweight, modular library for detecting when browser developer tools are opened, using multiple detection strategies.
🌟 Features
- Multiple Detection Methods: Uses various strategies to detect DevTools opening
- Modular Architecture: Easy to add or remove detection strategies
- TypeScript Support: Fully typed for better development experience
- Customizable Callbacks: Define custom actions when DevTools state changes
- Minimal Dependencies: Pure JavaScript/TypeScript implementation
🚀 Installation
npm install --save detect-devtools
📋 Usage
import { init } from 'detect-devtools';
// Initialize with a callback function
init((isOpen, type, detail) => {
console.log(`DevTools ${isOpen ? 'opened' : 'closed'}`);
console.log(`Detection method: ${type}`);
console.log(`Additional details:`, detail);
});
HTML Example
Check /dist/example.html
Live example: https://vehbiu.github.io/detect-devtools/dist/example.html
🛠️ Detection Strategies
The library uses multiple strategies to detect DevTools:
- Object ID Check: Monitors changes in object properties
- Performance Logging: Analyzes console.log performance
- Debug Check: Checks for debug-related behaviors
- ToString Check: Evaluates function.toString() behavior
📁 Project Structure
src/
├── checks/
│ ├── impl/
│ │ └── [...checkName].ts
│ └── BaseCheck.ts
├── util/
├── index.ts
└── tsconfig.json
⚙️ API Reference
init(onChange?: OnChangeProps)
Initializes the detection system with an optional callback function.
type OnChangeProps = (
open: boolean, // true if DevTools is open
type: string, // detection method that triggered
detail: object | string | null // additional information
) => void;
🤝 Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a new branch:
git checkout -b feature/your-feature
- Make your changes
- Submit a pull request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
👤 Author
Vehbi
- GitHub: @vehbiu
🙏 Acknowledgments
- Inspired by various DevTools detection techniques
- Lots of techniques improved from:
- https://github.com/sindresorhus/devtools-detect/
Made with ❤️ for the developer community