Skip to content

Commit

Permalink
Use CSS.supports() to detect support of native :has()
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Dec 25, 2023
1 parent abbff2d commit 38bde79
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions platform/common/vapi-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,38 +178,24 @@ vAPI.webextFlavor = {
soup.add('mobile');
}

// Asynchronous
if (
browser instanceof Object &&
typeof browser.runtime.getBrowserInfo === 'function'
) {
browser.runtime.getBrowserInfo().then(info => {
flavor.major = parseInt(info.version, 10) || flavor.major;
soup.add(info.vendor.toLowerCase())
.add(info.name.toLowerCase());
if ( flavor.major >= 121 && soup.has('mobile') === false ) {
soup.add('native_css_has');
}
dispatch();
});
if ( browser.runtime.getURL('').startsWith('moz-extension://') ) {
soup.add('firefox')
.add('user_stylesheet')
.add('html_filtering');
flavor.major = 115;
}
return;
if ( CSS.supports('selector(a:has(b))') ) {
soup.add('native_css_has');
}

// Synchronous -- order of tests is important
const match = /\bChrom(?:e|ium)\/([\d.]+)/.exec(ua);
if ( match !== null ) {
soup.add('chromium')
.add('user_stylesheet');
flavor.major = parseInt(match[1], 10) || 0;
if ( flavor.major >= 105 ) {
soup.add('native_css_has');
// Order of tests is important
if ( browser.runtime.getURL('').startsWith('moz-extension://') ) {
soup.add('firefox')
.add('user_stylesheet')
.add('html_filtering');
const match = /Firefox\/(\d+)/.exec(ua);
flavor.major = match && parseInt(match[1], 10) || 115;
} else {
const match = /\bChrom(?:e|ium)\/(\d+)/.exec(ua);
if ( match !== null ) {
soup.add('chromium')
.add('user_stylesheet');
}
flavor.major = match && parseInt(match[1], 10) || 120;
}

// Don't starve potential listeners
Expand Down

0 comments on commit 38bde79

Please sign in to comment.