web: Warn about root movie fetch over file protocol

This commit is contained in:
nosamu 2023-01-04 00:32:01 -06:00 committed by Nathan Adams
parent 7254d3c110
commit 21c65252f5
1 changed files with 20 additions and 22 deletions

View File

@ -1466,23 +1466,9 @@ export class RufflePlayer extends HTMLElement {
displayRootMovieDownloadFailedMessage(): void {
if (
window.location.origin === this.swfUrl!.origin ||
!this.isExtension ||
!window.location.protocol.includes("http")
this.isExtension &&
window.location.origin !== this.swfUrl!.origin
) {
const error = new Error("Failed to fetch: " + this.swfUrl);
if (
window.location.origin !== this.swfUrl!.origin &&
!this.isExtension
) {
error.ruffleIndexError = PanicError.SwfCors;
} else {
error.ruffleIndexError = PanicError.SwfFetchError;
}
this.panic(error);
return;
}
this.hidePreloader();
const div = document.createElement("div");
div.id = "message_overlay";
@ -1494,6 +1480,18 @@ export class RufflePlayer extends HTMLElement {
</div>
</div>`;
this.container.prepend(div);
} else {
const error = new Error("Failed to fetch: " + this.swfUrl);
if (!this.swfUrl!.protocol.includes("http")) {
error.ruffleIndexError = PanicError.FileProtocol;
} else if (window.location.origin === this.swfUrl!.origin) {
error.ruffleIndexError = PanicError.SwfFetchError;
} else {
// This is a selfhosted build of Ruffle that tried to make a cross-origin request
error.ruffleIndexError = PanicError.SwfCors;
}
this.panic(error);
}
}
displayUnsupportedMessage(): void {