htmlpreview / htmlpreview.github.com

HTML Preview for GitHub Repositories

Home Page:htmlpreview.github.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

addEventListener("DOMContentLoaded", ...) never runs?

jason-s opened this issue · comments

This is because the scripts are being fetched and run after DOMContentLoaded event, so the solution is to use load event instead or check if DOMContentLoaded event has been fired:

if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', main); else main();

Nope, then the solution is to use another service then.

This is a bug.

Rawgit.org works fine: https://ghcdn.rawgit.org/jason-s/embedded-blog-public/master/demos/gravity1/gravity1.html

Rawgit is a third-party proxy server and could theoretically shut down at any time, while HTMLPreview is a client-side project without third-party servers (with an exception of external JS/CSS scripts, which are being proxied due to CORS). Because of this, the scripts are deferred and run past the DOMContentLoaded event. I can experiment with manually dispatch DOMContentLoaded event, but I am afraid this could have side effects on existing scripts (double dispatch).

How about running all functions returned from getEventListener(document).DOMContentLoaded?

@MaxLOh Do you mean getEventListeners()? It's only in Chrome DevTools. But I can manually dispatch DOMContentLoaded event like this: document.dispatchEvent(new Event('DOMContentLoaded', {bubbles: true, cancelable: true}));, although it may have side effects, which I wrote above.