forked from Anidetrix/rollup-plugin-styles
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
bugSomething isn't workingSomething isn't working
Description
When bundled in a userscript the injection fails when the script is set to run at document-start instead of document-body or later. Essentially the script ends up running before the DOM has been fully parsed meaning <head> is not there yet causing insertAdjacentElement to fail. This is the tampermonkey documentation.
TypeError: can't access property "insertAdjacentElement", s is undefined
Would it be possible to add a fallback for when there's no <head> yet? Maybe something like:
if (document.head) { injectStyles(); } else { document.addEventListener("DOMContentLoaded", injectStyles); }or
if (document.head) {
injectStyles();
} else {
(function waitForHead() {
if (document.head) {
injectStyles();
} else {
requestAnimationFrame(waitForHead);
}
})();
}megheaiulian
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working