fix: keep exact clutter selectors from removing majority-content containers#337
Open
mvanhorn wants to merge 3 commits into
Open
fix: keep exact clutter selectors from removing majority-content containers#337mvanhorn wants to merge 3 commits into
mvanhorn wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pages whose main content lives inside a container with an ad-like class (like
<app-root class="ad">) no longer come back empty. The exact-selector clutter pass now skips removing an ambiguous ad-like element when it holds the large majority of the page's text, while explicit clutter (#comments,footer, dialogs, nav) and unsafe tags (script,style,noscript,iframe) stay removable as before.Why this matters
The reporter's page in #283 extracts to zero words. The root cause:
EXACT_SELECTORS'.adentry matches the SPA's root elementapp-root class="ad", which holds essentially all of the page text, and thedisplay:noneprint copy is removed by hidden-element handling, so nothing survives. Any site whose framework root or wrapper happens to carry an ad-like class hits the same total-loss failure, and there is no retry path that disables exact selectors.The guard is deliberately narrow: it only protects elements whose class matches ambiguous ad-like tokens, only when they hold >=80% of the main content's text (minimum 200 chars), and never protects unsafe tags or high-confidence clutter selectors, so existing fixtures are unaffected.
Testing
issues--283-clutter-selector-removes-contentreproduces the reporter's page shape (SPA root withclass="ad", hidden print copy, large inline script): extraction goes from 0 words to the full article, and leaked script HTML is asserted absent.TZ=UTC npx vitest run: 20 files, 371 tests pass.Fixes #283