androidmobile-chrome

Can I stop Chrome on Android refreshing the page when dark mode is toggled?


I have a simple music player app which stores a transient playlist. I also have a scheduled dark mode on my Samsung mobile (running Android 10). When dark mode time comes around (and also if I manually toggle dark mode), Chrome refreshes the page, summarily losing the playlist and cached songs.

Ideally it wouldn't do this. Is there any way to disable this behaviour?

What I've tried

I tried setting the window.onbeforeunload function, which stops me from manually refreshing the page. However, when I toggle the system dark mode, this is ignored and Chrome refreshes the page automatically.

I've tested toggling dark mode on my Windows 10 desktop, and Google Chrome does not refresh the page here.


Solution

  • Well I drafted that question, and thought I'd also check the chrome mobile flags for good measure.

    Turns out there is an option, using the enable-android-night-mode-tab-reparenting flag:

    If enabled, when the user changes themes the tabs are reparented instead of reloaded – Android

    When that is enabled, the tab is repainted instead of reloaded.