diff --git a/js/index.js b/js/index.js index f5d90d1e..a554cb81 100644 --- a/js/index.js +++ b/js/index.js @@ -84,11 +84,13 @@ const NOISY_ACTION_TYPES = new Set([ const MIN_MILKDROP_WIDTH = 725; let screenshot = false; +let clearState = false; let skinUrl = configSkinUrl; if ("URLSearchParams" in window) { const params = new URLSearchParams(location.search); screenshot = params.get("screenshot"); skinUrl = params.get("skinUrl") || skinUrl; + clearState = Boolean(params.get("clearState")); } function supressDragAndDrop(e) { @@ -296,7 +298,7 @@ Raven.context(async () => { // Expose webamp instance for debugging and integration tests. window.__webamp = webamp; - await bindToIndexDB(webamp); + await bindToIndexDB(webamp, clearState); await webamp.renderWhenReady(document.getElementById("app")); }); diff --git a/js/indexdb.js b/js/indexdb.js index 36563817..73596012 100644 --- a/js/indexdb.js +++ b/js/indexdb.js @@ -2,9 +2,17 @@ import IdbKvStore from "idb-kv-store"; import { throttle } from "./utils"; const LOCAL_STORAGE_KEY = "webamp_state"; -export async function bindToIndexDB(webamp) { +export async function bindToIndexDB(webamp, clearState) { const localStore = new IdbKvStore("webamp_state_database"); + if (clearState) { + try { + await localStore.clear(); + } catch (e) { + console.log("Failed to clear our IndexdB state", e); + } + } + let previousSerializedState = null; try { previousSerializedState = await localStore.get(LOCAL_STORAGE_KEY);