`CSSStyleSheet.insertRule` is broken?

,

It appears something with the implementation of CSSStyleSheet.insertRule is not working correctly.

It always throws this error, regardless of what arguments I pass in:

​ Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at new e.exports (uxp://uxp-internal/domjs_scripts.js:2)
    at e.exports.insertRule (uxp://uxp-internal/domjs_scripts.js:2)
    at <anonymous>:1:25

Here is an example you can run the developer console:

document.styleSheets[0].insertRule("*{}")

I also tried adding an index argument, but that doesn’t fix it. e.g.,:

document.styleSheets[0].insertRule("*{}", document.styleSheets[0].cssRules.length)

The documentation doesn’t lead me to believe that insertRule isn’t supported, so I think this is a bug: https://developer.adobe.com/xd/uxp/develop/reference/uxp/class/CSSStyleSheet/#cssstylesheetinsertrulerule-index

I am acknowledging this as a bug. We shall investigate this internally. I did an initial investigation and we’re indeed incorrectly handling the passed-in rule string. Thanks for highlighting this bug in our CSSOM.

2 Likes