浏览器在 head 标签前插入的 Brave 标签

Tag inserted by the browser Brave before the head tag

我在我的网页的 head 标签前发现了一个标签,由 Brave 浏览器插入。 如果我的内容 Content-Security-Policy 不允许 运行 没有有效随机数或完整性属性的脚本,我的问题将在我的页面上显示以下 运行。 第二个问题,脚本要求禁用(disableDappDetectionInsertion)??? 第三,这个脚本是做什么的?这个脚本有一个属性“data-dapp-detection”。 它发生在 window 模糊一段时间后。 勇敢的控制台也没有错误。 Brave 版本 1.10.97 Chromium:83.0.4103.116(官方构建)(64 位)

(function() {
  let alreadyInsertedMetaTag = false

  function __insertDappDetected() {
    if (!alreadyInsertedMetaTag) {
      const meta = document.createElement('meta')
      meta.name = 'dapp-detected'
      document.head.appendChild(meta)
      alreadyInsertedMetaTag = true
    }
  }

  if (window.hasOwnProperty('web3')) {
    // Note a closure can't be used for this var because some sites like
    // www.wnyc.org do a second script execution via eval for some reason.
    window.__disableDappDetectionInsertion = true
    // Likely oldWeb3 is undefined and it has a property only because
    // we defined it. Some sites like wnyc.org are evaling all scripts
    // that exist again, so this is protection against multiple calls.
    if (window.web3 === undefined) {
      return
    }
    __insertDappDetected()
  } else {
    var oldWeb3 = window.web3
    Object.defineProperty(window, 'web3', {
      configurable: true,
      set: function (val) {
        if (!window.__disableDappDetectionInsertion)
          __insertDappDetected()
        oldWeb3 = val
      },
      get: function () {
        if (!window.__disableDappDetectionInsertion)
          __insertDappDetected()
        return oldWeb3
      }
    })
  }
})()

安装 brave 浏览器并访问此站点以查看您的 CSP 政策允许或不允许的内容。 https://content-security-policy.com/browser-test/

关于 dapp-detection 这个网站有更详细的介绍: https://www.howtogeek.com/449046/what-is-the-brave-browser-and-how-does-it-compare-to-chrome/

但简而言之...Brave 使用 BAT(基本注意力令牌)并附带已安装的广告拦截器(Brave Shields)。 BAT 基于以太坊区块链,是他们允许广告和货币化同时尊重用户隐私的方式。