Scenario:
I have parent site A domain A that embeds an iframe with domain B...note that I have control of both sites. Im calling postMessage from site A that posts some information to be stored as cookie in iframe domain B. The iFrame will listen to the postMessage event and set cookie accordingly.
Domain A:
var frame = document.getElementById('exampleFrame');
frame.contentWindow.postMessage({"age":28}, '*');
Embedded iframe domain B:
window.addEventListener('message', messageReceivedEvent, false);
function messageReceivedEvent(e) {
document.cookie("age=" + e.data.age + ";");
console.log(document.cookie);
}
console.log(document.cookie) returns nothing
The issue here is that, once i set the cookie in the messageReceivedEvent, it seems like the cookie is not stored in domain B. Did I missed out something?
Note: This issue only happened in latest Google Chrome version, Firefox works fine.