diff --git a/web/packages/core/src/internal/player/inner.tsx b/web/packages/core/src/internal/player/inner.tsx index a5848340ac55..1f611a35d89e 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, + BFCacheBehavior, } from "../../public/config"; import { MovieMetadata, ReadyState } from "../../public/player"; import { ruffleShadowTemplate } from "../ui/shadow-template"; @@ -2134,8 +2135,15 @@ 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?.bfcacheBehavior === BFCacheBehavior.Restore + ) { + return; + } + if (this.loadedConfig?.bfcacheBehavior === BFCacheBehavior.Reload) { + this.reload(); 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..a7456b0e4815 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, + BFCacheBehavior, } from "./load-options"; export const DEFAULT_CONFIG: Required = { @@ -22,6 +23,7 @@ export const DEFAULT_CONFIG: Required = { upgradeToHttps: true, compatibilityRules: true, favorFlash: true, + 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 18523741ac89..cbdada646abd 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 BFCacheBehavior { + /** + * 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. */ @@ -450,6 +470,13 @@ export interface BaseLoadOptions { */ favorFlash?: boolean; + /** + * Behavior when the bfcache takes effect + * + * @default BFCacheBehavior.Inform + */ + bfcacheBehavior?: BFCacheBehavior; + /** * This is no longer used and does not affect anything. * It is only kept for backwards compatibility.