I know this project has a disclaimer about not supporting all of the CSSOM, but I encountered some errors while trying to get HTML Inspector to work with jsdom instead of PhatomJS, and I tracked it down to the lack of these two properties on the CSSStyleSheet
object.
From what I can tell, the following function in level2/style.js is where this could/should be added, but I'm not familiar enough with the codebase to know for sure.
function evaluateStylesheet(data, sheet, baseUrl) {
// this is the element
var newStyleSheet = cssom.parse(data);
var spliceArgs = newStyleSheet.cssRules;
spliceArgs.unshift(0, sheet.cssRules.length);
Array.prototype.splice.apply(sheet.cssRules, spliceArgs);
scanForImportRules.call(this, sheet.cssRules, baseUrl);
// Add references to `this` and `baseUrl`.
sheet.href = baseUrl;
sheet.ownerNode = this;
this.ownerDocument.styleSheets.push(sheet);
}
Anyway, this changed work for me locally, so hopefully it's as simple as that. Thanks for the consideration.
Good catch. I will tag this as a bug and hopefully get a more principled version of your fix in soon.
FWIW, I believe cross-origin policies dictate that non-same-origin stylesheets are not included in document.styleSheets
. I'm not sure how jsdom treats the origin of file it's processing, so this may be tricky, but either way I think it's something worth keeping in mind.
Hello
I was about to file an issue for this, ownerNode is still not supported right?
If it is the case I will be happy to try to add it
Thx !
@lexoyo I also need this and have been trying to look into it - but not sure how...
There is a file, HTMLStyleElement-impl.js, that calls createStylesheet() in helpers > stylesheet.js and here is a bunch of garbage and TODO's.
It seems to me that "cssom" should be used instead, which (seem to) have what we need - but, not sure how at the moment. Also I don't have more time, so I will investigate further if I can get some more time. If you figure it out, please let me know!
Most helpful comment
@lexoyo I also need this and have been trying to look into it - but not sure how...
There is a file, HTMLStyleElement-impl.js, that calls createStylesheet() in helpers > stylesheet.js and here is a bunch of garbage and TODO's.
It seems to me that "cssom" should be used instead, which (seem to) have what we need - but, not sure how at the moment. Also I don't have more time, so I will investigate further if I can get some more time. If you figure it out, please let me know!