v160 · javascript · cssom
Round-trip into string APIs
The practical reason selectorText exists. The rest of the platform names pseudo-elements by string: getComputedStyle(el, "::x"), el.animate(kf, {pseudoElement: "::x"}), el.pseudo("::x"). A reusable helper that is handed only a CSSPseudoElement object (from pseudoTarget, from a framework, from a previous lookup) needs a string that selects exactly that pseudo-element. Run the same helper with selectorText and with the pre-160 workaround, type, and compare.
selectorText column will read “not exposed”. Enable chrome://flags/#enable-experimental-web-platform-features and relaunch, or launch with --enable-blink-features=CSSPseudoElementSelectorText / --enable-features=CSSPseudoElementSelectorText. The type column runs for real either way.
The page
- Ship the release
| key | getComputedStyle | animate() | pseudo(key) === p |
|---|---|---|---|
| not run yet | |||
the helper
function pulse(pseudo) {
const key = pseudo.selectorText; // Chrome 160+
const from = getComputedStyle(pseudo.element, key).opacity;
pseudo.element.animate([{ opacity: from }, { opacity: 0.3 }, { opacity: from }],
{ duration: 400, pseudoElement: key });
}
// Pre-160 workaround: pseudo.type — fine for "::before", but
// getComputedStyle(html, "::view-transition-group") → empty declaration
// html.animate(kf, { pseudoElement: "::view-transition-group" }) → SyntaxError
Verified on Chromium 153 in this container: with key "::view-transition-group", animate() throws SyntaxError: ::view-transition-group is a syntactically invalid pseudo-element and getComputedStyle returns empty values, while the full "::view-transition-group(panel)" works during a transition.