-1

I'm trying to write a userscript that selects <div> elements containing a <ytd-rich-grid-media> element with a [is-dismissed] attribute as an immediate child.

<div> <!-- do not select this -->
    <div> <!-- do not select this -->
        <ytd-rich-grid-media>
        </ytd-rich-grid-media>
    </div>
    <div> <!-- DO select this -->
        <ytd-rich-grid-media is-dismissed>
        </ytd-rich-grid-media>
    </div>
</div>

The environment supports selection by attribute; this user script is able to select the child of the target element:

ytd-rich-grid-media[is-dismissed]  {
    
    display: none !important;
    
}

The environment also supports the :has() selector; this script is able to select <div>s that contain <ytd-rich-grid-media>s (regardless of attribute or depth of inheritance).

div:has(ytd-rich-grid-media) {
    
    display: none !important;
    
}

Lastly, the environment supports the > child selector; this script is able to select the <ytd-rich-grid-media> elements that are the direct child of a <div>:

div > ytd-rich-grid-media {
    
    display: none !important;
    
}

However, the moment I try to combine the :has() selector with either of the other tools, everything falls apart. I would expect the CSS I'm looking for to look something like this:

div:has(> ytd-rich-grid-media[is-dismissed] ) {
    
    display: none !important;
    
}

However, this returns errors in Stylus on Opera. The first error is Expected RPAREN but found '>'.; if the > is removed as a diagnostic step, the first error is instead Expected RPAREN but found '['.. If I instead remove the [is-dismissed], the first error remains present.

While I haven't been able to find any information about whether :has() can support children with attribute selectors, I've found a few sources (including this one) that suggest that the > selector should work just fine with :has(). Is this an implementation bug (within Opera and/or Stylus), an unsupported combination of CSS selectors (either for within Opera specifically or within CSS as a whole), a mistake on my part in assembling those selectors, or something else?

redyoshi49q
  • 679
  • 1
  • 5
  • 7
  • 1
    the selector works fine: https://jsfiddle.net/9bpg1w5h/ (at least in a browser that supports the :has selector) – Temani Afif Jun 10 '23 at 22:48
  • This is not standard HTML. You need to tag this with whatever those non-standard tags are from and about. – Rob Jun 11 '23 at 11:55

1 Answers1

1

Seems more like a stylus extension's problem.

The selector works fine in Chrome Dev Tools and other CSS environments.

whatserface
  • 55
  • 1
  • 8
  • 1
    Okay, so I'm not going crazy, then. I'm ultimately looking to update a userscript that I wrote for a friend (an update to Youtube's pages broke it), and it looks like my friend's version of Stylus isn't quite the most current. I'll try updating their Stylus extension next and see whether a newer version might have fixed this issue. If not... I guess I'll be filing a Stylus bug report? Thanks. – redyoshi49q Jun 11 '23 at 04:18