darkreader / darkreader

Dark Reader Chrome and Firefox extension
https://darkreader.org/
MIT License
19.66k stars 2.42k forks source link

[Bug] Pages ending with ".pdf" are treated as PDF files, even when they're actually HTML files #11004

Open ghost opened 1 year ago

ghost commented 1 year ago

Prerequisites

Bug Description

Some pages that end in ".pdf" are treated as PDF files even when they're not, therefore dark theme will not apply to these pages.

Steps To Reproduce

  1. Visit https://example.com/example.pdf

Expected Behavior

Dark mode should automatically apply, with an option to disable it

Actual Behavior

Dark mode does not apply, and the description "Disable for PDF Files" is shown instead, with no way to enable dark mode.

Screenshots

No response

Operating System

Ubuntu 22.04

Web Browser name and version

Firefox 110.0

Dark Reader version

4.9.62

Additional Context

This issue seems to stem from lines 186-214 of the /src/utils/url.ts file. My understanding of this function is it first searches the url for ".pdf", then runs some additional logic to exclude certain sites (including wikipedia and dropbox) on top of removing query strings, before checking once again that the page ends in ".pdf".

This can be solved by checking the "Content-Type" in the response headers once the page is downloaded and matching it against "application/pdf".

Dark mode on PDFs can also be enabled through "Settings > Site list > Enable on restricted pages", but this option isn't very clear to users.

Edit: this does apply to actual webpages, such as https://en.wikisource.org/wiki/Index:Final_Report_of_the_Select_Committee_to_Investigate_the_January_6th_Attack_on_the_United_States_Capitol.pdf. I used an example site to illustrate the simplicity of the bug

StormyIceLeopard commented 8 months ago

Dark mode on PDFs can also be enabled through "Settings > Site list > Enable on restricted pages", but this option isn't very clear to users.

I do not see this option