From 49c73895cf91dcb4fa7d83f0d2bae91d02160142 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 27 Mar 2019 17:01:15 +0100 Subject: [PATCH] check if the user is running brave browser --- www/common/cryptpad-common.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index e19b59a9e..831b9faa3 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1135,6 +1135,31 @@ define([ window.RTCPeerConnection); }; + common.isBrave = function () { // Courtesy of https://www.ctrl.blog/entry/brave-user-agent-detection + try { + // initial assertions + if (!window.google_onload_fired && navigator.userAgent && !navigator.userAgent.includes('Chrome')) { + return false; + } + + // set up test + var test = document.createElement('iframe'); + test.style.display = 'none'; + document.body.appendChild(test); + + // empty frames only have this attribute set in Brave Shield + var is_brave = (test.contentWindow.google_onload_fired === true); + + // teardown test + test.parentNode.removeChild(test); + + return is_brave; + } catch (e) { // just in case... + console.error(e); + return false; + } + }; + common.ready = (function () { var env = {}; var initialized = false; @@ -1182,6 +1207,10 @@ define([ Feedback.send('NO_CSS_VARIABLES'); } + if (common.isBrave()) { + Feedback.send('BRAVE_BROWSER'); + } + Feedback.reportScreenDimensions(); Feedback.reportLanguage(); };