From 7d3bf3a0826fba03711e352f1cd842824cf3d2c5 Mon Sep 17 00:00:00 2001 From: benoit74 Date: Tue, 17 Nov 2026 19:58:29 +0000 Subject: [PATCH] Vendor a stopgap wombat.js patch for CSSStyleSheet.replaceSync()/.replace() insertRule() already runs its argument through rewriteStyle() before applying it, but replaceSync()/.replace() (the Constructable Stylesheets API used by Shadow DOM web components to adopt a stylesheet built from a plain JS string) don't, leaving any url() in that text unrewritten and 404ing on replay. Confirmed on developer.mozilla.org, where several web components (mdn-compat-table-lazy, mdn-survey, mdn-user-menu, mdn-placement-sidebar) adopt stylesheets this way for shared icons. Reported upstream as webrecorder/wombat#249; this is the same kind of interim local patch already used here for #240/#242/#244, kept until upstream lands the real fix. --- rules/patch_wombat.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/rules/patch_wombat.py b/rules/patch_wombat.py index 1ab19be..28f9fd6 100644 --- a/rules/patch_wombat.py +++ b/rules/patch_wombat.py @@ -19,6 +19,12 @@ and (unlike the narrower Location-getter patch this supersedes, previously here for openzim/python-scraperlib#382, webrecorder/wombat#244) `location.replace()`/ `.assign()`/`updateLocation` (openzim/python-scraperlib#396). +- `CSSStyleSheet.prototype.replaceSync`/`.replace()` (the Constructable + Stylesheets API used by Shadow DOM web components to adopt a stylesheet built + from a plain JS string, e.g. `new CSSStyleSheet().replaceSync(cssText)`) not + rewriting `url()` references in that text, unlike `insertRule()` (which already + calls `rewriteStyle()`) -- so any `url()` in such a sheet stays as the original, + unrewritten, absolute URL and 404s on replay. Not yet reported upstream. This script is invoked via `execute_after` on the wombat.js `get_file` action in openzim.toml, right after wombat.js is downloaded, so it runs on every @@ -358,6 +364,48 @@ ")),this._no_rewrite?t:o.extractOriginalURL(t)}))}" ) +# --- CSSStyleSheet.prototype.replaceSync()/.replace(): rewrite url() too ---- +# +# `insertRule()` already runs its argument through `rewriteStyle()` (the same +# regex-based `url()`/`@import` rewriter used for inline `style` attributes), +# but the Constructable Stylesheets API -- `new CSSStyleSheet()` followed by +# `.replaceSync(cssText)` or the async `.replace(cssText)` -- is not patched +# at all, even though it is the standard way a Shadow DOM web component +# adopts a shared stylesheet built from a plain JS string +# (`shadowRoot.adoptedStyleSheets = [sheet]`). Any `url()` reference in that +# text is never seen by any part of the rewriting pipeline: it is not a +# `text/css` HTTP response (`CssRewriter`), not an inline `