happy-dom: document.styleSheets is undefined
Is there a way to compute the document.styleSheets attribute once the window element is created and some HTML is added to it?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (10 by maintainers)
Commits related to this issue
- #242@minor: Adds support for HTMLStyleElement. Adds support for HTMLLinkElement. Adds support for Document.styleSheets. Adds support for load and error event to HTMLScriptElement. Fixes bug where Wind... — committed to capricorn86/happy-dom by capricorn86 3 years ago
- Merge pull request #254 from capricorn86/task/242-add-support-for-document-style-sheets #242@minor: Adds support for HTMLStyleElement. Adds support for HTMLL… — committed to capricorn86/happy-dom by capricorn86 3 years ago
@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-registratorin test environments. I do not recommend using@happy-dom/global-registratorin 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.
Thanks for reporting @Leprosy! 🙂
I will look into this as soon as possible.