0

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:

enter image description here

And also hide javascript errors in the log.

Thank you in advance

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

what is the use of %c here before Stop? and also for me it is printing like this %cStop! color:red; font-size:60px; font-weight: bold; -webkit-text-stroke: 1px black;
"%c" applies the css as the second parameter. Some browser versions may not support it. See: link
2

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.

Comments

1

try this: 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/

Comments

0

I founded out an old post on this site that talks about that :

How does Facebook disable the browser's integrated Developer Tools?

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.