npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bian-disable-devtool

v1.0.1

Published

禁用通过F12按键、右键点击以及浏览器中的其他方式来启动网页开发者工具。

Downloads

7

Readme


1. 快速使用

1.1 npm 引用

npm i @deppon/bian-disable-devtool
import DisableDevtool from '@deppon/bian-disable-devtool';

DisableDevtool();

1.2 script属性配置

<script bian-disable-devtool-auto src='https://ca.deppon.com.cn/uu/bian-disable-devtool.js'></script>

2.功能

bian-disable-devtool 可以禁用所有一切可以进入开发者工具的方法,防止通过开发者工具进行的 代码搬运

该库有以下特性:

  1. 支持可配置是否禁用右键菜单
  2. 禁用 f12ctrl+shift+i 等快捷键
  3. 支持识别从浏览器菜单栏打开开发者工具并关闭当前页面
  4. 多种监测模式,支持几乎所有浏览器(IE,360,qq浏览器,FireFox,Chrome,Edge...)
  5. 高度可配置、使用极简、体积小巧
  6. 支持npm引用和script标签引用(属性配置)
  7. 识别真移动端与浏览器开发者工具设置插件伪造的移动端,为移动端节省性能
  8. 支持识别开发者工具关闭事件
  9. 支持可配置是否禁用选择、复制、剪切、粘贴功能
  10. 支持识别 eruda 和 vconsole 调试工具
  11. 支持挂起和恢复探测器工作
  12. 支持配置ignore属性,用以自定义控制是否启用探测器
  13. 支持配置iframe中所有父页面的开发者工具禁用

3. 使用

3.1 npm使用时的配置参数

推荐使用这种方式安装使用,使用script脚本可以被代理单独拦截掉从而无法执行 安装 bian-disable-devtool

npm i @deppon/bian-disable-devtool
import DisableDevtool from '@deppon/bian-disable-devtool';

DisableDevtool(options);

3.1.1 返回值

返回值 DisableDevtool 的返回值为如下类型

interface IDDResult {
    success: boolean; // 表示是否正常启用
    reason: string; // 未正常启用的原因
}

3.1.2 参数

options中的参数与说明如下:

interface IConfig {
    url?: string; // 关闭页面失败时的跳转页面,默认值为localhost
    ondevtoolopen?(type: DetectorType, next: Function): void; // 开发者面板打开的回调,启用时url参数无效,type 为监测模式,详见3.5, next函数是关闭当前窗口
    ondevtoolclose?(): void; // 开发者面板关闭的回调
    interval?: number; // 定时器的时间间隔 默认200ms
    disableMenu?: boolean; // 是否禁用右键菜单 默认为true
    stopIntervalTime?: number; // 在移动端时取消监视的等待时长
    clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控 默认为false, 在使用ondevtoolclose时该参数无效
    detectors?: Array<DetectorType>; // 启用的检测器 检测器详情见 3.5 默认为全部,建议使用全部
    clearLog?: boolean; // 是否每次都清除log
    disableSelect?: boolean; // 是否禁用选择文本 默认为false
    disableCopy?: boolean; // 是否禁用复制 默认为false
    disableCut?: boolean; // 是否禁用剪切 默认为false
    disablePaste: boolean; // 是否禁用粘贴 默认为false
    ignore?: (string|RegExp)[] | null | (()=>boolean); // 某些情况忽略禁用
    disableIframeParents?: boolean; // iframe中是否禁用所有父窗口
    timeOutUrl?: string; // 关闭页面超时跳转的url;
    rewriteHTML: string; // 检测到打开之后重写页面
}

enum DetectorType {
  Unknown = -1,
  RegToString = 0, // 根据正则检测
  DefineId, // 根据dom id检测
  Size, // 根据窗口尺寸检测
  DateToString, // 根据Date.toString 检测
  FuncToString, // 根据Function.toString 检测
  Debugger, // 根据断点检测,仅在ios chrome 真机情况下有效
  Performance, // 根据log大数据性能检测
  DebugLib, // 检测第三方调试工具 eruda 和 vconsole   
};

3.2 script使用属性配置

<script 
    bian-disable-devtool-auto
    src='https://ca.deppon.com.cn/uu/bian-disable-devtool.js'
    url='xxx'
    interval='xxx'
    disable-menu='xxx'
    detectors='xxx'
    clear-log='true'
    disable-select='true'
    disable-copy='true'
    disable-cut='true'
    disable-paste='true'
></script>

注:

  1. 如希望自动禁用,属性配置时必须要带上 bian-disable-devtool-auto 属性
  2. 属性配置都是可选的,字段与3.1中一致,区别是将驼峰形式改成横线分割
  3. 该script标签建议放在body最底部
  4. detectors 需要使用空格分割,如 detectors='1 2 3'

3.3 script不使用属性配置

<script src='https://ca.deppon.com.cn/uu/bian-disable-devtool.js'></script>
<script>
    DisableDevtool({
        // 参数与3.1中一致
    })
</script>

3.4 监测模式

bian-disable-devtool有以下几种监测模式, DisableDevtool.DetectorType 为所有的监测模式枚举

enum DetectorType {
  Unknown = -1,
  RegToString = 0, // 根据正则检测
  DefineId, // 根据dom id检测
  Size, // 根据窗口尺寸检测 // 0.3.5版本后该探测器默认不启用
  DateToString, // 根据Date.toString 检测
  FuncToString, // 根据Function.toString 检测
  Debugger, // 根据断点检测,仅在ios chrome 真机情况下有效
  Performance, // 根据log大数据性能检测
  DebugLib, // 检测第三方调试工具
};

ondevtoolopen 事件的回调参数就是被触发的监测模式

可以在 ondevtoolopen 里执行业务逻辑,比如做数据上报、用户行为分析等

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

3.5 其他 API

3.5.1 isRunning

用于获取 DisableDevtool 是否正在运行中 (挂起或忽略状态也视为运行中,因为可以动态开启)

DisableDevtool.isRunning;

3.5.2 isSuspend

用于获取或设置 DisableDevtool 是否被挂起 (挂起状态所有的禁用都将暂时失效)

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

3.5.3 config.ignore

ignore 用于自定义某些忽略的场景

  1. 传入数组

传入数组是支持 字符串和正则表达式,表示匹配链接中是否含有传入的内容,使用如下

DisableDevtool({
    ignore: [
        '/user/login', // 当链接中含有该内容时禁用暂时被忽略
        /\/user\/[0-9]{6}/, // 当链接匹配该正则时禁用暂时被忽略
    ]
});
  1. 传入函数

传入函数表示自定义判断条件,返回一个bool类型,使用如下

DisableDevtool({
    ignore: () => {
        return userType === 'admin'; // 当是管理员时忽略禁用
    }
});