web: Fix compatibility with Rocket Loader

Cloudflare's Rocket Loader script [prevents the DOMContentLoaded event from firing](https://dev.to/hollowman6/solution-to-missing-domcontentloaded-event-when-enabling-both-html-auto-minify-and-rocket-loader-in-cloudflare-5ch8), which was preventing Ruffle's public API from initializing. Work around this by also listening for the `load` event.

Fixes #2254 and #6583.
This commit is contained in:
nosamu 2022-04-21 03:53:18 -05:00 committed by Mike Welsh
parent 3dbde841df
commit e8d5274a18
1 changed files with 3 additions and 1 deletions

View File

@ -83,7 +83,9 @@ export class PublicAPI {
} }
if (document.readyState === "loading") { if (document.readyState === "loading") {
window.addEventListener("DOMContentLoaded", this.init.bind(this)); // Cloudflare Rocket Loader interferes with the DOMContentLoaded event,
// so we listen for readystatechange instead
document.addEventListener("readystatechange", this.init.bind(this));
} else { } else {
window.setTimeout(this.init.bind(this), 0); window.setTimeout(this.init.bind(this), 0);
} }