ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
14.01k stars 816 forks source link

SharedArrayBuffer is not defined in "vite preview" mode while it works fine in "vite" mode with @ffmpeg/core": "^0.11.0" #498

Open htcongvn opened 1 year ago

htcongvn commented 1 year ago

Describe the bug

To Reproduce Steps to reproduce the behavior:

  1. Go to chrome://flags/ and enable Experimental JavaScript shared memory features (aka. SharedArrayBuffers)
  2. yarn build --mode production in order to build the app
  3. yarn preview to run the frontend app on default local port 4173
  4. See error on the Chrome browser's console when go to at http://localhost:4173/ :
    [info] use ffmpeg.wasm v0.11.6
    [info] load ffmpeg-core
    [info] loading ffmpeg-core
    SharedArrayBuffer is not defined

Expected behavior ffmpeg-core and SharedArrayBuffer is defined as it was in "yarn dev" mode. And the browser console log should look like below:

[info] use ffmpeg.wasm v0.11.6
[info] load ffmpeg-core
[info] loading ffmpeg-core
[info] ffmpeg-core loaded
[info] run FS.writeFile rachelMessage.wav <2901 bytes binary file>
[info] run ffmpeg command: -i rachelMessage.wav rachelMessage.mp3
[fferr] ffmpeg version 9e96b1c Copyright (c) 2000-2020 the FFmpeg developers
....

Desktop (please complete the following information):

rambo-panda commented 1 year ago
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

add the headers to your server response

mattiaz9 commented 1 year ago

This is the vite.config.ts that should fix it:

export default {
  server: {
    headers: {
      "Cross-Origin-Embedder-Policy": "require-corp",
      "Cross-Origin-Opener-Policy": "same-origin",
    }
  }
}
deepaksharmaongraph commented 11 months ago

@mattiaz9 can you provide me configuration for vue.config.js but it is causing issue in production again

 configureWebpack: {
        devServer: {
            onBeforeSetupMiddleware: ({ app }) => {
              app.use((_, res, next) => {
                res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
                res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
                next();
              });
            },
          },
deepaksharmaongraph commented 11 months ago

Also I don't wanna to hurt other third party apis like firebase storage

ijt commented 8 months ago

I added those headers and confirmed that they are being added in the Chrome dev console. However, I still get the "SharedArrayBuffer is not defined" error.

Update: I cleared the browser cache and that fixed it.

syjf commented 4 months ago
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

将标头添加到服务器响应

After adding, the iframe and server images cannot be accessed. How can I solve this problem

syjf commented 4 months ago

此外,我不想伤害其他第三方 API,例如 firebase 存储

After adding, the iframe and server images cannot be accessed. How can I solve this problem