• Stars
    star
    1,690
  • Rank 27,610 (Top 0.6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Disable web developer tools from the f12 button, right-click and browser menu

stars forks version downloads jsdelivr issue

author license Size TopLang test visitors

🚀 One line of code to disable web developer tools

中文 | Online Trial | Changelog | Gitee | Message Board | QQ Group: 720626970


Open source maintenance is not easy, if you have the financial means, you can donate the author for a cup of coffee

test test test


1. Quick use

1.1 npm reference

npm i disable-devtool
import DisableDevtool from 'disable-devtool';

DisableDevtool();

1.2 script attribute configuration

<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool'></script>

Or cite by version:

<!--Use the specified version-->
<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/[email protected]'></script>
<!--Use latest version-->
<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool@latest'></script>

1.3 False trigger problem location help


If you have problems during use, please click on me

Because there are many devices, browsers, and operating environments, it is inevitable that there will be some scenarios where the library is incompatible, and this part is used for developers to check the problem by themselves, and then feedback the details to issues to help us locate and solve bugs

1.3.1 The probe was triggered incorrectly

In some cases, if the console is not opened but the page does not close or the jump is away, because a probe is triggered by error, use the following code to locate which probe was triggered by mistake:

DisableDevtool({
    ondevtoolopen: (type) => {
        const info = 'devtool opened!; type =' + type;
        alert(info);
        // If you are worried about blocking the page, use console.warn(info); and open the console to view
    },
})

The above code needs to be used this when using script references

<script src='https://cdn.jsdelivr.net/npm/disable-devtool'></script>
<script>
    DisableDevtool({
        ondevtoolopen: (type) => {
            const info = 'devtool opened!; type =' + type;
            alert(info); // If you are worried about blocking the page, use console.warn(info); and open the console to view
        },
    })
</script>

1.3.2 The probe is not triggered

When devtool is opened in any way, but the page does not close or jump correctly, first try printing the following to see if the detector is working properly

console.log(DisableDevtool.isRunning);

If it returns true, then this is an incompatibility problem because none of the probes are triggered, which is tricky, and there is currently no universal way to locate it

Please submit an issue, as detailed as possible with the browser version, device model and version, operating environment, preferably a screenshot or demo address, we will troubleshoot the corresponding problem later


2. Function

disable-devtool disables all access to the devtools, preventing 'code porting' via the devtools

The library has the following features:

  1. Support configurable whether to disable the right-click menu
  2. Disable shortcut keys such as f12 and ctrl+shift+i
  3. Support recognition to open developer tools from browser menu bar and close the current page
  4. Developers can bypass the disable (url parameters are encrypted with tk and md5)
  5. Multiple monitoring modes, support almost all browsers (IE, 360, qq browser, FireFox, Chrome, Edge...)
  6. Highly configurable, minimalist to use, compact
  7. Support npm reference and script tag reference (property configuration)
  8. Identify the real mobile terminal and the browser developer tool to set the plug-in forged mobile terminal to save performance for the mobile terminal
  9. Support for identifying developer tools close events
  10. Support configurable whether to disable selection, copy, cut, paste function
  11. Support to identify eruda and vconsole debugging tools
  12. Support suspending and resuming probe work
  13. Support configuring ignore attributes to customize whether to enable probes
  14. Support for configuring all parent pages in iframes to be disabled

3. Use

3.1 Configuration parameters when using npm

It is recommended to use this method of installation and use, and the script script can be intercepted by the agent separately and cannot be executed

install disable-devtool

npm i disable-devtool
import DisableDevtool from 'disable-devtool';

DisableDevtool(options);

3.1.1 Return value

Return value DisableDevtool The return value is of the following type

interface IDDResult {
    success: boolean; Indicates whether it is enabled normally
    reason: string; The reason why it was not properly enabled
}

3.1.2 parameters

The parameters and descriptions in options are as follows:

declare interface IConfig {
    md5?: string; // bypass disabled md5 value, see 3.2 for details, 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; // The callback for opening the developer panel, the url parameter is invalid when enabled, the type is monitoring mode, see 3.5 for details, the next function is to close the current window
    ondevtoolclose?(): void; // callback for developer panel close
    interval?: number; // timer interval default 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 the default is false, this parameter is invalid when using ondevtoolclose
    detectors?: Array<DetectorType>; // Enabled detectors See 3.5 for details of 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 selection text 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 paste, default is false
    ignore?: (string| RegExp)[] | null | (()=>boolean); // Some cases ignore the disablement
    disableIframeParents?: boolean; // Whether all parent windows are disabled in the iframe
    timeOutUrl?: // Turn off URLs that page timeouts forward towards
}

enum DetectorType {
  Unknown = -1,
  RegToString = 0, // Check according to regular
  DefineId, // detect based on dom id
  Size, // Detect based on window size // After version 0.3.5, this probe is not enabled by default
  DateToString, // check against Date.toString
  FuncToString, // check according to Function.toString
  Debugger, // According to breakpoint detection, it is only valid in the case of ios chrome real machine
  Performance, // Performance detection based on log big data
  DebugLib, // Detect third-party debugging tools eruda and vconsole
};

3.2 md5 and tk bypass disabled

The way in which the key is used in conjunction with md5 in this library allows developers to bypass the ban online.

The process is as follows:

First specify a key a (the value should not be recorded in the code), use md5 encryption to obtain a value b, and pass in b as the md5 parameter. When accessing the url, the developer only needs to bring the url parameter ddtk=a, then you can Bypass disable.

The disableDevtool object exposes the md5 method, which can be used by developers when encrypting:

DisableDevtool.md5('xxx');

3.3 script uses attribute configuration

<script
    disable-devtool-auto
    src='https://cdn.jsdelivr.net/npm/disable-devtool'
    md5='xxx'
    url='xxx'
    tk-name='xxx'
    interval='xxx'
    disable-menu='xxx'
    detectors='xxx'
    clear-log='true'
    disable-select='true'
    disable-copy='true'
    disable-cut='true'
    disable-paste='true'
></script>

Note:

  1. If you want to disable it automatically, you must include the disable-devtool-auto property when configuring the property
  2. The attribute configuration is optional, and the fields are the same as in 3.1, the difference is that the hump form is changed to a horizontal line.
  3. The script tag is recommended to be placed at the bottom of the body
  4. Detectors need to be separated by spaces, such as detectors='1 2 3'

3.4 script does not use attribute configuration

<script src='https://cdn.jsdelivr.net/npm/disable-devtool'></script>
<script>
    DisableDevtool({
        // The parameters are the same as in 3.1
    })
</script>

3.5 Monitoring Mode

Disable-Devtool has the following monitoring modes, DisableDevtool.DetectorType enumerates all monitoring modes

enum DetectorType {
  Unknown = -1,
  RegToString = 0, // Check according to regular
  DefineId, // detect based on dom id
  Size, // Detect based on window size
  DateToString, // check against Date.toString
  FuncToString, // check according to Function.toString
  Debugger, // According to breakpoint detection, it is only valid in the case of ios chrome real machine
  Performance, // Performance detection based on log big data
  DebugLib, // Detect third-party debugging tools
};

The callback parameter of the ondevtoolopen event is the triggered monitoring mode

You can execute business logic in OndevtoolOpen, such as data reporting, user behavior analysis, etc

DisableDevtool({
    ondevtoolopen(type, next){
        alert('Devtool opened with type:' + type);
        next();
    }
});

3.6 Additional APIs

3.6.1 isRunning

Used to get whether DisableDevtool is running (the pending or ignore state is also considered running because it can be turned on dynamically)

DisableDevtool.isRunning;

3.6.2 isSuspend

Used to get or set whether DisableDevtool is suspended (suspended state, all disabled will be temporarily disabled)

DisableDevtool.isSuspend = true;
DisableDevtool.isSuspend = false;

3.6.3 config.ignore

ignore is used to customize certain ignored scenarios

  1. Pass in the array

The incoming array is supported by strings and regular expressions that indicate whether the matching link contains the incoming content, using the following

DisableDevtool({
    ignore: [
        '/user/login', // Disabled is temporarily ignored when the link contains this content
        /\/user\/[0-9]{6}/, // When a link matches that regular, disabling is temporarily ignored
    ]
});
  1. Pass in the function

The passing function represents a custom judgment condition and returns a bool type, as follows

DisableDevtool({
    ignore: () => {
        return userType === 'admin'; // Disable is ignored when you are an administrator
    }
});

3.6.4 version

Get DisableDevtool version

DisableDevtool.version;

More Repositories

1

cnchar

🇨🇳 功能全面的汉字工具库 (拼音 笔画 偏旁 成语 语音 可视化等) (Chinese character util)
TypeScript
2,340
star
2

jsbox

JS online runtime sandbox (JS在线运行环境,在线IDE)
JavaScript
58
star
3

type

汉字打字游戏
JavaScript
52
star
4

dingdong-node

叮咚买菜nodejs自动下单脚本,支持邮件强通知和定时任务,支持捡漏和高峰模式
JavaScript
45
star
5

piano

Play the piano with type (钢琴打字游戏)
JavaScript
31
star
6

logger

Web logger based on indexedDB and WebWorker
TypeScript
26
star
7

salary

工资计算器(2022年最新计税规则)
TypeScript
25
star
8

spark-node

讯飞星火认知大模型 Nodejs SDK
TypeScript
22
star
9

mac

 Build Amazing macOS in your browser
TypeScript
20
star
10

mp-mixin

微信小程序 mixin & 全局store 方案
TypeScript
15
star
11

qrcode

🚀 Powerful qrcode js lib
TypeScript
14
star
12

tc-event

Powerful, easy-to-use eventbus
TypeScript
14
star
13

star-each-other

Leave your repository in issue and we star each other
14
star
14

easy-icon

A simple and easy to use web font icon js library
CSS
9
star
15

sener

Easy-to-use and highly scalable nodejs Web Framework
TypeScript
9
star
16

tc-editor

Code Editor JavaScript Library
JavaScript
8
star
17

comment

Commont component without any account or config, support Emoji and Markdown.
JavaScript
8
star
18

wx-minigame-ts

typescript + webpack 开发微信小游戏模板
JavaScript
8
star
19

webos

Webos terminal Based on HTML5 FileSystem and Alins
TypeScript
8
star
20

vite-vue3-ts-eslint

vite + vue3.2 + ts + eslint demo, script setup
Vue
7
star
21

theajack

7
star
22

bombbattle

大作战纯前端小游戏
JavaScript
7
star
23

laya-game

基于layabox开发的小游戏
JavaScript
7
star
24

jet

Jet--前端轻量级渐进式MVVM框架[便于使用 易于理解 双向绑定 数据驱动]
JavaScript
7
star
25

count-code-line

Count lines and characters for your project
JavaScript
7
star
26

cross-window-message

🚀 Elegant cross-window communication and global page management solution
TypeScript
7
star
27

canvas-render-html

Render HTML code with canvas
TypeScript
6
star
28

keyboard

Nothing But A Funny Keyboard
TypeScript
6
star
29

vuepress-plugin-tc-comment

Support tc-comment in Vuepress
JavaScript
6
star
30

easy-dom

Easy-Dom js library for convenient operation of dom
TypeScript
5
star
31

ts-demo

JavaScript
5
star
32

util

常用的工具方法
TypeScript
5
star
33

json-db

JavaScript
4
star
34

particle-drawer

Draw text or pictures with particles.
TypeScript
4
star
35

vue-i

vue implement
JavaScript
4
star
36

log-progress

A simple, flexible, and highly configurable progress bar
JavaScript
4
star
37

jetee

轻量级的渐进式 Web MVVM框架
JavaScript
4
star
38

pure-v

purev.js: A lightweight, extensible, pure js validation plugin
JavaScript
4
star
39

qr-camera

Web camera and QR code scanner
JavaScript
4
star
40

ebuild-cli

Build webpack, babel, eslint, less, commitlint, typescript, vue, react and other development environments
JavaScript
4
star
41

theajack.github.io

About personal website
JavaScript
4
star
42

jetterjs

js lib for form operate
JavaScript
4
star
43

tacl-ui

A set of simple ui components for taost, confirm, loading, alert, drag
4
star
44

tcon

基于 try catch 捕获所有异常的移动端调试工具
JavaScript
4
star
45

copy

Easy to use and compact JS library for copying text
JavaScript
4
star
46

ts-miniapp

Wechat miniapp demo with typescript (mp-mixin dev env)
TypeScript
4
star
47

easy-test-lib

A simple and easy-to-use testing framework
TypeScript
4
star
48

message-board

一条链接开启留言板,无需服务器
JavaScript
4
star
49

music-pc

by github.com/jonobr1/Neuronal-Synchrony
JavaScript
3
star
50

pixi-vue

pixi + vue3
JavaScript
3
star
51

tc-image

Image Editing Lib
TypeScript
3
star
52

ebuild-vite-vue3

ebuild-vite-vue3
JavaScript
3
star
53

tool

小工具
Vue
3
star
54

sener-best-practice

sener-best-practice
JavaScript
3
star
55

selon

Select * from jon
JavaScript
3
star
56

jet-js-cli

Jet 的脚手架工具,帮助您更便捷地使用Jet
JavaScript
3
star
57

leetcode

leetcode 记录
JavaScript
3
star
58

ts-jest-demo

ts + jest
TypeScript
3
star
59

react-ts

react + ts + antd-mobile + redux
JavaScript
3
star
60

electron-demo

electron-demo
JavaScript
3
star
61

university

甄别野鸡大学,查询大学信息
JavaScript
3
star
62

storage-enhance

Support multi-end enhanced storage js library
TypeScript
3
star
63

webapp-box

Web Application Container
JavaScript
3
star
64

electron-vue

electron-vue
JavaScript
3
star
65

laya-game2

JavaScript
3
star
66

sener-docs

Docs for Sener
JavaScript
3
star
67

landscape-simulator

Simulate landscape in scenes that cannot be landscaped
JavaScript
3
star
68

eveit

Event-emitter with strong support for type hints
JavaScript
3
star
69

weve

Develop Android with webview and native(kotlin) (like electron)
JavaScript
3
star
70

ebuild-template-npm

ebuild-template-npm
JavaScript
3
star
71

string-worker

Makes creating WebWorker easier
JavaScript
3
star
72

pixi-ts

JavaScript
2
star
73

design-pattern

JavaScript
2
star
74

excel

JavaScript
2
star
75

ebuild-template-rollup

ebuild-template-rollup
JavaScript
2
star
76

url-module-loader

url-module-loader
JavaScript
2
star
77

npm-ts-template

Typescript npm package template with ebuild cli
JavaScript
2
star
78

x-state

JavaScript
2
star
79

ebuild-template-vue

ebuild-template-vue 2.x
JavaScript
2
star
80

ebuild-template-css

ebuild-template-css
JavaScript
2
star
81

ebuild-template-light

ebuild-template-light
JavaScript
2
star
82

ebuild-template

JavaScript
2
star
83

formidable-fix

Revised version of https://github.com/node-formidable/formidable
JavaScript
2
star
84

ecsv

2
star
85

cmd-game

2
star
86

ebuild-template-lerna

ebuild template for monorepo project
JavaScript
2
star
87

cdn

cdn
JavaScript
2
star
88

ebuild-template-node-npm

ebuild-templat-node-npm
JavaScript
2
star
89

cnchar-app

cnchar 应用列表
2
star
90

sener-docs-cn

sener-docs 中文版本
JavaScript
2
star
91

drone

JavaScript
2
star
92

magic

Magic - Mind reading
JavaScript
2
star
93

jext

Next Jet Frame
JavaScript
2
star
94

code-game

TypeScript
2
star
95

node-es6-demo

node es6 template for ebuild cli
JavaScript
2
star
96

vue3-ts

Vue
2
star
97

dirty-word-filter

A js lib for dirty word filter
JavaScript
2
star
98

jet-template

jet-template
JavaScript
1
star
99

bql

Bind Query Library
JavaScript
1
star
100

minesweeper

Minesweeper game
TypeScript
1
star