I am trying to detect (and then change) stylesheet in any loaded page.
I try the folowing code:
// from https://developer.mozilla.org/en-US/docs/Web/API/StyleSheetList
var allCSS =
[].slice.call(document.styleSheets)
.reduce(function (prev, styleSheet) {
if (styleSheet.cssRules) {
return prev +
[].slice.call(styleSheet.cssRules)
.reduce(function (prev, cssRule) {
return prev + cssRule.cssText;
}, '');
} else {
return prev;
}
}, '');
console.log(allCSS);
When I run this code on this page for example, I get a few stylesheets in the console.
However this is definitely not all the styles, it is infact just a small portion of it.
For example in the debugger I see that the page loads all.css
from 'cdn.sstatic.net' with many styles, none of them are shown.
What am I doing wrong ? and how can I get ALL stylesheets ?
Thx!