vuejs前端项目禁止用户调试(Vue项目防止被调试)

390 ℃

vuejs前端项目禁止用户调试,在用户打开console控制台的时候,直接跳到新的页面,或者无限debugger、无限加载,下面web建站小编给大家简单介绍一下具体实现代码!

1、新建console-ban.min.js文件

!(function(e, t) {
  typeof exports == 'object' && typeof module != 'undefined' ?
    t(exports) :
    typeof define == 'function' && define.amd ?
    define(['exports'], t) :
    t(((e = typeof globalThis != 'undefined' ? globalThis : e || self).ConsoleBan = {}))
})(this, function(e) {
  'use strict'
  var t = function() {
    return (
      (t =
        Object.assign ||
        function(e) {
          for (var t, n = 1, i = arguments.length; n < i; n++) {
            for (var o in (t = arguments[n])) {
              Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o])
            }
          }
          return e
        }),
      t.apply(this, arguments)
    )
  }
  var n = { clear: !0, debug: !0, debugTime: 3e3, bfcache: !0 }
  var i = 2
  var o = function(e) {
    return ~navigator.userAgent.toLowerCase().indexOf(e)
  }
  var r = function(e, t) {
    t !== i ? (location.href = e) : location.replace(e)
  }
  var c = 0
  var a = 0
  var f = function(e) {
    var t = 0
    var n = 1 << c++
      return function() {;
        (!a || a & n) && ++t === 2 && ((a |= n), e(), (t = 1))
      }
  }
  var s = function(e) {
    var t = /./
    t.toString = f(e)
    var n = function() {
      return t
    }
    n.toString = f(e)
    var i = new Date();
    (i.toString = f(e)), console.log('%c', n, n(), i)
    var o
    var r
    var c = f(e);
    (o = c),
    (r = new Error()),
    Object.defineProperty(r, 'message', {
        get: function() {
          o()
        }
      }),
      console.log(r)
  }
  var u = (function() {
    function e(e) {
      var i = t(t({}, n), e)
      var o = i.clear
      var r = i.debug
      var c = i.debugTime
      var a = i.callback
      var f = i.redirect
      var s = i.write
      var u = i.bfcache;
      (this._debug = r),
      (this._debugTime = c),
      (this._clear = o),
      (this._bfcache = u),
      (this._callback = a),
      (this._redirect = f),
      (this._write = s)
    }
    return (
      (e.prototype.clear = function() {
        this._clear && (console.clear = function() {})
      }),
      (e.prototype.bfcache = function() {
        this._bfcache &&
          (window.addEventListener('unload', function() {}),
            window.addEventListener('beforeunload', function() {}))
      }),
      (e.prototype.debug = function() {
        if (this._debug) {
          var e = new Function('debugger')
          setInterval(e, this._debugTime)
        }
      }),
      (e.prototype.redirect = function(e) {
        var t = this._redirect
        if (t) {
          if (t.indexOf('http') !== 0) {
            var n
            var i = location.pathname + location.search
            if (((n = t) ? (n[0] !== '/' ? '/'.concat(n) : n) : '/') !== i) r(t, e)
          } else location.href !== t && r(t, e)
        }
      }),
      (e.prototype.callback = function() {
        if ((this._callback || this._redirect || this._write) && window) {
          var e
          var t = this.fire.bind(this)
          var n = window.chrome || o('chrome')
          var r = o('firefox')
          if (!n) {
            return r ?
              (((e = /./).toString = t), void console.log(e)) :
              void(function(e) {
                var t = new Image()
                Object.defineProperty(t, 'id', {
                    get: function() {
                      e(i)
                    }
                  }),
                  console.log(t)
              })(t)
          }
          s(t)
        }
      }),
      (e.prototype.write = function() {
        var e = this._write
        e && (document.body.innerHTML = typeof e == 'string' ? e : e.innerHTML)
      }),
      (e.prototype.fire = function(e) {
        this._callback ?
          this._callback.call(null) :
          (this.redirect(e), this._redirect || this.write())
      }),
      (e.prototype.prepare = function() {
        this.clear(), this.bfcache(), this.debug()
      }),
      (e.prototype.ban = function() {
        this.prepare(), this.callback()
      }),
      e
    )
  })()
  e.init = function(e) {
    new u(e).ban()
  }
})

2、引入到index.html页面

<script src="/static/js/console-ban.min.js"></script>
<% if (process.env.NODE_ENV === 'production' ) { %> //判断环境执行
    <script>
      ConsoleBan.init({
        redirect: '/' //跳到指定的页面
      })
   </script>
<% } %>

console控制台输入有哪些好玩的用法

console.log报Uncaught TypeError: Assignment to constant varia

JS如何实现console执行次数

开发移动端网页如何调用控制台(Eruda、vconsole)

console.log输出图片和ascii

标签: console, Vue禁止调试

上面是“vuejs前端项目禁止用户调试(Vue项目防止被调试)”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_14412.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

dedecms织梦多条件联动筛选带删除功能教程
织梦cms如何去掉列表推荐时被加粗的样式
vue项目部署成功后刷新页面报404(解决方法)
html语法和css语法如何去除空格
wordpress出现头像错位怎么解决