Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will pay someone to fix this: Unable to import a .webm file #909

Open
1 of 2 tasks
ryanmargono opened this issue Aug 2, 2024 · 7 comments
Open
1 of 2 tasks

Will pay someone to fix this: Unable to import a .webm file #909

ryanmargono opened this issue Aug 2, 2024 · 7 comments

Comments

@ryanmargono
Copy link

ryanmargono commented Aug 2, 2024

Build tool

Vite

Where do you see the problem?

  • In the browser
  • In the terminal

Describe the bug

Not able to import a .webm file to use as a video source.
Am able to import images to use as img sources.
Confirmed this is a plugin issue since i disabled it and ran dev in the browser as standlone vite react app.
When inspecting the popup with dev tools, the asset doesn't show (when hovering the src) while the images do.

Example:

import aura from './sign-in_aura.webm'; // in src/popup/pages/sign-in
...
      <video
        src={aura}
        controls
        playsInline
        muted
        autoPlay
        loop
      />

^ This worked when using Plasmo. And this would be a blocker from us fully migrating to your tool.

Config:

import react from '@vitejs/plugin-react';
import path from 'node:path';
import { defineConfig } from 'vite';
import webExtension from 'vite-plugin-web-extension';

// https://vitejs.dev/config/
export default defineConfig({
  root: '.',
  server: {
    port: 5000,
  },
  plugins: [react(), webExtension()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@app/core': path.resolve(__dirname, '../core/src'),
      '@app/features': path.resolve(__dirname, '../features/src'),
    },
  },
});

Manifest:

{
	"manifest_version": 3,
	"name": "CRXJS React Vite Example",
	"version": "1.0.0",
	"action": { "default_popup": "src/index.html" }
}

Reproduction

N/A

Logs

No response

System Info

System:
    OS: macOS 13.4
    CPU: (12) arm64 Apple M2 Max
    Memory: 88.95 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.1/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
    pnpm: 8.10.5 - ~/.nvm/versions/node/v18.16.1/bin/pnpm
  Browsers:
    Chrome: 127.0.6533.89
    Safari: 16.5

Severity

blocking an upgrade

@ryanmargono ryanmargono changed the title Unable to import a .webm file Will pay someone to fix this: Unable to import a .webm file Aug 5, 2024
@Toumash
Copy link

Toumash commented Aug 6, 2024

Alright i've put the sample as sample.web into the public/assets/sample.web and added

<video src={chrome.runtime.getURL('/assets/sample.webm')} />

into my Popup.tsx

"@crxjs/vite-plugin": "^2.0.0-beta.23",
"vite": "^5.2.11",

my vite.config.ts:

import { crx, defineManifest } from '@crxjs/vite-plugin';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';

....
 plugins: [
   crx({ manifest: createManifest(env) }),
   react(),
 ],

aaaand it works in the 🟢production build but for some reason not in 🔴dev

image

Why it does not work in dev? No idea, the response looks fine just the video does not load
image
Even when looking at the direct response from a vite dev server it looks fine
image

@ryanmargono
Copy link
Author

Working in dev is a hard requirement imo.

@ryanmargono
Copy link
Author

ryanmargono commented Aug 8, 2024

@Toumash what will it take for this to get prioritized? More than happy to work something out.

@Toumash
Copy link

Toumash commented Aug 8, 2024

Its looks like a problem with Chrome's CSP but im not sure. No errors no nothing in the fetch() here

const response = await fetch(url.href.replace(/=$|=(?=&)/g, ''))
in sendToServer.
Only found this thread https://groups.google.com/a/chromium.org/g/chromium-extensions/c/xmg1ez0IxYU

But.
Perhaps the better solution is to host the video yourself. Heck, even github allows for it somehow.
Works on dev and prod.

      <video src={`https://github.com/Toumash/video-csp-test/raw/main/sample.webm`} controls></video>

Works just fine

image

@cpakken
Copy link

cpakken commented Aug 9, 2024

If its a CSP problem sometimes the generated manifest web accessible resources / host permissions is different when in dev vs build. Try checking the generated manifest file to make sure you have permissions for the file.

You might want to a specific manifest config for vite while in dev mode to give your self all the permissions and then change it up when building

@Toumash
Copy link

Toumash commented Aug 10, 2024

@cpakken prod manifest has even less configuration and yet it works. Service worker has it wrong somehow - theres a tip from a comment in the source code

// circumvent extension CSP by creating response from extension origin

image

@ch0c0l8ra1n
Copy link

@ryanmargono Just wondering if the bounty was still on for this before I take a crack at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants