Thank you! Detailed answer, it will be useful for other things too.
Anyway, the issue with the Envato iframe comes before PHP, also with JS, I can’t get cookies to work…
I used this code and it is not working when inside and Envato iframe:
document.cookie = name + "=" + value + ";expires=Thu, 01 Jan 1970 00:00:01 GMT" + ";path=/;SameSite=None";
Could you please try to add “secure” & check ? You have to set SameSite to None, and secure to True. document.cookie = name + "=" + value + ";expires=Thu, 01 Jan 1970 00:00:01 GMT" + ";path=/;SameSite=None;Secure";
Mind that the cookies appear in the browser developers tools, they are saved in the source domain, but if you try to read them via JS, they will not work.
Looks like you’ve worked around the problem by using localStorage.
The “speaker” issue is a red herring here – Chrome displays it as an error, but it’s unrelated to your site or Javascript in general (it’s a part of Feature Policy, but support for that varies across browsers).
As you’ve seen, your application is sending cookies without a SameSite attribute, which Chrome now treats as if you’d set them as Lax – meaning they’re only sent when the domain of the page matches the domain of the cookie. In the context of a cross-site iframe, these don’t match, and the cookie is not sent. Setting the attribute to None will solve part of the problem, but you also must set the Secure boolean attribute on the cookie as well (Chrome 80+ requires this).
Please note that this isn’t behavior that Envato has control over; rather it’s the browser manufacturers slowly clamping down on iframes and cross-site interactions, to improve browser security.
Once your cookies set both SameSite=None and Secure, they should start working in the preview iframe again.
You can see that both the Secure and SameSite columns are empty – Secure should contain a checkmark, and SameSite should contain the value None.
When viewing your page within the Market iframe, no cookies are loaded (since they’re missing both values). I built a small test webapp inside an iframe and can duplicate this behavior exactly.
So, for the time being (until browser vendors change something else), cookies can still work within iframes, so long as they have the Secure flag set and use SameSite=None.
There’s an ongoing thread about this issue. It’s unfortunate that you have to resort to allowing cross-site cookies or using local storage, but it’s something that’s only controlled by the browser vendors. We’re considering how we can make this scenario better and hope to have some changes soon.