fix: don't infer the date from response headers - #274
Conversation
`addHead` injected `<meta name="date">` built from `last-modified`, `date`
or `age`. Only `last-modified` says anything about the content: `date` is
when the response was generated and `age` how long it sat in a cache.
Any origin that does not send `last-modified` (most dynamic pages) got a
meta date equal to the moment of the request, and `metascraper-date` reads
`meta[name="date"]` first, so that value won as the page date:
https://primary.miltoneducation.com -> date: <now>
The insert guard also tested `meta[property="article:published_time"]`
while inserting `meta[name="date"]`, so a page carrying its own date got a
second, header-derived one appended. It now matches what it inserts, plus
the `name` form `rewriteMetaTags` produces for `article:published_time`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E1yARH3MU7jQYm5J8cAhtR
📝 WalkthroughWalkthroughRemoved response-header date extraction and generated date metadata from HTML rendering. Removed the ChangesDate Metadata Removal
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant ResponseHeaders
participant addHead
participant RenderedHTML
ResponseHeaders->>addHead: provide response headers
addHead->>RenderedHTML: preserve existing date metadata
addHead-->>RenderedHTML: omit generated date metadata
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/html.js`:
- Around line 23-35: Remove getDate and PUBLISHED_TIME_SELECTOR from src/html.js
(lines 23-35), and remove the header-derived date insertion block at src/html.js
(lines 54-56). Delete the obsolete getDate tests in test/html/get-date.js (lines
12-30), and update test/html/add-date.js (lines 16-18) so the last-modified case
asserts that no date meta tag is injected.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9b74ac5a-0f1a-41d7-a08a-711966ca81f3
📒 Files selected for processing (4)
src/html.jstest/html/add-date.jstest/html/get-date.jstest/url.js
Review feedback: consumers run metascraper over the returned markup and it has its own rules to find the date, so there is nothing to compensate for here. Narrowing the injection to `last-modified` still invents metadata the page never declared; remove the tag instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1yARH3MU7jQYm5J8cAhtR
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/html/add-head.js`:
- Line 19: Update the header assertions in the relevant test cases to directly
verify the exact date metadata element, including both name="date" and its
expected content, rather than checking only the timestamp text or absence of a
name attribute. Preserve the existing coverage for non-injection and
preservation behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1a3ffe1a-35ed-46b9-a403-f658d27dec9c
⛔ Files ignored due to path filters (1)
test/snapshots/index.js.snapis excluded by!**/*.snap
📒 Files selected for processing (6)
src/html.jstest/html/add-head.jstest/html/get-date.jstest/index.jstest/pdf.jstest/snapshots/index.js.md
💤 Files with no reviewable changes (2)
- test/html/get-date.js
- test/snapshots/index.js.md
Select `meta[name="date"]` and both `article:published_time` forms and compare the parsed list, so restoring any header-derived tag fails. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1yARH3MU7jQYm5J8cAhtR
What
addHeadinjected a<meta name="date">tag built from the response headers —last-modified, falling back todate, falling back tonow - age.Only
last-modifiedsays anything about the content.dateis when the response was generated andageis how long it sat in a cache, so every origin that does not sendlast-modified(most dynamically served pages) got adateequal to the moment of the request.Seen through microlink:
Reproduced with no browser involved:
metascraper-datereadsmeta[name="date"]as its first rule, so the injected value won over everything the page actually declares.Why remove it rather than restrict it to
last-modifiedConsumers run their own date detection over the returned markup, so there is nothing here to compensate for. Inferring metadata from transport headers only creates values the page never claimed.
The insert was also guarded by
meta[property="article:published_time"]while insertingmeta[name="date"]— a page carrying its own date got a second, header-derived one appended. That goes away with the tag.Tests
test/html/add-head.js— no date is inferred even whenlast-modified,dateandageare all present; a date already in the markup survives untouched.test/url.js/test/snapshots/index.js.md— expectations drop the injected tag.test/index.js,test/pdf.js— drop the$('meta[name="date"]').remove()scrubbing that existed only to make the injected tag deterministic.getDateis gone; it had no consumer outside its own test.Full suite green, except the pre-existing
getaddrinfo ENOTFOUND notexisturl.devuncaught exception intest/index.js, which fails the same way onmaster.🤖 Generated with Claude Code
https://claude.ai/code/session_01E1yARH3MU7jQYm5J8cAhtR
Note
Medium Risk
Changes metadata emitted for downstream scrapers (e.g. microlink/metascraper-date); behavior is intentional but may shift published-date fields for URLs that relied on the old injection.
Overview
Stops injecting
<meta name="date">from HTTP response headers during HTML rewrite (addHead). The removedgetDatehelper and its export are deleted entirely.Previously,
last-modified,date, oragecould produce a date tag that metascraper-date treated as authoritative—even when it only reflected fetch/cache timing, not page content. Dates already in the markup are unchanged.Tests add
test/html/add-head.jsfor the new behavior, droptest/html/get-date.js, and refresh snapshots/integrations that no longer strip an injected date for determinism.Reviewed by Cursor Bugbot for commit 7634516. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
article:published_timemetadata derived from response headers.Tests