tree: 33c3bb18b45854a96514dc7f035aec2ba14722b0 [search]
  1. .gitignore
  2. Readability-readerable.js
  3. Readability.js
  4. README.md
  5. run_readability.cjs
third_party/readability/modded_src/README.md

Modded Readability.js

This directory contains Chromium‘s locally modified version of Mozilla’s Readability.js and Readability-readerable.js. These scripts are used by the DOM Distiller component to extract the main content of web pages for Reader Mode.

Modifications to the upstream library should be done directly in these files. Always ensure that regexes and common logic are kept in sync between Readability.js and Readability-readerable.js.

Running Upstream Tests

Upstream's test suite is not checked in. To run it against these files, clone upstream at the Revision in ../README.chromium and copy the files over:

git clone https://github.com/mozilla/readability /tmp/readability
git -C /tmp/readability checkout <Revision from ../README.chromium>
cp third_party/readability/modded_src/Readability*.js /tmp/readability/
cd /tmp/readability && npm install && npm test

Some tests fail on purpose, because of the changes listed under Local Modifications in ../README.chromium, for example the lead <figure> that Chromium adds to the content.

Readability Debugging Tool

This directory also provides run_readability.cjs, a lightweight command-line script to test and debug the distillation logic against arbitrary HTML files without needing a full Chromium build.

Prerequisites

The runner requires jsdom to simulate a browser environment in Node.js. To install it locally within this directory (without committing to the tree), run:

cd third_party/readability/modded_src
npm install --prefix . jsdom

Usage

Run the script using node (specifically .cjs for CommonJS compatibility).

Tip: Save your test page as input.html and distilled results as output.html in this directory. These filenames are already ignored by git.

cd third_party/readability/modded_src
node run_readability.cjs input.html output.html
  • <input.html>: Path to the raw HTML file you wish to distill.
  • [output.html]: (Optional) Path to save the distilled HTML content. If omitted, content is printed to standard output.

Capturing Debug Output

Readability's internal debug logs (which trace scoring and node removal) are printed to stderr during execution. Capture them by redirecting output:

node run_readability.cjs input.html output.html 2> debug.log

AI-Assisted Debugging

This script is ideal for command-line AI agents (like Gemini CLI) to autonomously test distillation fixes:

  1. Obtain the raw HTML of the problematic page.
  2. Run run_readability.cjs input.html output.html 2> debug.log.
  3. Analyze debug.log to understand node scoring or regex matching.
  4. Modify Readability.js and re-run to verify the fix.

Caveats

  • No JavaScript Execution: jsdom does not execute scripts. <noscript> tags may be treated as active content.
  • Post-processing: This script only runs Readability.js. Downstream Chromium post-processing steps are not applied.
  • No Shadow DOM: In production, web_distiller.js runs Readability over a flattened-tree clone so that content inside open shadow roots is visible. jsdom has no shadow DOM and this script clones nothing, so a page whose article body lives inside a web component will distill differently here than it does in Chrome.