"Forget me when I close this site" breaks dark theme preference on websites

Description:
If I enable “Forget me when I close this site”, sites don’t load in dark mode as expected. If I reload the tab, the site is in dark mode.

Reproduction:

  1. Set “Brave Colors” to dark in brave://settings
  2. Enable “Forget me when I close this site” in the brave shields popup
  3. Navigate to google.com. It is in light mode.
  4. Reload google.com. It is in dark mode.
  5. Disabling “Forget me when I close this site” immediately loads the site in dark mode as expected.

Expected result:
Site respects dark mode preference.

Brave Version( check About Brave):
Version 1.66.118 Chromium: 125.0.6422.147 (Official Build) (64-bit)
](https://brave.com/latest/)

Additional Information:

The “forget me” setting doesn’t have anything to do with this, it’s a problem with Google. There are several ways in which a website can respect the user’s choice of theme, but Google is doing something weird and non-standard.

If you delete all your Google cookies at brave://settings/content/all?searchSubpage=google and then reload the Google homepage you’ll get a white background. Examining the page in the Developer Tools window (F12) lets you discover that the colour is set at line 60 of the page’s code:

body {
    background: #fff
}

Once the page has been loaded, there will be a new cookie in the cookies page.

If you reload the Google homepage again and examine the source of the new background colour, you’ll see it’s in the same line of code, but the code is different:

body {
    background: #202124
}

Google is doing something to find your theme preference after the page first loads, and is storing the theme in a cookie so that the it can be sent with the request for the page. The colour is then determined on Google’s servers and embedded in the code.

The normal method for respecting a user’s theme choice is to define colours for both options, and let the browser pick the right one, which will work the first time you load a page.

The normal method will work even if you delete all cookies, but the Google method will not, and there’s no way to fix that in the browser.

Thanks for the explanation!

I suppose “Forget me when I close this site” keeps me from maintaining the dark mode cookie that I otherwise would — problem solved from Brave’s POV.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.