Skip to content

Vendor a stopgap wombat.js patch for CSSStyleSheet.replaceSync()/.replace() - #410

Merged
benoit74 merged 1 commit into
mainfrom
benoit74/vendor-css-stylesheet-replacesync-patch
Nov 17, 2026
Merged

benoit74 merged 1 commit into
mainfrom
benoit74/vendor-css-stylesheet-replacesync-patch

Conversation

@benoit74

@benoit74 benoit74 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • insertRule() on the vendored wombat.js already runs its argument through rewriteStyle() before applying it, so any url() reference inside gets rewritten the same way an inline <style> tag would. replaceSync()/.replace() — the Constructable Stylesheets API used by Shadow DOM web components to adopt a stylesheet built from a plain JS string (new CSSStyleSheet().replaceSync(cssText)) — were not patched at all, leaving any url() in that text absolute and unrewritten, 404ing on replay.
  • Confirmed concretely on developer.mozilla.org: several web components (mdn-compat-table-lazy, mdn-survey, mdn-user-menu, mdn-placement-sidebar) each adopt a stylesheet this way for shared icons (browser-compat-table icons, external-link markers, etc.), none of which are visible to any other part of the rewriting pipeline — not a text/css HTTP response, not an inline <style>/style="" attribute in captured HTML, and JsRewriter deliberately doesn't rewrite arbitrary JS string literals.
  • Fixes it the same way insertRule() already is: wraps replaceSync/replace (each guarded on its own existence) to run their CSS text through the existing rewriteStyle() helper first.
  • Same convention as the fetch()/Request() POST-to-GET patch already in this file (for fetch(): convert POST (and other non-GET) requests to GET webrecorder/wombat#242): a local stopgap for an issue reported upstream but not yet fixed there. Reported as CSSStyleSheet.prototype.replaceSync()/.replace() does not rewrite url() the way insertRule() does webrecorder/wombat#249.

Verified on a real built ZIM of developer.mozilla.org content: all previously-404ing compat-table icons (chrome/firefox/safari/edge/opera/samsung-internet/webview/monitor/smartphone/check/external-link) now load correctly in both light and dark mode, with no regression in tests/rewriting/ (767 passed) and the patch applying idempotently against a fresh wombat.js download.

…lace()

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.
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5cb9bd3) to head (7d3bf3a).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #410   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           42        42           
  Lines         2989      2989           
  Branches       457       457           
=========================================
  Hits          2989      2989           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@benoit74
benoit74 merged commit 4732fd5 into main Nov 17, 2026
10 checks passed
@benoit74
benoit74 deleted the benoit74/vendor-css-stylesheet-replacesync-patch branch November 17, 2026 20:03
@benoit74 benoit74 added this to the 5.6.0 milestone Nov 20, 2026
@benoit74 benoit74 mentioned this pull request Nov 20, 2026
18 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant