This is a bit confusing, but your code really works, you just cannot see the inserted rules in the returned XML tree.
To make sure your code works, there are two tests you can perform:
var style = (function() {
<p class="foo"> I am some text </p>
Run the above snippet and you will see that the CSS rule applies. And the cssRules property also changes in the console.
This is often noted when browser extensions generate custom stylesheets added to the DOM, and when they are debugged, they appear as empty stylesheets in the inspector.
source share