Skip to content

locateFile() not called for .js with EXPORT_ES6 #22508

Open

Description

@jozefchutka

Using emscripten 3.1.65 and -sEXPORT_ES6=1, the following .js is generated

function allocateUnusedWorker() {
                var worker;
                var workerOptions = {
                    type: "module",
                    name: "em-pthread"
                };
                worker = new Worker(new URL("ffmpeg-lgpl-simd.js",import.meta.url),workerOptions);
                PThread.unusedWorkers.push(worker)
            },


function findWasmBinary() {
            if (Module["locateFile"]) {
                var f = "ffmpeg-lgpl-simd.wasm";
                if (!isDataURI(f)) {
                    return locateFile(f)
                }
                return f
            }
            return new URL("ffmpeg-lgpl-simd.wasm",import.meta.url).href
        }

The problem is allocateUnusedWorker() is not calling locateFile() (as findWasmBinary() does) making it hard to customize the URL. Please enhance allocateUnusedWorker() to call locateFile() before constructing .js url

Activity

  1. sbc100 commented on Sep 5, 2024

    @sbc100
    Collaborator

    This is kind of unfortunate. Ideally we would just use new URL(import.meta.url) since we know we are trying to load the same file that is currently running.... however that apparently breaks bundlers. See #22140.

    I wonder if we need a new settings such as BUNDLER_FRIENDLY here since by default it would be really nice to just use new URL(import.meta.url) when we know we want to load ourselves.

  2. jozefchutka commented on Sep 6, 2024

    @jozefchutka
    Author

    In my case, I am not using a standard https://... url, but a blob:https:// url as the main js. Same blob url I would like to use inside allocateUnusedWorker() to avoid any possible network related slow downs.

  3. TingShine commented on Dec 4, 2024

    @TingShine

    In my case, I am not using a standard https://... url, but a blob:https:// url as the main js. Same blob url I would like to use inside allocateUnusedWorker() to avoid any possible network related slow downs.

    The same to me. I must add Module["locateFile"] function manually.

  4. sbc100 commented on Dec 4, 2024

    @sbc100
    Collaborator

    Does new URL with import.meta.url not include the blob:https:// part? What is import.meta.url in your case?

  5. TingShine commented on Dec 4, 2024

    @TingShine

    Does new URL with import.meta.url not include the blob:https:// part? What is import.meta.url in your case?

    I referred to the code of https://github.com/ffmpegwasm/ffmpeg.wasm, passed the workerURL through mainScriptUrlOrBlob in the worker, and then rewrote Module["locateFile"] to obtain the file. So in multithreaded mode and with Export_ES6 added during compilation, I hope that in the allocateUnusedWorker function, the worker address can still be obtained through theModule["locateFile"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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