Detect if user is using Brave as browser when navigates on my website

Hey there!

Didn’t know exactly where to ask this question, but assuming that i have several websites, and i want user to able only to access(or at last view content) only if is using Brave browser.

i use the following JS script to detect, but “sometimes” im able to see the content from Google.
Is becouse at core is using Chromium?

js code
var screenFrame = document.getElementById("ScrFrm"); if (window.navigator.brave != undefined) { if ( == "isBrave") { = "block"; } else { = “none”; const para = document.createElement("h3"); para.innerHTML = "Brave Browser not detected <hr>First, install Brave browser!"; document.getElementById("div1").appendChild(para); } } else { = "none"; const para = document.createElement("h3"); para.innerHTML = "Operate Your Wallet&Node from Brave Browser! <hr>Install Brave Browser to continue please."; document.getElementById("div1").appendChild(para); }

Any help/tricks/tips is appreciated.
Thank you!

It shouldn’t happen because that navigator.brave is only present in Brave.

I am not JS guru, I only use it as hobby but seems like reading the code, some stuff clearly seems like it could improved.

For example, what is the purpose of ‘detecting brave twice’ and then the two messages h3? you know the ones “Brave Browser not detected” and the other with “Operate Your Wallet&Node from Brave Browser” technically one would never be used because window.navigator.brave != undefined and == "isBrave" will always co-exist and be true when using Brave. There is no way Brave will be != undefined and then ==isBrave will be false or that’s what I have seen.

In that case wouldn’t if (window.navigator.brave != undefined && == "isBrave") be better?

That means the logic for the messages is kind of more complicated than it should be, since one of the else would never happen and one h3 message would be displayed if the person is not using Brave.

BTW, you can test Brave without the API, if you use example##+js(brave-fix) in brave://adblock as custom rule, which will make it easy to remove the API with the simple scriptlet Brave created and then you can test it inside Brave too, how would it work without it. you can also add all your website domains like example1,example2 and that rule would apply to all of them in case you want to test them without it and not just in another browser.

Like I said, I am not coder, just learned it because I like to learn, especially when I started making my own scriptlet injections for the adblocker. But I am not like the person who would say any code or anything, just say what I think when I read the code and how Brave seems to work.

Anyway, hope something I said can be helpful! Take care.


The brave-fix snippet is only used for anti-brave sites.

1 Like

Well yes, technically that’s why you made the scriptlet for, but it can help for this, because for example, I tested the code in codepen, and I only needed to add and done, any change would reload the iframe which means I could quickly see it working without switching browsers, which in my case was not needed.

So only because it was made for that purpose doesn’t restrict users from doing it for something else, like testing the other way, to see if it is blocking correctly the site when not using Brave, instead of removing the block.

This is already available for any Brave user, but to be honest, I am already able to use any scriptlet inside Brave, like how I took the ‘set-cookies’ pes10k was converting from Adguard which was all restricted because of ‘security’ and I removed all the restrictions and now I can set whatever it’s needed.
What happened to that? is it going to be released and used someday? because I only saw it in adblock-resources and being approved and merged but notwhere else, only mention of it it’s the Fanboy annoyances list at the bottom which you added, and while I don’t need it, seems like a cool scriptlet to have available for Brave lists when needed.

Being creative and breaking rules or ‘hack it’ is better and less boring, than just use things as they were meant to be.

No issues people using the script. When I land a fix on our side its used to counter detection of Brave and counter roadblocks/warnings.

Ahh… my mistake, the code actually is for React components aka .hbs files(and it seems that somehow has been “reinterpreted” by the post rules, since i didn t read them well).

Clearly i didn’t expected that someone will respond, but you made all clear for my surprise!
And i can adapt to all my situations.

Now that finally found the perfect way to detect if a user is using Brave, i will simply do the other way around, and restrict the users to use our websites from BRAVE.
I brought them here, i will move them from here.
R.I.P Grave Browser.

P.S still batt here, since this free community ban peoples that brings issues in front.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.