-
-
Notifications
You must be signed in to change notification settings - Fork 237
Open
Description
Describe the bug
pywb's JavaScript writer inserts initialization code at the beginning of JS files, placing it before ES6 import statements. This breaks ES6 modules since the ECMAScript specification requires imports to appear before any other code.
Steps to reproduce the bug
- Archive a web page containing an ES6 module with import statements
- Replay the page through pywb
- The injected pywb code appears before imports, causing a syntax error
Example file that breaks:
import { foo } from 'module1';
import bar from 'module2';Becomes:
let window = _init('window'); // ❌ Injected first
import { foo } from 'module1'; // ERROR: imports must be first!Expected behavior
Import statements should remain at the top of the file, with pywb's initialization code inserted after all imports:
import { foo } from 'module1'; // ✅ Imports at top
import bar from 'module2';
let window = _init('window'); // Injected after importsScreenshots
N/A
Environment
- Component: pywb JavaScript rewriter
- Affected files: Any ES6 module with import statements
- Version: All versions prior to fix
Additional context
Root cause: The first_buff mechanism in StreamingRewriter always inserts code at the very beginning without checking for ES6 imports.
Metadata
Metadata
Assignees
Labels
No labels