Skip to content

Serve ES modules with a wrapper the browser accepts - #892

Open
karenrasmussen wants to merge 1 commit into
mainfrom
fix/esm-script-rewriting
Open

karenrasmussen wants to merge 1 commit into
mainfrom
fix/esm-script-rewriting

Conversation

@karenrasmussen

Copy link
Copy Markdown

Context

Kanopy rebuilt its frontend and now ships it as an ES module. The page loads through Via but never boots: the browser discards the bundle before running a line of it, leaving Kanopy's loading screen up forever. pywb wraps every script it serves in a block which redeclares window, location and the rest so wombat can proxy them.
A module rejects that wrapper twice over, it declares let arguments, which strict mode forbids, and it encloses the module's export in a block.
pywb has no notion of modules at all: every <script src> maps to the classic JS modifier whatever its type. This is a known pywb bug, open since 2022 (webrecorder/pywb#771 for the strict mode error, #964 for the enclosed export, #764 tracking the fix). 2.10.0 doesn't address it, so upgrading isn't a way out.

Changes

A modifier of our own, esm_, applied to <script type="module"> and <link rel="modulepreload">, and a rewriter which serves what carries it: pywb's own wrapper minus let arguments and minus the block. The block can go because a module's outermost scope is already its own, a classic script's is the global scope, which is why pywb needs one. Dropping it also leaves the export at the top level, where it must be.

This branch has not been deployed

No deployments
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