Recently, while inspecting the html of a random website, I noticed this weird script at the bottom the <head> tag. I've unminified it for better readability. I opened the same site on another browser and the script wasn't there at all, so this seems to be a Brave only thing.

Does anyone have an idea about its purpose?

<script data-dapp-detection="">
!function() {
  let e = !1;
  function n() {
    if(!e) {
      const n = document.createElement("meta");
      n.name = "dapp-detected", document.head.appendChild(n), e=!0
  if(window.hasOwnProperty("ethereum")) {
    if(window.__disableDappDetectionInsertion =! 0,void 0 === window.ethereum)
  } else {
    var t = window.ethereum;
    Object.defineProperty(window, "ethereum", {
      configurable: !0,
      enumerable: !1,
      set: function(e) {
        window.__disableDappDetectionInsertion || n(), t = e
      get: function() {
        if(!window.__disableDappDetectionInsertion) {
          const = arguments.callee;
          e && e.caller && e.caller.toString && -1 !== e.caller.toString().indexOf("getOwnPropertyNames") || n()
        return t

1 Answer 1


I found this on the GitHub comments for this script:

// For dapp detection:
// Redefine window.ethereum so that when window.ethereum is accessed by the page,
// we'll insert a meta header to say that this is a dapp and ethereum is installed.
// If the page itself accesses window.ethereum within the first 2 seconds, and the
// wallet is not installed yet, then we'll prompt to install it.

as well as:

  // If a website tries to access window.ethereum within the first 2 seconds,
  // then we prompt to install Brave Crypto Wallets.
  // If a website does not try to access window.ethereum, then we will not prompt.

So basically Brave browser injects some scripts check if the site you are on is trying to access the blockchain via any DApp. If this check is passed in the first 2 seconds; they prompt to use their wallet if you have not yet otherwise they don't prompt.

The prompt will look like this: enter image description here

Why you may ask?

The reason I can think of is that Brave uses its own add blocker and instead allows ADS for BAT rewards and also has their own user privacy policies in place. So this supports the whole Brave browser reward distribution via a decentralized web system by creating a wallet for you. It can also just be to promote their wallet.

More info on that here: https://www.howtogeek.com/449046/what-is-the-brave-browser-and-how-does-it-compare-to-chrome/

This script can be turned off in extension settings.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.