Skip to content

Switching to 'Dark Mode' by itself when window.print() is called on Chrome #6479

Closed

Description

@DogaGencerOSF

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

I'm using window.print() to print preview the docs I created. While doing tests, I noticed that when print preview is opened either with window.print() or ctrl+p, the docusaurus site is switched to the dark mode by itself in Chrome browser. I tested it on two different computers and the result is the same. The storage theme value remains in light but for some reason the site goes dark mode.

This only happens if your system wide dark mode setting is on.

Steps to reproduce

  1. Turn OS dark mode setting on
  2. Get into any docusaurus site (https://docusaurus.io/showcase) with Chrome browser
  3. Press ctrl+p or write window.print() in console

Expected behavior

The theme of the site should not change.

Actual behavior

The theme of the site goes dark mode if it were set light to mode.

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used: 2.0.0-beta.15
  • Environment name and version: Chrome: Version 97.0.4692.99, Node: 16.13.1
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 10 & Windows 11

Reproducible demo

https://codesandbox.io/s/gifted-brahmagupta-juslb?file=/docs/intro.mdx

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Jan 27, 2022
  2. added and removed
    status: needs triage
    on Jan 27, 2022
  3. DogaGencerOSF commented on Jan 27, 2022

    @DogaGencerOSF
    Author
  4. Josh-Cena commented on Jan 27, 2022

    @Josh-Cena
    Collaborator

    I'm still totally clueless whether we are doing something wrong or if this is browser behavior... Looks like Safari has the same behavior as well

  5. slorber commented on Jan 27, 2022

    @slorber
    Collaborator

    I guess it's like opening the site in a new browser session, with localStorage empty 🤷‍♂️

    Maybe we could add an option, or always force light mode in print?

    Is there a use case for printing in dark mode?

  6. Josh-Cena commented on Jan 27, 2022

    @Josh-Cena
    Collaborator

    Is there a use case for printing in dark mode?

    The problem is that it forces you to print in dark mode, which sometimes messes things up because of incompatible colors. (The background stays white)

    The hypothesis about empty local storage makes a lot of sense. I think we should try to preserve the color mode when printing though, if that's ever possible.

    @slorber You can try on different browsers: on Chrome, pressing ⌘ + P immediately changes the color to dark, but on Safari, the page stays light until you close the print popup. Bit unexpected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions