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

Version 0.1.9 not working from CDN #111

Closed ggarro-ptech closed 1 year ago

ggarro-ptech commented 1 year ago

Issue Summary

​After updating to version 0.1.9 from CDN the library stopped working.

Steps to Reproduce

  1. Open the CDN example from codepen https://codepen.io/buzzone/pen/eYNjJrx
  2. Open the browser console
  3. Load a video from the file input
  4. Check the network tab in the browser console. The MediaInfoModule.wasm throws a 404

Additional info: It works fine if you use version 0.1.8 with this link https://unpkg.com/mediainfo.js@0.1.8/dist/mediainfo.min.js

buzz commented 1 year ago

Thanks for reporting this.

It seems emscripten changed the loader code for the WASM file.

<  var _scriptDir =
<       typeof document !== 'undefined' && document.currentScript
<         ? document.currentScript.src
<         : undefined
<     if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename
---                                                  
>  var _scriptDir =
>       typeof document === 'undefined' && typeof location === 'undefined'
>         ? new (require('u' + 'rl').URL)('file:' + __filename).href
>         : typeof document === 'undefined'
>         ? location.href
>         : (document.currentScript && document.currentScript.src) ||
>           new URL('mediainfo.js', document.baseURI).href

It now prefers location.href over document.currentScript.src.

We can easily override this using Emscripten Module locateFile.

I updated the CodePen and the documentation to reflect this change.