Skip to content

rollup bundles throw TypeError when encountering __WB properties of Function.prototype #191

Open
@ato

Description

@ato

Encountered on https://www.burnet.edu.au/ with both pywb client-side replay and replayweb.page, blank white page with console error:

Uncaught TypeError: Cannot read properties of undefined (reading 'get')
    at _interopNamespace (js-bundle.js.v638853690469027136:30:543)
    at js-bundle.js.v638853690469027136:30:5046
    at js-bundle.js.v638853690469027136:30:283
    at js-bundle.js.v638853690469027136:30:308

Thrown here which appears to come from rollup (ES module bundler):

function _interopNamespace(e) {
    ...
        for (const k in e)                                       // e is a function t(o, i)
            if (k !== "default") {                               // k is "__WB_orig_apply"
                const d = Object.getOwnPropertyDescriptor(e, k); // returns undefined
                Object.defineProperty(n, k, d.get ? d : {        // <-- TypeError because d is undefined
                    enumerable: !0,
                    get: () => e[k]
                })
            }
   ...
}

The problem seems to be that Object.getOwnPropertyDescriptor(e, k) returns undefined because __WB_orig_apply is inherited from Function.prototype.

Possible idea for a fix (untested)

For each of __WB_orig_apply, __WB_orig_bind, __WB_orig_call maybe instead of assigning them with:

$wbwindow.Function.prototype.__WB_orig_apply = orig_apply;

we could define them as not enumerable:

Object.defineProperty($wbwindow.Function.prototype, "__WB_orig_apply", {
  value: orig_apply,
  enumerable: false   // hide from for...in
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions