Skip to content

Commit fc91e68

Browse files
committed
web: Fix error messages outside the extension player
The error messages outside the extension player have been fixed. Ruffle now correctly determines whether the last load command originated from the extension player and displays the error messages specific to it (invalid URL / local URL / URL with unsupported protocol entered) only in that case. The advice to try entering http explicitly has also been removed if the URL is not loaded from the extension player. Additionally, if the website now embeds a URL with an unsupported protocol (e.g. file), a new specific error message about the website being misconfigured is now displayed instead of a button to open the URL in the extension player (which itself will result in an error).
1 parent 8ad6076 commit fc91e68

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

web/packages/core/src/internal/errors.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export class LoadSwfError extends Error {
2-
constructor(public swfUrl: URL | undefined) {
2+
constructor(public swfUrl: URL | undefined, public inExtensionPlayer: boolean) {
33
super(`Failed to fetch ${swfUrl}`);
44
this.swfUrl = swfUrl;
5+
this.inExtensionPlayer = inExtensionPlayer;
56
}
67
}
78

web/packages/core/src/internal/ui/panic.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
LoadRuffleWasmError,
99
LoadSwfError,
1010
} from "../errors";
11-
import { isExtension } from "../../current-script";
1211

1312
interface PanicLink {
1413
type: "open_link";
@@ -155,41 +154,49 @@ function createPanicError(error: Error | null): {
155154
actions: PanicAction[];
156155
} {
157156
if (error instanceof LoadSwfError) {
158-
const urlExtensionProtocol = isExtension ? document.baseURI.split(":")[0] + ":" : "";
157+
const inExtensionPlayer = error.inExtensionPlayer;
158+
const urlExtensionProtocol = inExtensionPlayer ? document.baseURI.split(":")[0] + ":" : "";
159159
if (error.swfUrl && error.swfUrl.protocol === urlExtensionProtocol) {
160-
// The user entered an invalid URL
160+
// The user entered an invalid URL in the extension player
161161
const urlExtensionPart = document.baseURI.split("player.html")[0]!;
162162
return {
163163
body: textAsParagraphs("error-no-valid-url", {
164164
url: error.swfUrl.href.replace(urlExtensionPart, ""),
165165
}),
166166
actions: [CommonActions.ShowDetails],
167167
};
168-
} else if (error.swfUrl && error.swfUrl.protocol === "file:") {
169-
// The user entered a local file URL
168+
} else if (error.swfUrl && inExtensionPlayer && error.swfUrl.protocol === "file:") {
169+
// The user entered a local file URL in the extension player
170170
return {
171171
body: textAsParagraphs("error-local-root-url"),
172172
actions: [CommonActions.ShowDetails],
173173
};
174-
} else if (error.swfUrl && !SUPPORTED_PROTOCOLS.includes(error.swfUrl.protocol)) {
175-
// The user entered a URL with an unsupported protocol
174+
} else if (error.swfUrl && inExtensionPlayer && !SUPPORTED_PROTOCOLS.includes(error.swfUrl.protocol)) {
175+
// The user entered a URL with an unsupported protocol in the extension player
176176
return {
177177
body: textAsParagraphs("error-unsupported-root-protocol", {
178178
protocol: error.swfUrl.protocol,
179179
}),
180180
actions: [CommonActions.ShowDetails],
181181
};
182+
} else if (error.swfUrl && !SUPPORTED_PROTOCOLS.includes(error.swfUrl.protocol)) {
183+
// The website embedded a URL with an unsupported protocol
184+
return {
185+
body: textAsParagraphs("error-misconfigured-url"),
186+
actions: [CommonActions.ShowDetails],
187+
};
182188
}
183189

184190
if (
185191
window.location.origin === error.swfUrl?.origin ||
186192
// The extension's internal player page is not restricted by CORS
187193
window.location.protocol.includes("extension")
188194
) {
195+
const tryHttpAdvice = inExtensionPlayer
196+
? error.swfUrl?.protocol?.includes("https")?.toString() ?? "true"
197+
: "false";
189198
return {
190-
body: textAsParagraphs("error-swf-fetch", {
191-
https: error.swfUrl?.protocol?.includes("https")?.toString() ?? "true",
192-
}),
199+
body: textAsParagraphs("error-swf-fetch", {https: tryHttpAdvice}),
193200
actions: [CommonActions.ShowDetails],
194201
};
195202
}

web/packages/core/src/ruffle-player.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { text, textAsParagraphs } from "./internal/i18n";
1818
import { isExtension } from "./current-script";
1919
import { configureBuilder } from "./internal/builder";
2020
import { showPanicScreen } from "./internal/ui/panic";
21-
import { RUFFLE_ORIGIN } from "./internal/constants";
21+
import { RUFFLE_ORIGIN, SUPPORTED_PROTOCOLS } from "./internal/constants";
2222
import {
2323
InvalidOptionsError,
2424
InvalidSwfError,
@@ -168,6 +168,9 @@ export class RufflePlayer extends HTMLElement {
168168

169169
private volumeSettings: VolumeControls;
170170

171+
// Whether the last load command originates from the extension player
172+
private inExtensionPlayer = false;
173+
171174
/**
172175
* Triggered when a movie metadata has been loaded (such as movie width and height).
173176
*
@@ -900,11 +903,14 @@ export class RufflePlayer extends HTMLElement {
900903
*
901904
* The options will be defaulted by the [[config]] field, which itself
902905
* is defaulted by a global `window.RufflePlayer.config`.
906+
* @param inExtensionPlayer Whether the load command originates from the extension player.
903907
*/
904908
async load(
905909
options: string | URLLoadOptions | DataLoadOptions,
906910
isPolyfillElement: boolean = false,
911+
inExtensionPlayer: boolean = false
907912
): Promise<void> {
913+
this.inExtensionPlayer = inExtensionPlayer;
908914
options = this.checkOptions(options);
909915

910916
if (!this.isConnected || this.isUnusedFallbackObject()) {
@@ -2055,8 +2061,9 @@ export class RufflePlayer extends HTMLElement {
20552061
this.container.prepend(div);
20562062
}
20572063

2058-
public displayRootMovieUnsupportedUrlMessage(unsupportedUrl: string) {
2064+
public displayExtensionPlayerUnsupportedUrlMessage(unsupportedUrl: string) {
20592065
this.swfUrl = new URL(unsupportedUrl, document.baseURI);
2066+
this.inExtensionPlayer = true;
20602067
this.displayRootMovieDownloadFailedMessage(false);
20612068
}
20622069

@@ -2065,13 +2072,14 @@ export class RufflePlayer extends HTMLElement {
20652072
if (
20662073
openInNewTab &&
20672074
this.swfUrl &&
2068-
window.location.origin !== this.swfUrl.origin
2075+
window.location.origin !== this.swfUrl.origin &&
2076+
SUPPORTED_PROTOCOLS.includes(this.swfUrl.protocol)
20692077
) {
20702078
this.addOpenInNewTabMessage(openInNewTab, this.swfUrl);
20712079
} else {
20722080
const error = invalidSwf
20732081
? new InvalidSwfError(this.swfUrl)
2074-
: new LoadSwfError(this.swfUrl);
2082+
: new LoadSwfError(this.swfUrl, this.inExtensionPlayer);
20752083
this.panic(error);
20762084
}
20772085
}

web/packages/core/texts/en-US/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ error-unsupported-root-protocol =
8989
error-no-valid-url =
9090
"{$url}" is not a valid URL and can't be resolved.
9191
Please enter a valid web URL or use the Select File button.
92+
error-misconfigured-url =
93+
The embedded SWF file is not under a supported URL Ruffle can load from.
94+
This is most likely due to a website misconfiguration.
95+
Try contacting the website administrator for help.
9296
error-unknown =
9397
Ruffle has encountered a major issue whilst trying to display this Flash content.
9498
{$outdated ->

web/packages/extension/src/player.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async function load(options: string | DataLoadOptions | URLLoadOptions) {
124124

125125
const supportedURL = utils.supportedURL(url);
126126
if (!supportedURL && urlString) {
127-
player.displayRootMovieUnsupportedUrlMessage(urlString);
127+
player.displayExtensionPlayerUnsupportedUrlMessage(urlString);
128128
return;
129129
}
130130
if (
@@ -148,7 +148,7 @@ async function load(options: string | DataLoadOptions | URLLoadOptions) {
148148
return;
149149
}
150150
}
151-
player.load(options, false);
151+
player.load(options, false, true);
152152
player.addEventListener("loadedmetadata", () => {
153153
if (player.metadata) {
154154
for (const [key, value] of Object.entries(player.metadata)) {

0 commit comments

Comments
 (0)