Closed Rich-Harris closed 1 year ago
@Rich-Harris Thanks for making a note of this. We (Webrecorder project) have actually implemented module detection + different rewriting path in some of our tools (see: webrecorder/wabac.js#101, webrecorder/pywb#810) which does something similar to what you suggest.
For example, oldweb.today use our system for the full stack https://oldweb.today/?browser=ruffle#20230327165731/https://kit.svelte.dev/ and https://express.archiveweb.page/#https://kit.svelte.dev/ would attempt to determine if the JS in a module and apply the correct rewriting. In testing these, I did notice another error (from incorrect assumption that dynamic import implies the code is in a module, marking the inline script as a module), but that's something that should be fixable.
The IA wayback machine only uses wombat.js from Webrecorder, the rest of their stack is their own proprietary implementation, so they would need to implement the module detection on their end, but it is possible.
As long as Svelte doesn't use implicit cross-file globals (see #82), things should generally work. In general, don't think we've seen any replaying Svelte based sites :)
Good to know, thank you! I contacted IA to let them know about this issue, hopefully they'll be able to implement the module detection.
In testing these, I did notice another error (from incorrect assumption that dynamic import implies the code is in a module, marking the inline script as a module), but that's something that should be fixable.
This is now fixed on our end, see this archive and oldweb.today live version. The video can replay if it is archived and the module rewriting is applied
I was looking at archived copies of https://kit.svelte.dev on the Wayback Machine (example), and discovered that the JavaScript errors when it loads:
This is happening because the file in question is a JavaScript module (i.e. it uses
import
/export
syntax):As the error message says,
import
andexport
can only appear at the top level of a module, not inside a function body. Unfortunately this means that Wombat's transformation breaks every site that uses native modules. Today, these sites are in the minority, but since modules are supported in all modern browsers and many tools emit them automatically, the number is growing rapidly.Afraid I don't have a great suggestion for a solution handy! Perhaps something like this, if
import
/export
is detected in the code......where
xyz123
is a base64-encoded module containing the relevant overrides?