playback instead.
    .catch(() => {
      button.click();
    })
    // Reset button style for both success and error case.
    .finally(() => {
      button.style.opacity = 1.0;
    });
}

/**
 * Attempt to start (full) playback. Waits for the play button to appear and
 * become ready.
 */
async function startFullPlayback() {
  await document.requestStorageAccess();

  // Wait for DOMContentLoaded before looking for the playback button.
  await waitForDOMContentLoaded();

  let numTries = 0;
  let intervalId = setInterval(() => {
    try {
      document.querySelector(SELECTOR_FULL_PLAY).click();
      clearInterval(intervalId);
      console.debug("Clicked play after storage access grant.");
    } catch (e) {}
    numTries++;

    if (numTries >= 50) {
      console.debug("Can not start playback. Giving up.");
      clearInterval(intervalId);
    }
  }, 200);
}

(async () => {
  // Only run the shim for embedded iframes.
  if (window.top == window) {
    return;
  }

  console.warn(
    `When using the Spotify embedded player, Firefox calls the Storage Access API on behalf of the site. See https://bugzilla.mozilla.org/show_bug.cgi?id=1792395 for details.`
  );

  // Already requested storage access before the reload, trigger playback.
  if (sessionStorage.getItem(AUTOPLAY_FLAG) == "true") {
    sessionStorage.removeItem(AUTOPLAY_FLAG);

    await startFullPlayback();
    return;
  }

  // Wait for the user to click the preview play button. If the player has
  // already loaded the full version, this method will do nothing.
  document.documentElement.addEventListener(
    "click",
    previewPlayButtonListener,
    { capture: true }
  );
})();
PK