From 31a7bf3eb94b97c1dc39cffd4df18afec547e78a Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Thu, 13 Nov 2025 14:42:26 -0500 Subject: [PATCH 1/3] web: Add config option to hide message when Ruffle restores from bfcache --- web/packages/core/src/internal/player/inner.tsx | 7 +++++-- web/packages/core/src/public/config/default.ts | 1 + web/packages/core/src/public/config/load-options.ts | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/web/packages/core/src/internal/player/inner.tsx b/web/packages/core/src/internal/player/inner.tsx index a5848340ac55..e6d90d5ef111 100644 --- a/web/packages/core/src/internal/player/inner.tsx +++ b/web/packages/core/src/internal/player/inner.tsx @@ -2134,8 +2134,11 @@ export class InnerPlayer { * Inform the user that the browser restored the file from the back/forward cache. */ protected displayRestoredFromBfcacheMessage(): void { - // Do not display the message if another one is already shown. - if (this.container.querySelector("#message-overlay") !== null) { + // Do not display the message if another one is already shown or website opted out. + if ( + this.container.querySelector("#message-overlay") !== null || + this.loadedConfig?.hideRestoredMessage + ) { return; } const message = textAsParagraphs("message-restored-from-bfcache"); diff --git a/web/packages/core/src/public/config/default.ts b/web/packages/core/src/public/config/default.ts index c7d21e7ebebf..399dd031d56b 100644 --- a/web/packages/core/src/public/config/default.ts +++ b/web/packages/core/src/public/config/default.ts @@ -22,6 +22,7 @@ export const DEFAULT_CONFIG: Required = { upgradeToHttps: true, compatibilityRules: true, favorFlash: true, + hideRestoredMessage: false, warnOnUnsupportedContent: true, logLevel: LogLevel.Error, showSwfDownload: false, diff --git a/web/packages/core/src/public/config/load-options.ts b/web/packages/core/src/public/config/load-options.ts index 18523741ac89..18a8cd5ecbad 100644 --- a/web/packages/core/src/public/config/load-options.ts +++ b/web/packages/core/src/public/config/load-options.ts @@ -450,6 +450,13 @@ export interface BaseLoadOptions { */ favorFlash?: boolean; + /** + * Hide the message when content is restored from the back/forward cache. + * + * @default false + */ + hideRestoredMessage?: boolean; + /** * This is no longer used and does not affect anything. * It is only kept for backwards compatibility. From a59fcc2c1283a77528b32a13c900efe7ab59e9c4 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Thu, 13 Nov 2025 16:05:30 -0500 Subject: [PATCH 2/3] web: Change config to bfcacheBehavior enum (inform, restore, reload) --- .../core/src/internal/player/inner.tsx | 7 ++++- .../core/src/public/config/default.ts | 3 ++- .../core/src/public/config/load-options.ts | 26 ++++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/web/packages/core/src/internal/player/inner.tsx b/web/packages/core/src/internal/player/inner.tsx index e6d90d5ef111..bb2f986e61f6 100644 --- a/web/packages/core/src/internal/player/inner.tsx +++ b/web/packages/core/src/internal/player/inner.tsx @@ -9,6 +9,7 @@ import { UnmuteOverlay, URLLoadOptions, WindowMode, + CacheBehavior, } from "../../public/config"; import { MovieMetadata, ReadyState } from "../../public/player"; import { ruffleShadowTemplate } from "../ui/shadow-template"; @@ -2137,10 +2138,14 @@ export class InnerPlayer { // Do not display the message if another one is already shown or website opted out. if ( this.container.querySelector("#message-overlay") !== null || - this.loadedConfig?.hideRestoredMessage + this.loadedConfig?.bfcacheBehavior === CacheBehavior.Restore ) { return; } + if (this.loadedConfig?.bfcacheBehavior === CacheBehavior.Reload) { + this.reload(); + return; + } const message = textAsParagraphs("message-restored-from-bfcache"); this.displayMessageOrElement(message); diff --git a/web/packages/core/src/public/config/default.ts b/web/packages/core/src/public/config/default.ts index 399dd031d56b..c4b0df11b12d 100644 --- a/web/packages/core/src/public/config/default.ts +++ b/web/packages/core/src/public/config/default.ts @@ -10,6 +10,7 @@ import { UnmuteOverlay, WindowMode, ScrollingBehavior, + CacheBehavior, } from "./load-options"; export const DEFAULT_CONFIG: Required = { @@ -22,7 +23,7 @@ export const DEFAULT_CONFIG: Required = { upgradeToHttps: true, compatibilityRules: true, favorFlash: true, - hideRestoredMessage: false, + bfcacheBehavior: CacheBehavior.Inform, warnOnUnsupportedContent: true, logLevel: LogLevel.Error, showSwfDownload: false, diff --git a/web/packages/core/src/public/config/load-options.ts b/web/packages/core/src/public/config/load-options.ts index 18a8cd5ecbad..75aa28963dba 100644 --- a/web/packages/core/src/public/config/load-options.ts +++ b/web/packages/core/src/public/config/load-options.ts @@ -361,6 +361,26 @@ export enum GamepadButton { DPadRight = "dpad-right", } +/** + * The behavior when the bfcache takes effect + */ +export enum CacheBehavior { + /** + * Inform the user that the content was restore from the bfcache. + */ + Inform = "inform", + + /** + * Restore the content from the bfcache without a message. + */ + Restore = "restore", + + /** + * Reload the content so it starts fresh if the bfcache takes effect. + */ + Reload = "reload", +} + /** * Any options used for loading a movie. */ @@ -451,11 +471,11 @@ export interface BaseLoadOptions { favorFlash?: boolean; /** - * Hide the message when content is restored from the back/forward cache. + * Behavior when the bfcache takes effect * - * @default false + * @default CacheBehavior.Inform */ - hideRestoredMessage?: boolean; + bfcacheBehavior?: CacheBehavior; /** * This is no longer used and does not affect anything. From 7d976a945dad2b89d0931b2c98cc619e894b370c Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Thu, 13 Nov 2025 16:45:14 -0500 Subject: [PATCH 3/3] web: Address nit by renaming CacheBehavior to BFCacheBehavior --- web/packages/core/src/internal/player/inner.tsx | 6 +++--- web/packages/core/src/public/config/default.ts | 4 ++-- web/packages/core/src/public/config/load-options.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/web/packages/core/src/internal/player/inner.tsx b/web/packages/core/src/internal/player/inner.tsx index bb2f986e61f6..1f611a35d89e 100644 --- a/web/packages/core/src/internal/player/inner.tsx +++ b/web/packages/core/src/internal/player/inner.tsx @@ -9,7 +9,7 @@ import { UnmuteOverlay, URLLoadOptions, WindowMode, - CacheBehavior, + BFCacheBehavior, } from "../../public/config"; import { MovieMetadata, ReadyState } from "../../public/player"; import { ruffleShadowTemplate } from "../ui/shadow-template"; @@ -2138,11 +2138,11 @@ export class InnerPlayer { // Do not display the message if another one is already shown or website opted out. if ( this.container.querySelector("#message-overlay") !== null || - this.loadedConfig?.bfcacheBehavior === CacheBehavior.Restore + this.loadedConfig?.bfcacheBehavior === BFCacheBehavior.Restore ) { return; } - if (this.loadedConfig?.bfcacheBehavior === CacheBehavior.Reload) { + if (this.loadedConfig?.bfcacheBehavior === BFCacheBehavior.Reload) { this.reload(); return; } diff --git a/web/packages/core/src/public/config/default.ts b/web/packages/core/src/public/config/default.ts index c4b0df11b12d..a7456b0e4815 100644 --- a/web/packages/core/src/public/config/default.ts +++ b/web/packages/core/src/public/config/default.ts @@ -10,7 +10,7 @@ import { UnmuteOverlay, WindowMode, ScrollingBehavior, - CacheBehavior, + BFCacheBehavior, } from "./load-options"; export const DEFAULT_CONFIG: Required = { @@ -23,7 +23,7 @@ export const DEFAULT_CONFIG: Required = { upgradeToHttps: true, compatibilityRules: true, favorFlash: true, - bfcacheBehavior: CacheBehavior.Inform, + bfcacheBehavior: BFCacheBehavior.Inform, warnOnUnsupportedContent: true, logLevel: LogLevel.Error, showSwfDownload: false, diff --git a/web/packages/core/src/public/config/load-options.ts b/web/packages/core/src/public/config/load-options.ts index 75aa28963dba..cbdada646abd 100644 --- a/web/packages/core/src/public/config/load-options.ts +++ b/web/packages/core/src/public/config/load-options.ts @@ -364,7 +364,7 @@ export enum GamepadButton { /** * The behavior when the bfcache takes effect */ -export enum CacheBehavior { +export enum BFCacheBehavior { /** * Inform the user that the content was restore from the bfcache. */ @@ -473,9 +473,9 @@ export interface BaseLoadOptions { /** * Behavior when the bfcache takes effect * - * @default CacheBehavior.Inform + * @default BFCacheBehavior.Inform */ - bfcacheBehavior?: CacheBehavior; + bfcacheBehavior?: BFCacheBehavior; /** * This is no longer used and does not affect anything.