localStorage is not visible in iFrame – Iframe

by
Ali Hasan
google-chrome iframe local-storage third-party-cookies

Quick Fix: Disable the experimental feature "Third-party storage partitioning" and ensure that third-party cookies are allowed in your browser settings to resolve localStorage visibility issues within iFrames. Refer to developer documentation for more details.

The Problem:

In a web application, users are facing a sporadic issue where data stored in localStorage in a separate tab is not accessible when the same domain is loaded within an iFrame under a different domain. This problem affects specific users and is difficult to reproduce locally, particularly on Windows operating systems. The issue persists even with third-party cookies enabled and proper CORS policies in place. The expected result is to see the localStorage data from the separate tab reflected in the iFrame, but instead, the localStorage appears empty. The issue seems to have emerged around the beginning of August, and the provided resources indicate that it may be related to Chromium browser behavior.

The Solutions:

Solution 1: Disable New Chrome Experimental Feature

A new experimental feature in Chrome called “Third-party storage partitioning” can cause localStorage to not be visible in iFrames. To fix this issue, disable this feature by following these steps:

  1. Open Chrome and navigate to the address bar.
  2. Type chrome://flags/#third-party-storage-partitioning and press Enter.
  3. Find the “Third-party storage partitioning” flag and set it to “Disabled”.
  4. Relaunch Chrome by completely exiting and then restarting the browser.

Check that “Third-party cookies” is enabled for your browser.

Q&A

How to fix missing localStorage data in iFrame?

Disable Chrome’s third-party storage partitioning feature and enable third-party cookies.

What causes localStorage data to disappear in iFrame?

New Chrome feature called third-party storage partitioning.

Where to check localStorage data in iFrame?

Check under the domain of the parent page, not the iFrame.

Video Explanation:

The following video, titled "Share local storage between websites - Javascript - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Share local storage between websites - Javascript Cross-domain local storage Blog post: ...