[Bug] Darkreader breaks browser detection routines on Firefox
See original GitHub issueBug 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:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Good suggestion!
@Gusted, thank you for the explanation!
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 thatwindow.chrome
is then not reliable anymore for browser detection routines.After that, feel free to close my bug report 😉