document.styleSheets is undefined
See original GitHub issueIs there a way to compute the document.styleSheets
attribute once the window
element is created and some HTML is added to it?
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (10 by maintainers)
Top Results From Across the Web
Trying to read styleSheets returns undefined - Stack Overflow
I'm trying to read cssText of the first stylesheet using document.styleSheets[0].cssText , but it always returns undefined .
Read more >stylesheet variable is undefined in Chrome · Issue #223 - GitHub
The issue seems to be that Chrome doesn't update the documents.styleSheets variable right after the text node with the CSS rules has been...
Read more >document.styleSheets[0] is undefined [#362735] | Drupal.org
I am getting this error in FF Error: document.styleSheets[0] is undefined .../modules/dynamic_views/js/dynamic_views.js line 229.
Read more >Document.styleSheets - Web APIs | MDN
The styleSheets read-only property of the Document interface returns a StyleSheetList of CSSStyleSheet objects, for stylesheets explicitly ...
Read more >CSSStyleDeclaration parentRule Property - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Leprosy I managed to find what caused the problem now and I have fixed it in the latest release.
I recommend using a VM context to set Happy DOM as global if you will run scripts. You can also use
@happy-dom/global-registrator
in test environments. I do not recommend using@happy-dom/global-registrator
in environments where you do not have control over the page HTML. If you plan to execute unknown code I recommend to use a VM context and disable script evaluation in the VM as it is always a risk that the script manages to jump out from the VM somehow.I have also added support for the window “load” event and the document “readystatechange” event, but as your code seems to execute scripts I recommend using
happyDOM.whenAsyncComplete()
as it will also wait for the script to finish executing (timeouts, fetches etc.).You can read more about the latest releases here: https://github.com/capricorn86/happy-dom/releases/tag/v2.17.1
I used this script for testing:
@Leprosy the code examples I sent is for server side. However, I am working on adding support for the “load” and “readystatechange” event that you will be able to use instead.