Disable web developer tools from the f12 button, right-click and browser
npm install @comptechco/disable-devtoolbash
npm install @comptechco/disable-devtool --//registry.npmjs.org/:_authToken=ComptechcoToken
`
$3
1. Add the following entry to your package.json:
`json
"@comptechco/disable-devtool": "version"
`
2. Create a .npmrc file in the root of your project and add the following content:
`ini
//registry.npmjs.org/:_authToken=ComptechcoToken
`
3. Run the following command to install the package:
`bash
npm i
`
Usage
Import the package and use it as follows:
`javascript
import disableDevtool from "@comptechco/disable-devtool";
disableDevtool({
disableMenu: false,
url: "assets/html/yourhtmlpage.html",
});
`
Configuration
You can pass an options object to customize the behavior of the package. Below are the available options:
`typescript
declare interface IConfig {
md5?: string; // Bypass disabled MD5 value, bypass disabled by default
url?: string; // Jump page when closing the page fails, the default value is localhost
tkName?: string; // Bypass URL parameter name when disabled, default is ddtk
ondevtoolopen?(type: DetectorType, next: Function): void; // Callback for opening the developer panel
ondevtoolclose?(): void; // Callback for developer panel close
interval?: number; // Timer interval, default is 200ms
disableMenu?: boolean; // Whether to disable the right-click menu, default is true
stopIntervalTime?: number; // Waiting time to cancel monitoring on mobile
clearIntervalWhenDevOpenTrigger?: boolean; // Whether to stop monitoring after triggering, default is false
detectors?: Array; // Enabled detectors. The default is all, it is recommended to use all
clearLog?: boolean; // Whether to clear the log every time
disableSelect?: boolean; // Whether to disable text selection, default is false
disableCopy?: boolean; // Whether to disable copying, default is false
disableCut?: boolean; // Whether to disable cutting, default is false
disablePaste?: boolean; // Whether to disable pasting, default is false
ignore?: (string | RegExp)[] | null | (() => boolean); // Conditions to ignore the disablement
disableIframeParents?: boolean; // Whether all parent windows are disabled in the iframe
timeOutUrl?: string; // URL to forward when the page timeout occurs
rewriteHTML?: string; // HTML page to rewrite after opening the dev tools
}
`
$3
`typescript
enum DetectorType {
Unknown = -1,
RegToString = 0, // Check based on regular expression
DefineId, // Detect based on DOM id
Size, // Detect based on window size (this probe is not enabled by default)
DateToString, // Check based on Date.toString
FuncToString, // Check based on Function.toString
Debugger, // Detect breakpoints (valid only for iOS Chrome on real devices)
Performance, // Performance detection based on log big data
DebugLib, // Detect third-party debugging tools (e.g., eruda, vconsole)
}
``