Repository navigation
Add host-gated site-specific JS content patches, fix MDN permalink - #395
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #395 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 42 42
Lines 2937 2947 +10
Branches 450 452 +2
=========================================
+ Hits 2937 2947 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
developer.mozilla.org's top "Try it" widget (<interactive-example>) renders its inner <mdn-play-runner> without the `permalink` attribute, so that component falls back to crypto.randomUUID() for a session-random id instead of the content-derived hash <mdn-live-sample-result> uses elsewhere on the same page (whose own template already always sets `permalink`). A fresh random id can never match anything captured in a WARC, so the widget always fails to load on replay, even though its initial, pre-edit code is just as content-stable as the other live-sample widgets that already work - only the id source differs. Add a small SITE_JS_PATCHES table to JsRewriter, keyed by exact hostname (the host of the article URL currently being rewritten), applied before any other rewriting. Each entry pairs a marker (cheap substring check) with a regex patch, so the regex only ever runs on content that both matches the host AND contains the marker. Register one entry for developer.mozilla.org that adds `permalink` to <interactive-example>'s three <mdn-play-runner> template variants. Verified against the real captured MDN chunk: 3 patches applied when rewritten as developer.mozilla.org, 0 when rewritten as any other host (including lookalikes like developer.mozilla.org.evil.example, where exact-hostname matching rather than a substring check prevents any match). Found via openzim/warc2zim#327. (#394)
benoit74
force-pushed
the
benoit74/mdn-permalink-site-patch
branch
from
November 8, 2026 20:47
abf0025 to
b8e7c59
Compare
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
<interactive-example>(developer.mozilla.org's top "Try it" widget) renders its inner<mdn-play-runner>without thepermalinkattribute, so that component falls back tocrypto.randomUUID()for a session-random id instead of the content-derived hash<mdn-live-sample-result>uses elsewhere on the same page (whose own template already always setspermalink). A fresh random id can never match anything captured in a WARC, so the widget always fails to load on replay — even though its initial, pre-edit code is just as content-stable as the other live-sample widgets that already work; only the id source differs.SITE_JS_PATCHEStable toJsRewriter, keyed by exact hostname (the host of the article URL currently being rewritten, i.e. this JS file's own URL), applied before any other rewriting. Each entry pairs a cheap marker substring check with a regex patch, so the regex only ever runs on content that both matches the host and contains the marker.developer.mozilla.orgthat addspermalinkto<interactive-example>'s three<mdn-play-runner>template variants (choices/console/tabbed).Deliberately scoped as a content-level fix in the existing rewriting pipeline rather than patching WARC files at crawl time (discussed in openzim/warc2zim#327): the pipeline already hands
JsRewriterclean, decoded JS text with no WARC/HTTP framing to worry about, and this follows the same precedentfuzzyRules.jsalready set for narrow, host-scoped quirk handling inside this general-purpose library.Verified against the real captured MDN chunk, not just synthetic test fixtures: 3 patches applied when rewritten as
developer.mozilla.org, 0 when rewritten as any other host — including lookalikes likedeveloper.mozilla.org.evil.exampleandnotdeveloper.mozilla.org, confirming exact-hostname matching (not a substring/prefix/suffix check) is what gates this.Fixes #394, found via openzim/warc2zim#327.