Repository navigation
Record the original for every rewritten URL attribute - #338
Conversation
Widens the script-src case to src, href and xlink:href on any tag. wombat's getAttribute override looks for the recorded original first and otherwise calls extractOriginalURL, which can only reverse rewrites wombat itself performed. A value rewritten here is unrecognisable to it, so it prepends the original scheme to what is already a relative path. That is openzim/warc2zim#413 as well as #473: same cause, two symptoms. Needs the matching wombat change, since retrieveWBOSRC is SCRIPT-only until then and nothing reads the other attributes back. Measured on en.wikipedia.org/wiki/Whale (1,766 links): 152 attributes added, 0.9% larger gzipped. Most links are fragments or already relative and record nothing. poster is deliberately excluded: wombat rewrites it, this rewriter does not, so it would record nothing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #338 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 42 42
Lines 2798 2801 +3
Branches 417 416 -1
=========================================
+ Hits 2798 2801 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thank you very much! Just for clarification: this change concerns only ZIMs built with scraperlib rewriting, i.e. zimit/warc2zim and mindtouch ATM (the fact you tested on a WPEN page could lead someone to be concerned it might impact mwoffliner ZIMs, which is not the case - at this stage of mwoffliner development at least). Putting PR in draft until wombat PR settles, so we do not merge this by accident (even if it would be harmless, but not really useful either). |
|
Now that upstream PR has been merged, @epheterson do you confirm that we can move this forward and merge? |
The poster test from openzim#339 predates recording originals; a rewritten src now carries __wb_orig_src. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
It returns these recorded originals from getAttribute for any attribute, not just a script's src. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Can someone explain why the change in wombat (and the follow-up) is needed for zim replay, but not for our existing server-side and service worker-based replay? As I recall, the original workaround was a hack having to do with being able to add the modifier like js_ / esm_ that is particular to scripts, and needing to resolve relative paths to absolute for that reason, though there could be a better solution. Why is it that you're running into a double rewriting issue? |
I do not recall about this hack, and looking at our codebase I do not see matching code.
Maybe we just miss the hack (because we ignored it or forgot about it) and went into a too complex solution. ATM we have no way to know JS-side that a URL has already been rewritten. Which causes issue when for instance JS code is fetching a For instance on noted.lol, there is a script which fetches some rewritten |
|
Yup, good to go! Bumped the pin and updated the changelog. |
|
The difference is that a ZIM has no replay prefix. URLs are rewritten at scrape time to plain relative paths inside the archive, like That rewrite also loses information: whether the original was relative or absolute, and the |
benoit74
left a comment
There was a problem hiding this comment.
LGTM, thank you.
@ikreymer I will merge this because I feel like it is providing expected value, but I'm still interested to continue the discussion you've started (thank you for speaking up btw), always good to have a good shared understanding + identify potential better solutions.
Follow-up to #337, widening it from
<script src>tosrc,hrefandxlink:hrefon any tag, as you suggested.extractOriginalURLprepends the original scheme when it cannot recognise a value as one wombat rewrote, so an href rewritten here comes back ashttps://followed by a relative path.retrieveWBOSRCis SCRIPT-only and nothing reads the other attributes back.posteris excluded: wombat rewrites it, this rewriter does not, so it would record nothing.