skip to Main Content

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");
  },
);

2

Answers


  1. 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)

    Login or Signup to reply.
  2. I think maybe your problem lies with how you’re trying to call requestStorageAccess()

    requestStorageAccess() requests are automatically denied unless the embedded content is currently processing a user gesture such as a tap or click (transient activation), or unless permission was already granted previously. If permission was not previously granted, they need to be run inside a user gesture-based event handler.

    From https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccess#return_value

    Make sure the function is called inside an event listener like an onclick function.

    By the way, as it was an example from MDN (which is the developper of FireFox), it shouldn’t fail on FireFox… Unless you’re not doing it right…

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search