question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Darkreader breaks browser detection routines on Firefox

See original GitHub issue

Bug Report

Bug Description

Dark Reader creates the objet window.chrome on Firefox, which breaks browser detection using “duck-typing” methods.

I’ve recently included Dark Reader in some webpack projects (using npm install darkreader) but now Firefox is seen as a Chrome/Chromium browser when checking for window.chrome

I know I could adjust my browser detection routines to use feature detection (or user agent detection), but I still think it’s a bit overkill to unconditionally create the window.chrome object on non-Chrome/Chromium browsers just for internal use. Other JavaScript libraries don’t do that, it pollutes the window object.

The culprit is following code: https://github.com/darkreader/darkreader/blob/0edbc3f2e3f84ed37a0368f1c5445d3157a9c8f0/src/api/chrome.ts#L7

PS: Dark Reader is a great library, thank you for your great work!

Website Address

https://stackoverflow.com/a/9851769/2332350

Steps To Reproduce

Use the code from above stackoverflow link in Firefox in a webpack project with Dark Reader installed:

var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);

Expected Behavior

Previous test should return false on Firefox, but Dark Reader breaks the test by creating a “fake” window.chrome object.

Actual Behavior

Previous test returns true on Firefox.

Screenshots

System Information

  • OS: Windows 10
  • Browser: Firefox 94.0.1
  • Dark Reader Version: 4.9.40

Additional Context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Gustedcommented, Nov 25, 2021

At least, would it be possible to put some comment/warning in the “Using Dark Reader for a website” section? Users should be aware that an object window.chrome could be created after the inclusion of the Dark Reader library and that window.chrome is then not reliable anymore for browser detection routines.

Good suggestion!

0reactions
tbl0605commented, Nov 25, 2021

The name of the file chrome.ts is because we’re using the chrome. namespace - which is btw supported on Firefox.

@Gusted, thank you for the explanation!

As a lot of people(giving experience with current API) will not understand it properly even if it’s clear with warnings and errors.

At least, would it be possible to put some comment/warning in the “Using Dark Reader for a website” section? Users should be aware that an object window.chrome could be created after the inclusion of the Dark Reader library and that window.chrome is then not reliable anymore for browser detection routines.

After that, feel free to close my bug report 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] Dark Reader broken on Firefox Nightly (not able to ...
When page initially loads, Dark Reader fails to properly select and transition light css to dark css. Steps To Reproduce. Dark Reader configs:...
Read more >
Dark mode in all firefox browsing sites do not work now
Hi, I am using the dark mode in firefox which is god sent boon to persons having glaucoma, with dark mode in firefox...
Read more >
How to Make New Tabs in Firefox Dark Mode Friendly
Let's deploy a simple fix to ensure those high-lumen sneak attacks are a thing of the past. Forget Browser Extensions, Modify Your Chrome ......
Read more >
Firefox 96 | Hacker News
If your website supports dark mode and you want to opt-out from browser ... It just means more testing and more bugs, differences...
Read more >
Help – Dark Reader
If you are using Firefox, this is most likely a browser bug, use another mode for such websites. Contacts. For any questions e-mail...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found