最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to detect if Chrome's Devtools are using dark mode? - Stack Overflow

programmeradmin0浏览0评论

In Javascript from a PAGE and not from the devtools themselves is there currently a way to determine if Chrome's devtools are using dark mode instead of the "normal mode"?

I did find a bug report with a ment about this but it looks like that only relates to Chrome extensions.

In Javascript from a PAGE and not from the devtools themselves is there currently a way to determine if Chrome's devtools are using dark mode instead of the "normal mode"?

I did find a bug report with a ment about this but it looks like that only relates to Chrome extensions.

Share Improve this question edited Jan 31, 2017 at 15:40 Alexis Tyler asked Jan 31, 2017 at 15:14 Alexis TylerAlexis Tyler 9686 gold badges32 silver badges51 bronze badges 6
  • Yes. If you open the element inspector on the dev tools, the class -theme-with-dark-background is attached to the document body. Look for that. From there you can write some javascript to get the answer you want. – Seiyria Commented Jan 31, 2017 at 15:33
  • Is that class accessible from a site or just the devtools themselves though? – Alexis Tyler Commented Jan 31, 2017 at 15:35
  • The devtools themselves are an inspectable browser window. As for how you'd access this info from, say, another context like a chrome extension or the parent chrome window, I don't know if that'd be possible. – Seiyria Commented Jan 31, 2017 at 15:37
  • So that doesn't answer this at all. I already mentioned extensions can access this via a built in object. – Alexis Tyler Commented Jan 31, 2017 at 15:38
  • 1 Well, it does provide an answer if you have the devtools up for the devtools themselves. You didn't specify what context you were trying to get this information in. – Seiyria Commented Jan 31, 2017 at 15:39
 |  Show 1 more ment

1 Answer 1

Reset to default 7

No, it's not available from a page.

It is only available for extensions in javascript via:

chrome.devtools.panels.themeName

The name of the color theme set in user's DevTools settings. Possible values: default (the default) and dark.

Since Chrome 59.

Source: https://developer.chrome./extensions/devtools_panels

So it's technically possible to write an chrome-extension that reads the value and then exposes that to the page via a class or javascript variable.
But requiring your visitors to install an extension for detecting dark mode just isn't practical.

发布评论

评论列表(0)

  1. 暂无评论