简体   繁体   English

在控制台中警告用户并在Javascript中隐藏错误日志

[英]Warn user in console and Hide error logs in Javascript

I am working on a website that will deal with user data and I was wondering how can someone warn a user when he clicks on console tab in developper tools within the browser. 我正在一个处理用户数据的网站上工作,我想知道当用户单击浏览器中开发人员工具中的控制台选项卡时,如何警告用户。 something like this from facebook: 来自facebook的东西:

在此处输入图片说明

And also hide javascript errors in the log. 并且还将javascript错误隐藏在日志中。

Thank you in advance 先感谢您

try this: https://github.com/icodeforlove/Console.js 试试这个: https : //github.com/icodeforlove/Console.js

Or you can do it simply this way: 或者,您可以通过以下方式简单地做到这一点:

console.log("%cThis is a %cConsole.log", "background:black ; color: white", "color: red; font-size:25px");

Also check out this article: http://voidcanvas.com/make-console-log-output-colorful-and-stylish-in-browser-node/ 还要查看这篇文章: http : //voidcanvas.com/make-console-log-output-colorful-and-stylish-in-browser-node/

Try adding something like this: 尝试添加如下内容:

<script type="text/javascript">
  const warningTitleCSS = 'color:red; font-size:60px; font-weight: bold; -webkit-text-stroke: 1px black;';
  const warningDescCSS = 'font-size: 18px;';
  console.log('%cStop!', warningTitleCSS);
  console.log("%cThis is a browser feature intended for developers. If someone told you to copy and paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.", warningDescCSS);
  console.log('%cSee https://www.facebook.com/selfxss for more information.', warningDescCSS);
</script>

https://gist.github.com/tosbourn/f556ee09c4a551e91d1dfde2f7b254f4 https://gist.github.com/tosbourn/f556ee09c4a551e91d1dfde2f7b254f4

If you just want the formatting, you can do something like this: 如果只需要格式化,则可以执行以下操作:
console.log('%cSTOP!', 'font-size:24px;color:red;')

To not show js errors in the console, the easiest and best-practice way is to not have them in the first place and/or catch them and deal with them when they occur. 为了不在控制台中显示js错误,最简单,最佳实践的方法是不将它们放在首位和/或捕获它们并在它们发生时进行处理。

I founded out an old post on this site that talks about that : 我在这个网站上发表了一篇关于这方面的旧文章:

How does Facebook disable the browser's integrated Developer Tools? Facebook如何禁用浏览器的集成开发人员工具?

Different approches are listed but the result may depend upon the browser. 列出了不同的方法,但结果可能取决于浏览器。 I tried some and I could still execute from console, but the link is helpful for some reasons. 我尝试了一些,但仍可以从控制台执行,但是由于某些原因,该链接很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM