webrecorder / wabac.js

wabac.js - Web Archive Browsing Augmentation Client
https://replayweb.page
GNU Affero General Public License v3.0
96 stars 16 forks source link

Javascript function with the name "import" inside a class gets mistakenly rewritten #163

Closed borsboomm closed 4 months ago

borsboomm commented 4 months ago

When a Javascript class has a function with the name import Wabac tries to wrap it with _wb_rewriteimport

For example:

<script>
  class ContentImporter {
    constructor() {
    }

    import() {
      document.getElementById("import").innerHTML = 'Content written with import function';
    }

    export() {
      document.getElementById("export").innerHTML = 'Content written with export function';
    }

    init() {
      window.onload = () => {
        this.import();
        this.export();
      };
    }
  }
  const importer = new ContentImporter();
  importer.init();
</script>

It becomes:

  class ContentImporter {
    constructor() {
    }

    ____wb_rewrite_import__(null, ) {
      document.getElementById("import").innerHTML = 'Content written with import function';
    }

    export() {
      document.getElementById("export").innerHTML = 'Content written with export function';
    }

    init() {
      window.onload = () => {
        this.import();
        this.export();
      };
    }
  }
  const importer = new ContentImporter();
  importer.init();

}

I've attached a simple warc file where the problem has been isolated from a much bigger real life example.

importfunction.gz

ikreymer commented 4 months ago

Thanks for reporting, should be fixed with better regex matching to ignore this use of 'import'. Will be in 2.17.2 release of wabac.js

ikreymer commented 3 months ago

@borsboomm This fix has now been released in ReplayWeb.page 1.8.16