SamsungInternet / support

For general Samsung Internet support. You can use the Issues register here as a way to ask support questions.
MIT License
18 stars 0 forks source link

it clears cookie when it's reopend #37

Closed cs09g closed 4 years ago

cs09g commented 6 years ago

Hi,

I set cookies for the website and when it's refreshed, they stay very well. but when it's reopened, all cookies disappear.

the code for the cookie works on other browsers include mobile Safari, Chrome but Samsung internet.

if it has alert on onload and the page is refreshed with current session, then the data is stayed when it's reopened. but when there's no alert then the data is cleared.

poshaughnessy commented 6 years ago

Hi @cs09g. Sorry for the slow reply. Is this in Secret Mode, or in the regular browsing mode? Could you share a test case that we could debug?

cs09g commented 6 years ago

Yeap, it's a bit late though. It happens with regular browsing mode. I asked to samsung browser cs team by email (browser.cs@samsung.com), attached the code sample which handles cookie, but unfortunately no responses yet.

that attached code is:

  1. cookie handling functions

    /**
    * set cookie
    * @param {string} key
    * @param {string} value
    * @param {Object} options
    */
    setCookie: (key, value, options = {}) => {
    let option = options;
    let cookieString = `${key}=${value}`;
    
    if (option.expiration) {
        cookieString += `; expires=${option.expiration}`;
    }
    
    if (option.path) {
        cookieString += `; path=${option.path};`;
    }
    
    document.cookie = cookieString;
    }
    /**
    * return cookie
    * @param {string} key
    * @returns {string}
    */
    getCookie: (key) => {
    let cookies = document.cookie.split(/;\s+/);
    let value = "";
    let cookie;
    
    for (let i = 0, len = cookies.length; i < len; i++) {
        cookie = cookies[i].split("=");
        if (cookie[0] === key) {
            value = cookie[1];
            break;
        }
    }
    
    return value;
    }
  2. part of setting cookie
    
    let expiration = new Date();
    expiration.setDate(expiration.getDate() + 5);

setCookie("Authorize", authString, { expiration: expiration.toUTCString(), path: "/" });

3. part of using cookie

$(() => { let authString = getCookie("Authorize"); // <= when alert added here, cookie stays. but without alert, cookie disppears. });


Code seems no problem as it works well with other browsers. weird thing is number 3. when I add alert to check cookie values, then reopen it, cookie stays. 

the test cases are:

- usual way
  1. create cookie
  2. refresh browser => cookie stays
  3. reopen browser => cookie disappears
- insert `alert` on `onload`
  1. create cookie
  2. refresh browser => cookie stays
  3. reopen browser => cookie disappears
- insert `alert` on `onload` 2
  1. create cookie
  2. refresh browser => cookie stays
  3. refresh brwoser again (to check alert message) **
  4. reopen browser => cookie stays **
cs09g commented 6 years ago

when it has alert, refreshing more than 2 times, then it works as expected. guessing it's about some kind of timing issue.

PicchiKevin commented 4 years ago

Hi, Thank you for opening this issue. We are currently migrating our support channel to the Samsung Developer Forum. If you are still experiencing this issue I'd highly recommend re-opening it here please https://forum.developer.samsung.com/c/samsung-internet/

Thanks again, -Kevin