1
rui902
5y

Every time I turn on device mode on Google Chrome devtools I lose my session (I'm assuming it deletes the cookies).

1. Is this just in my local setup?
2. Is there a way to keep my current session every time I turn on/off device mode on Chrome?
3. What other solutions would I have to do live tests of responsive design on my website?

Thanks!

Comments
  • 1
    It doesn’t delete your cookies, but it does change the user agent header. If your application monitors the user agent to ensure it doesn’t change, then that’s why the session is getting killed.
  • 0
    @Nachfolger I'm not doing anything with the headers, I just have a website with Nginx + CakePHP (don't hate me), and it's using Redis for session handling. I'm using a session cookie, so when I delete the cookie, it also deletes my session and brings me back to the landing page, and it's exact same behaviour when I open device mode...
  • 0
    @rui902

    I’m confused by what you’re saying. Are you deleting the cookie or making the assumption that Chrome is doing that when switching to device emulator mode?

    As I’ve mentioned, when you turn on device emulator, Chrome will automatically modify the user agent header to pretend as if it’s the device you’re emulating (Eg. iPhone blabla).

    CakePHP is a user management / login system correct? I am extremely willing to bet that CakePHP stores the initial user agent in the session file, and upon each request validates your CURRENT user agent with the INITIAL user agent.

    What I’m getting at should be clear. You either need to disable the server side validation temporarily so you can use device emulator, or find another way to test your website as another device.

    I’m on the current Chrome version and it’s not clearing my cookies when I switch to device emulator, so by deduction, my theory is probable.
  • 0
    @Nachfolger I could test that, but at least I never implemented anything to validate session using the user agent, only the session cookie!

    And I totally understand you, no worries ahah

    I will have to see if cakephp is to blame here with some undercover validation that I'm not aware of
  • 0
    @Nachfolger ps. CakePHP is a PHP framework, much like laravel or any other MVC framework (although I really love laravel and would love if i had this whole project in it 😭)
Add Comment