buzz / mediainfo.js

Extract media file metadata in the browser using WebAssembly.
https://mediainfo.js.org
BSD 2-Clause "Simplified" License
689 stars 107 forks source link

locateFile property is not working correctly in Safari #135

Closed volodymyrbalytskyy closed 11 months ago

volodymyrbalytskyy commented 1 year ago

Issue Summary

​ WASM module location can be overridden with locateFile property. In Chrome and Firefox it appears to work correctly, but in Safari 16 the locateFile override is not picked at all and it tries to fetch the WASM module from the URL the user is currently on (the default behavior).

Steps to Reproduce

For this purpose, created a bare-bones repo which contains a Vite boilerplate and React. https://github.com/volodymyrbalytskyy/mediainfo_locate_safari

  1. clone the repo
  2. run yarn and than yarn dev
  3. open http://127.0.0.1:5173 in Safari browser (port might be different, check output from step 2)
  4. click on file input field and select any video file you have on your computer

EXPECTED behavior

in the Netwrok, the WASM module should be downloaded from https://unpkg.com/mediainfo.js@0.1.9/dist/MediaInfoModule.wasm as locateFile was set to that URL. Here is a snippet preview and actual code snippet here:

    MediaInfoFactory({
      full: true,
      // no matter what is returned here, in Safari 16, it is ignored
      locateFile: () => 'https://unpkg.com/mediainfo.js@0.1.9/dist/MediaInfoModule.wasm',

Here is a screenshot from Chrome

image

ACTUAL behavior

WASM module is downloaded from http://127.0.0.1:5174/MediaInfoModule.wasm

Here is a screenshot from Safari 16

image
buzz commented 1 year ago

I will probably not be able to help with that as I don't own any Apple devices.

You could check this CodePen though. When you load the main script from https://unpkg.com/mediainfo.js/dist/umd/index.min.js, the WASM file is loaded from the parent directory https://unpkg.com/mediainfo.js/dist/. This just works without even using locateFile.

Does the CodePen also fail in Safari?

craftycodie commented 1 year ago

Another solution would be a crude URL rewrite, here's one we use.

      {
        // Rewrites requests for the wasm file to the correct location due to
        // bug with locateFile in mediainfo.js in Safari.
        source: "/:path*/MediaInfoModule.wasm",
        destination: "/MediaInfoModule.wasm",
      },
github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 11 months ago

This issue was closed because it has been inactive for 30 days since being marked as stale.