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 `