google-chromeiframelocal-storagecross-browsercross-domain

Share local storage between site 'x' in a tab and the site 'x' inside an iframe of another site 'y'


Currently my site has a local storage key call isLoggedIn which is set to true after login. when the site is again opened in another tab then the new tab will also be logged in using the local storage value. Till this step no problems occured.

But now when I opened my site in a new tab and logged in. After this I opened another site from a 3rd party and inside this 3rd party site my site is gonna appear as a Iframe. And when i open the iframe it's not using the local storage value from my site in the new tab, instead a new set of values are created and both have separate values.

Local storage Values between two tabs are in sync and same goes for two iframes. But when i try to combine a tab and my site inside an Iframe then they are not in sync.

Can some one try to explain me why this is happening? And any solutions are also welcomed.


Solution

  • This is happening, because people used local storage in iframes, to track people across different websites. So now an iframe has its own context which is separate from the page hosting it.

    The only work around is to have a hidden iframe on the pages where you have your site in a tab and use that to process local storage requests.