Skip to content

Commit 0c56103

Browse files
committed
Add env_brave preparser token
Brave can't be told apart from Chrome through the user agent string, so detection uses `navigator.brave` with `navigator.userAgentData.brands` as fallback. Both are synchronous, unlike `navigator.brave.isBrave()` -- the flavor must be settled before filter lists are compiled and cached. Brave still offers uBO in MV2, and a considerable number of Brave users run Brave Shields and uBO at the same time. Filters which are safe on their own can conflict when both blockers apply them, and list maintainers currently have no way to express that: uBlockOrigin/uAssets#34162
1 parent 615a71a commit 0c56103

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

platform/common/vapi-common.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ vAPI.webextFlavor = {
197197
.add('user_stylesheet');
198198
}
199199
flavor.major = match && parseInt(match[1], 10) || 120;
200+
// Brave can't be told apart through the user agent string, which is
201+
// identical to Chrome's. Both tests below are synchronous, whereas
202+
// navigator.brave.isBrave() is promise-based -- the flavor must be
203+
// settled before filter lists are compiled and cached. Either test
204+
// alone would do, the second one is a fallback for the first.
205+
// https://github.com/brave/brave-browser/wiki/Detecting-Brave-(for-Websites)
206+
if (
207+
navigator.brave instanceof Object ||
208+
navigator.userAgentData?.brands?.some(a => a.brand === 'Brave')
209+
) {
210+
soup.add('brave');
211+
}
200212
}
201213

202214
// Don't starve potential listeners

src/js/static-filtering-parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ export const preparserIfTokens = new Set([
604604
'ext_ublock',
605605
'ext_ubol',
606606
'ext_devbuild',
607+
'env_brave',
607608
'env_chromium',
608609
'env_edge',
609610
'env_firefox',
@@ -4230,6 +4231,7 @@ export const utils = (( ) => {
42304231
[ 'ext_ublock', 'ublock' ],
42314232
[ 'ext_ubol', 'ubol' ],
42324233
[ 'ext_devbuild', 'devbuild' ],
4234+
[ 'env_brave', 'brave' ],
42334235
[ 'env_chromium', 'chromium' ],
42344236
[ 'env_edge', 'edge' ],
42354237
[ 'env_firefox', 'firefox' ],

0 commit comments

Comments
 (0)