webrecorder / wombat

Wombat.js client-side rewriting library
GNU Affero General Public License v3.0
81 stars 31 forks source link

wombat's addition to JavaScript file causing syntax error #127

Closed ldko closed 5 months ago

ldko commented 6 months ago

When replaying this web page in pywb one of the elements is not loading:

carousel_not_loading

There is an error displayed in the console:

Uncaught SyntaxError: redeclaration of let parent                                        main.js:16:5
note: Previously declared at line 10, column 5                                           main.js:10:5

It looks like the code that wombat.js inserts into one of the JavaScript files is causing this because it declares parent which is also declared in the original code:

var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; };
if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } }
{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opener = _____WB$wombat$assign$function_____("opener");
let arguments;

{//Calculating The Browser Scrollbar Width
var parent, child, scrollWidth, bodyWidth;

The issue can similarly be seen on the page replayed in Internet Archive's Wayback that also uses wombat.js.

The element loads correctly in OpenWayback that does not use wombat.js: carousel

This seems similar to what someone commented on in another issue.

ikreymer commented 6 months ago

Have a fix for this in wabac.js, unfortunately, this requires JS parsing, and not directly tied to wombat, so will need to be addressed separately for pywb, but will be fixed in replayweb.page more easily.

ikreymer commented 6 months ago

The approach is similar to that of #82, where it is necessary to detect global vars by parsing JS and ignore overriding parent and others if they are redeclared in the global scope.