Since you've identified that browser support for the :has pseudo-class is the issue, given that the user agent is Chrome version 103, let's address that.
As of my knowledge cutoff in early 2023, the :has pseudo-class does not have widespread browser support and is considered experimental, meaning it may not work in all browsers or may only work in specific conditions, like inside Developer Tools or under a flag in some versions of browsers. It is possible that Chrome 103 does not support it natively for use within JavaScript querySelectorAll.
Here's what you can do to work around the issue:
- Replace Complex Selector with JavaScript Logic: You can rewrite the selector to avoid using
:has and instead use JavaScript to apply the logic needed. For example:
// Instead of using :has, select all div elements and filter them with JavaScript
let iframes = document.querySelectorAll('div > iframe[id="198230182308109283091823098102938908128390"]');
let divsWithIframes = Array.from(iframes).filter(iframe => iframe.parentElement);
-
Update Browser or Use Polyfill: If :has support is critical, you could potentially instruct your users to use a browser version that does support the feature (always check the latest compatibility data), or you could implement a polyfill to provide equivalent functionality for browsers that don't support it. However, since this is a complex pseudo-class, a polyfill may have performance implications.
-
Feature Detection: In case you have a mixed environment where some users may be on browsers that do support :has and some may not, you can use feature detection to provide fallbacks depending on whether the feature is available:
try {
// Try to use the ':has' selector
let elements = document.querySelectorAll("div:has(> iframe[id='198230182308109283091823098102938908128390'])");
// ...use elements
} catch (e) {
// Fallback to another method if ':has' is not supported
let iframes = document.querySelectorAll('div > iframe[id="198230182308109283091823098102938908128390"]');
let divsWithIframes = Array.from(iframes).filter(iframe => iframe.parentElement);
// ...use divsWithIframes
}
-
Browser Upgrade: Encourage users to upgrade to a later version of Chrome where :has might be supported, if this is essential for your application’s functionality.
-
Static Checking Tools: If possible, integrate static checking tools in your development process that can warn you about the use of unsupported or experimental CSS features in your JavaScript code.
-
Documentation and Coding Standards: Update your team's coding standards and documentation to reflect that certain experimental features like :has should be avoided or used with caution, given their limited browser support.
As with all browser-specific issues, regularly check for updates on feature support as browsers evolve and add support for newer standards over time.