Printing a Page Means Printing the Website
Press Ctrl+P on a news article and the preview tells the whole story: three pages of masthead, a navigation menu down the side of the paper, an ad parked in the middle of the second paragraph, a newsletter signup between the conclusion and the footnotes, and the article itself squeezed into a sixty-character column. The browser prints what it renders, and what it renders is a website, not a document.
PrintClean is my answer to that: one click turns the page you are reading into a clean sheet — the article, set in readable type, everything else left behind — and hands it to the print dialog you already know. The interesting engineering is in the first half of that sentence. "The article" is not a thing the DOM labels for you. You have to find it, and finding it is a scoring problem.
Score the Paragraphs, Not the Containers
The naive approach is to look for a container that "looks like" an article: an <article> tag, a div.post-content, something with a promising class name. That works on well-built sites and fails everywhere else, because class names are marketing, not semantics — content wraps the sidebar on one site and the whole page on another.
The Readability-style approach inverts the question. Instead of guessing which container is the article, score the text and let the containers inherit their score from what they contain. Paragraphs are the unit of scoring because prose has a measurable shape:
- Text length. A navigation item is three words; an article paragraph is forty. Short blocks are almost never the article.
- Comma density. Prose breathes through commas. A list of links, a tag cloud, a menu — none of them have the comma rhythm of sentences. Counting commas per paragraph is a cheap, surprisingly strong prose detector.
- Ancestor decay. A paragraph's score belongs mostly to its immediate container, less to the grandparent, less again to the great-grandparent. Without decay,
<body>wins every election, because it contains everything.
Simplified to its skeleton, the pass looks like this:
// Illustrative, simplified. The real pass also weighs link density
// (a paragraph that is mostly links is navigation, not prose).
function scoreParagraph(p) {
const text = p.textContent.trim();
if (text.length < 25) return 0;
let score = 1; // it exists and is prose-sized
score += (text.match(/,/g) || []).length; // comma density
score += Math.min(Math.floor(text.length / 100), 3);
return score;
}
function propagate(p, score, scores) {
let node = p.parentElement, level = 0;
while (node && level < 3) {
const decay = level === 0 ? 1 : level === 1 ? 0.5 : 0.25;
scores.set(node, (scores.get(node) || 0) + score * decay);
node = node.parentElement;
level++;
}
}
// Walk every <p> (and paragraph-like block), score, propagate,
// then rank containers by accumulated score.
The decay ladder — full score to the parent, half to the grandparent, a quarter above that — is the whole trick. A sidebar full of three-word link texts accumulates almost nothing. A comment thread accumulates some, but its paragraphs are shorter and its containers shallower. The article's container sits on a mountain of prose score that nothing else on the page can match.
Semantics and Class Names as Tie-Breakers, Not Deciders
Scoring alone gets you most of the way. The last few percent come from hints — used as tie-breakers, never as the primary signal. A container that is an <article> or <main> element, or carries a class like post, entry-content or article-body, gets a bonus when its score is close to a competitor's. Negative hints work the same way in reverse: comment, sidebar, footer, nav in a container's identity subtracts from its claim.
The ordering matters. If semantics decide first, you are back to trusting the site's own labelling, which is exactly the thing that cannot be trusted. If semantics only break ties between text-scored candidates, a mislabelled page still extracts correctly, and a well-labelled page extracts a little more confidently. PrintClean's extraction is a scoring pass over paragraphs and their containers, with article/main semantics and common class names as the tie-breaker — in that order.
The Tightening Pass: A Wrapper Must Never Beat Its Own Text
There is a failure mode that pure ancestor scoring walks straight into. Suppose the winning container is div.page-wrapper, and inside it a single child div.article-body holds every scored paragraph. The wrapper's score is high because it contains the article — but printing the wrapper prints the wrapper's other children too: the share bar, the related rail, the "subscribe before you go" box.
So after the winner is chosen, a final tightening pass descends: while the current candidate has a child that carries essentially all of its score, move down to that child. The wrapper can never win over its own text, because the text is what scored in the first place. The pass stops the moment the score splits across siblings — that split is the signal that you have reached the real article boundary, where the prose lives alongside its figures and subheadings rather than inside one nested tube.
This pass is small, maybe twenty lines, and it fixes the single most common "why did my printout include the comments" bug in homegrown extractors. If you build one thing from this article, build the tightening pass.
Rebuild by Whitelist Clone, Not by Hiding Things
Reader modes hide things: they apply a stylesheet that makes the chrome invisible and restyles what remains. That is fine for reading on screen and wrong for paper, because hidden-but-present content still affects layout, and because "hide everything except" is an unbounded list — every site invents new chrome faster than you can hide it.
PrintClean decides what to keep, and rebuilds the document from that decision. The extraction result is cloned into a detached document — a fresh document created with document.implementation.createHTMLDocument(), not attached to any window. Two properties fall out of that choice for free:
- The original page is untouched. No innerHTML surgery on the live DOM, no classes toggled, no elements removed from the site you are reading. Close the reader and the page is exactly as it was, because nothing ever happened to it.
- The clone inherits no site CSS. A detached document has no stylesheets, so the print typography is the only typography. You are not fighting the site's
!importantrules; they simply do not exist in the new document.
Into that clone goes a whitelist: headings, paragraphs, lists, tables, blockquotes, code blocks, figures and captions — the things an article is made of. What does not go in: scripts, styles, forms, navigation, share bars, related-articles rails, newsletter boxes, and anything the live page hid with CSS. That last check has to happen before cloning, on the live page, where getComputedStyle can still see the site's stylesheets — an element with display: none or visibility: hidden is chrome the site itself admitted to hiding, and it does not get a second life on paper. It is not a screenshot either: the result is real text, selectable, searchable, reflowable at any font size, which is the entire difference between a document and a picture of one.
Typesetting for Paper
Once the content is clean, the sheet is typeset like a book page rather than a browser window. PrintClean exposes font size from 13 to 26 px, three line heights, and a measure — the line length — set in pixels, because "65 characters per line" is the oldest readability rule in typography and a browser window ignores it by default. Paper is A4 or Letter, with three margin presets, an optional article header carrying the title, the source URL and the date (the header toggles on and off; there is no footer option) so a printed article can be cited and found again, optional grayscale for a cheaper print, and images on or off.
The detail I care about most: the printed sheet and the on-screen sheet are the same document. The reader view you check before printing is the print layout, not an approximation of it. One page or ten, the article starts at the top of the paper — no masthead, no "page 1 of 7 is a cookie banner".
Batch Mode: Fetch From the Reader Page, Mark Failures in Place
Batch mode takes a list of addresses — up to three on the free tier, fifty with Pro — and produces one document with each article starting on a new page. The architectural decision here is where the fetch happens. Each address is fetched from the reader page itself, with your session cookies, which means pages behind a login work: the paywalled article you can read in your browser is fetched as you, from the extension's reader context, and goes to that site and nowhere else.
The failure policy is the part worth copying. A batch of fifty URLs will contain a URL that 403s, a URL that times out, and a URL that turns out to be a PDF. A naive pipeline throws on the first failure and loses the other forty-nine results. PrintClean marks the failed address in place — a placeholder page saying what happened — and continues the batch. One bad URL costs you one page, not the run.
Where the Text Lives: Memory Only, Deleted After Render
Extraction means an extension briefly holds the full text of what you are reading, so the storage story has to be explicit. The extracted article is handed from the extractor to the reader through the extension's session storage — memory only, never written to disk, cleared when the browser closes — and the payload is deleted the moment the reader has rendered it. Page text is never persisted by the add-on. No article text is uploaded anywhere; there is no analytics, no telemetry, no tracking pixel.
The permissions follow the same discipline: activeTab and scripting so the toolbar icon can read the tab you clicked and only that tab, host access used for exactly two things — injecting the extractor into that tab, and fetching the addresses you paste in batch mode. No content script is registered, so nothing runs on any page until you ask for it. Without a Pro key the only network requests are the batch pages you explicitly asked for; with one, the licence check joins them, throttled to about every two hours, cached for offline use, and a failed check never locks you out.
Free, Pro, and the Honest Limits
Free is permanently free: single-page clean print with every typography setting, A4 and Letter, all three margin presets, the toggleable article header (title, source, date), grayscale, images on or off, and batch up to three addresses. Pro — an optional one-off licence, one key on two browsers — raises batch to fifty and adds the escape hatches a heuristic extractor eventually needs: per-site selectors (hide this, keep that, remembered per domain, most specific domain wins), global selectors for every site, and rules bundles exported and imported as one JSON file. Nothing is time-limited and nothing disables after a trial.
The small print, because an extraction article owes it to you: scoring is a heuristic, and unusual layouts — a novel told in caption-less figures, an article that is one giant table, a page whose prose lives in shadow DOM — can defeat it. That is what the Pro selectors are for, and why they exist as a product feature rather than a promise that the algorithm is perfect. Wide tables can still overflow a paper measure; lazy-loaded images that never entered the viewport may not have a real src to clone. And there is a gate before any of this: a page that fails the article test — body text under roughly 120 words, or link text making up 60% or more of the prose — is refused rather than printed, so non-article pages are left unprocessed instead of getting a mangled sheet. PrintClean is a Manifest V3 extension built for Firefox 140 and later, with Chrome, Edge and Firefox store listings all still coming soon — the product page has the current state. Extraction, typography and printing all work offline; the only thing the network is ever used for is fetching pages you asked for and validating a licence you chose to buy.