0

Website a.com is rendering b.com in iframe. When running website b.com alone, everything is working fine. But when running a.com, website b.com is unable to set or get cookies.

Cookies.set(Key,Value,{sameSite:'None',secure:true,expires:30,domain:'b.com'})

  • When changing same-site option in chrome://flags from default to disable, everything is working as it should.
  • 1
    https://www.simoahava.com/analytics/cookieless-tracking-cross-site-iframes/ – Jaromanda X Oct 19 '20 at 08:37
  • @JaromandaX what is the purpose of passing clientId to iframe? what to do with this clientId? – Mudit Sharma Oct 20 '20 at 07:39
  • 1
    Not my blog - so, the answer is a pineapple - that's just one of many pages I found using google with your question - thought it may have information you need - if not, sorry for wasting our time – Jaromanda X Oct 20 '20 at 09:19
  • but this doesnt helped with cookies. Later I tried with localstorage, both were working some months ago, but now none is working at this moment. – Mudit Sharma Oct 21 '20 at 05:55

1 Answers1

0

Iframe child cookies cannot be set in parent and vice versa. It is restricted due to security reason. The best possible way is using postmessage from parent widow.getElementById("iframeId").contentWindow.postMessage("your message","*");

Child listen to that message

    const allowedOrigins = new Set();
    allowedOrigins.add('localhost:3000');
    await window.addEventListener("message", (event) => {
    if(event.origin) {
    const originUrl = new URL(event.origin);
    const originHost = originUrl.host;
    if(!allowedOrigins.has(originHost)) {
        return;
    } else {
        //do your thing
      }
    }```