clients icon indicating copy to clipboard operation
clients copied to clipboard

Safari Extension Fails to Detect Correct Dark Mode

Open zexpe opened this issue 2 years ago • 11 comments

Steps To Reproduce

Oftentimes the Safari Extension doesn't honour the system Dark Mode setting - the extension would be in light mode when the system is in Dark Mode, or it would be in dark mode when the system is in Light Mode...

Expected Result

That the extension would always switch between light mode and dark mode whenever the system changes.

Actual Result

It's often the opposite.

Screenshots or Videos

No response

Additional Context

No response

Operating System

macOS

Operating System Version

12.3

Web Browser

Safari

Browser Version

15.4

Build Version

1.56.6

zexpe avatar Mar 18 '22 22:03 zexpe

Can you provide any specific steps we can follow to reproduce this?

One thought - do you have your OS theme set to Auto? (i.e. it automatically uses light mode during the daytime and dark mode during nighttime.) If so, I think we're missing the listeners to automatically update the popup if you still have a popup window open (e.g. popped out or sidebar) when the transition occurs.

eliykat avatar Mar 21 '22 22:03 eliykat

Yes, it's set to Auto. This problem isn't unique to the Bitwarden extension. Other extensions seem to suffer from this problem too. It doesn't always happen in a clearly reproducible way but it does happen very frequently - that it's in dark mode when the browser is in light mode, or it's in light mode when the browser is in dark mode.

zexpe avatar Mar 22 '22 11:03 zexpe

It just happened today again. During the day. No manual or automatic changes to the system theme, which remained on light mode all day. I've used the Bitwarden extension multiple times today and it was showing light mode, until just now when it decided to go into dark mode, whilst the system is clearly not in dark mode and the extension is set to the default theme.

Screenshot 2022-03-29 at 15 03 42 Screenshot 2022-03-29 at 15 10 08

Extra image of the Neo Noir Safari Extension which correctly states that the system is in light mode. Screenshot 2022-03-29 at 15 12 15

zexpe avatar Mar 29 '22 14:03 zexpe

Changing the theme to Light manually makes it return to light mode, but then returning that setting to Default then makes it go back into Dark mode.

zexpe avatar Mar 29 '22 14:03 zexpe

Disabling the Safari Extension for Bitwarden and then enabling it again makes it return to Light mode (the system mode) with the Default setting again.

zexpe avatar Mar 29 '22 14:03 zexpe

@eliykat It seems we are checking the theme using a css/js trick inside the platform service, which gets called in the background page. We might need to move that check to the popup and call it on each launch instead.

@zexpe Is it possible the Bitwarden application got updated which restarted the extension? We recently released a new version to the Mac App Store.

Hinton avatar Mar 29 '22 19:03 Hinton

There is another odd bug(?) where sometimes when I open up the Bitwarden desktop app it reinstalls the safari extension. That didn't happen today, but it did happen yesterday. It wasn't when the desktop app was updated - that was a couple of days before...

zexpe avatar Mar 29 '22 20:03 zexpe

I guess it might be possible that that was the first launch of the desktop app after the AppStore update was installed, but that updated refused to install unless Safari was first closed, which gave the impression it would have updated the extension? I'll try to remember to investigate that one in more detail next time an update occurs.

zexpe avatar Mar 29 '22 20:03 zexpe

When the system automatically turned on dark mode, the Bitwarden extension remained in light mode. Screenshot 2022-03-29 at 22 02 20 Screenshot 2022-03-29 at 22 02 30 Disabling then re-enabling the extension fixed it again.

zexpe avatar Mar 29 '22 21:03 zexpe

@Hinton yes you're right, I think we should extract the theming logic into its own service (for all clients) and make sure to run it in the popup in browser.

@zexpe not sure about the update issue, please open a new issue if it happens again and we can investigate.

eliykat avatar Mar 30 '22 09:03 eliykat

Thanks to @addisonbeck the theming logic has been split out with https://github.com/bitwarden/clients/pull/2943. These changes will be included in the 2022.08 release.

@zexpe Please report back, once you've had a chance to test 2022.08

djsmith85 avatar Jun 29 '22 19:06 djsmith85

We need more information before we can help you with your problem. As we haven’t heard from you recently, this issue will be closed.

If this happens again or continues to be an problem, please respond to this issue with the information we’ve requested and anything else relevant.

github-actions[bot] avatar Sep 02 '22 05:09 github-actions[bot]

It's still clearly an issue on 2022.08, which I just updated to yesterday. Screenshot 2022-09-02 at 10 10 25

zexpe avatar Sep 02 '22 09:09 zexpe

@zexpe Thank you for reporting back and I'll re-open this.

Is there any change of behaviour with 2022.08? Any more information you can provide? Does this occur more often/less often, anything else that changed? Does this also happen when not using the Neo Noir Safari Extension?

djsmith85 avatar Sep 02 '22 09:09 djsmith85

I don't have enough experience yet, but I'll keep a note and report back once I've seen various behaviours.

zexpe avatar Sep 02 '22 10:09 zexpe

I've done some tests just changing the system dark mode on and off manually. Bitwarden in the "default" theme does not switch with the system mode. However, as shown Neo Noir does. The first video is with Neo Noir extension disabled, demonstrating I'm in "default" theme mode, and that manually switching the extension theme works. Returning to "default" theme mode it remains in dark mode, whatever the system mode is set to. The second video shows how the Neo Noir extension correctly detects the current system mode.

https://user-images.githubusercontent.com/9435103/188204195-e3333910-d5d1-4541-b766-a9d542c23cc4.mov

https://user-images.githubusercontent.com/9435103/188204476-4ecff5cf-71bb-462a-9d09-4de359a6e22e.mov

zexpe avatar Sep 02 '22 17:09 zexpe

Again, if I now disable the Bitwarden extension and then enable it again it starts up in Light mode, as per the system, and still under the "Default" theme option.

And whilst manually switching the system mode between Light and Dark, the Bitwarden extension now remains in Light mode.

It seems to be sticking to whatever mode the system was in at the point the extension was enabled / browser started.

zexpe avatar Sep 02 '22 17:09 zexpe

Linking https://github.com/bitwarden/clients/pull/3107 here for more context. This definitely only applies to Safari and seems to be due to an upstream issue with Safari.

Code comment from services.module:

// Safari doesn't properly handle the (prefers-color-scheme) media query in the popup window, it always returns light. // In Safari we have to use the background page instead, which comes with limitations like not dynamically changing the extension theme when the system theme is changed.

djsmith85 avatar Oct 11 '22 12:10 djsmith85