javascriptfacebookcookiesfacebook-instant-games

Facebook Instant Game JS Cookie Chrome Error


we have a game made on JavaScript and HTML. All works fine on Safari, Firefox, and on mobile App. The issue is that on Chrome, on the game page Cookies are NOT set.

We usually do this:

function setCookie(name, value, days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

The function works fine on all the browsers except for Chrome. We even try with a library called js-cookie but it simply doesn't set the values.

Are we missing something?


Solution

  • So the problem was the domain. Facebook use:

    .facebook.com
    

    But the app on Instant Games has another domain like:

    apps-*.apps.fbsbx.com
    

    The cookie is not set because this:

    https://blog.heroku.com/chrome-changes-samesite-cookie
    

    I just chane the cookie to add:

    { sameSite: "None", secure: true, expires: 7 }
    

    And that works fine.