Skip to content

fix: replace CDN-loaded Readability with server-side @mozilla/readability#68

Open
octo-patch wants to merge 1 commit into
mishushakov:mainfrom
octo-patch:fix/issue-8-server-side-readability
Open

fix: replace CDN-loaded Readability with server-side @mozilla/readability#68
octo-patch wants to merge 1 commit into
mishushakov:mainfrom
octo-patch:fix/issue-8-server-side-readability

Conversation

@octo-patch

Copy link
Copy Markdown

Fixes #8

Problem

The text format mode loaded @mozilla/readability from the skypack CDN via page.evaluate(), which runs in the browser context. Sites with strict Content Security Policy (CSP) — like Hacker News — block external CDN URLs in their script-src directive, causing the import to fail silently or throw an error.

Solution

Replace the in-browser CDN import with a server-side approach:

  1. Fetch the page HTML using page.content() (runs in Node.js, not the browser)
  2. Parse it with @mozilla/readability + jsdom on the server side, where CSP restrictions do not apply
  3. Fall back to page.innerText('body') if Readability cannot extract an article

This moves the dependency from a runtime CDN fetch to a proper npm package, making it reliable across all sites regardless of their CSP.

Changes

  • src/preprocess.ts: Replace page.evaluate() CDN import with server-side Readability + JSDOM
  • package.json: Add @mozilla/readability and jsdom as dependencies; add @types/jsdom as devDependency

Testing

The fix can be verified by running the scraper in text mode against https://news.ycombinator.com, which previously failed due to CSP blocking the skypack CDN.

…lity (fixes mishushakov#8)

The text format mode previously loaded @mozilla/readability from the
skypack CDN via page.evaluate(), which failed on sites with strict CSP
(e.g. Hacker News), because the CDN URL was blocked by the site's
script-src policy.

This commit replaces the in-browser CDN import with a server-side
approach: the page HTML is fetched via page.content() and parsed using
@mozilla/readability and jsdom running in Node.js, where CSP does not
apply. Falls back to page.innerText('body') if Readability cannot parse
the page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Readable.js on certain pages (like HN)

1 participant