javascriptfirefox

Issue with document.requestStorageAccess on Firefox


I just followed this example https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccess#examples to request localStorage access for a cross domain iframe. This works in Chrome. but in Firefox the handle is undefined. I can confirm that the localStorage access has been granted. Any idea why the handle is undefined in Firefox

document.requestStorageAccess({ localStorage: true }).then(
  (handle) => {
    console.log("localStorage access granted");
    handle.localStorage.setItem("foo", "bar");
  },
  () => {
    console.log("localStorage access denied");
  },
);

Solution

  • The types parameter (in your case {localStorage: true}) is not yet(?) supported in Firefox. See the Browser Compatibility.

    Your handle variable becomes undefined because the access to third-party cookies was granted and not types parameter was provided. Not because you didn't specify it, just because Firefox doesn't support it. (See here)