Rewrite ES module scripts for replay - #95
posthog[bot] wants to merge 1 commit into
Conversation
Teach the HTML and content rewriters about `<script type="module">`. Module scripts were excluded from rewriting because the wombat proxy wraps every script in a block scope, which is invalid around top-level import/export. As a result module imports were never rewritten to archive URLs and failed on replay. Add a module path gated on `type="module"`: - A new `esm_` URL modifier and `JSModuleRewriter` that rewrites URLs and location without the block-scope wrapper. - Inline module bodies, module `src`, and `rel=modulepreload` use it. - Served content with the `esm_` modifier resolves to the module rewriter and a JavaScript MIME type. Non-module scripts keep the existing behavior. Generated-By: PostHog Desktop Task-Id: a1580f14-6987-4b24-a7cf-a452ceefe10d
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
CI status noteThe red
This change itself passes the rewrite suite locally on a supported interpreter (Python 3.12): Getting CI green needs a workflow update (drop the end-of-life Python versions and/or bump |
Description
<script type="module">. The change is additive and gated ontype="module", so non-module scripts keep the exact behavior they have today.pywb/rewrite/regex_rewriters.py: addJSModuleRewriter, which reuses the existing URL andlocationrewriting but does not wrap the code in the wombat proxy block scope, and rewrites URLs with a newesm_modifier so imported chunks replay as modules too.pywb/rewrite/html_rewriter.py: rewrite inline module bodies with the module rewriter, and rewrite a modulesrcand<link rel="modulepreload">withesm_. Module state rides on a new_wb_parse_moduleflag; the parse-context name staysscriptso the</script>end tag still closes it.pywb/rewrite/content_rewriter.pyandpywb/rewrite/default_rewriter.py: content served with theesm_modifier resolves to the module rewriter and atext/javascriptMIME type (browsers reject a module served with a non-JS type).Motivation and Context
JSWombatProxyRewriterin a{ let window = ...; ... }block.import/exportare only valid at a module's top level, so modules cannot be wrapped and were excluded from rewriting entirely (_allow_js_typerejectstype="module"). Their import URLs were therefore never rewritten to the archive, so the browser fetched them live and the site content-policy header blocked them.webrecorder/pywbtoo (checked2.10.0b1), so there was no upstream implementation to port.csp-header, andlimit_one_per_daydrift between environments) live in themirrorweb/pfe-nrs-replaydeployment repo and are handled in the companion PR mirrorweb/pfe-nrs-replay#43.Refs WO-1734.
Screenshots (if appropriate):
Types of changes
Checklist:
Created with PostHog Desktop from this inbox report, addressing WO-1734.