#Video not loading in Electron Webpack + Typescript App

28 messages · Page 1 of 1 (latest)

gritty sinew
#

Previously I loaded video's by getting them with 'fs', this means they get loaded into the RAM. But I also bumped into another problem where the max video size was 2GB.
Now I'm trying to load them straight from the drive.

  // Create a new video element
  const videoElement = document.createElement("video");
  // Set the video source
  videoElement.src = "file:/" + videoPath;
  videoElement.load();

In my regular Electron App with just javascript, this works fine.
But in Typescript I get the error:
"Refused to load media from 'file://users/jules/Documents/FuneralDesigner/AMPS_TEST/TEMP/VIDEO_1694202616957.mp4' because it violates the following Content Security Policy directive: "default-src 'self' 'unsafe-inline' data:". Note that 'media-src' was not explicitly set, so 'default-src' is used as a fallback."

I tried a lot but can't seem to solve it.
I also can't remake the project in a regular electron app because it's already in project and the project got quite big now.

What is usually the best way to load video's in a typescript + webpack electron app?

PS: "webSecurity: false" This is already set for other reasons.

woeful shale
gritty sinew
#

I also found this link but it also didn't seem to help

woeful shale
#

Still same error?

gritty sinew
#

When I for example add this:

  session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
    callback({
      responseHeaders: {
        ...details.responseHeaders,
        // Allow loading assets from `file://` URLs. and allow to load inline styles alos images
        "Content-Security-Policy": ["*"],
      },
    });
  });

This happens: "GET file://users/jules/Documents/FuneralDesigner/AMPS_TEST/TEMP/VIDEO_1694202616957.mp4 net::ERR_FAILED"

woeful shale
#

your path is wrong

gritty sinew
#

what do you mean?

woeful shale
#

do you have users/jules/... folder?

#

file:// is protocol

gritty sinew
#

so I need to put a third slash?

woeful shale
#

yes

gritty sinew
#

omg

#

it works

#

thank you so much!

woeful shale
#

i dont think you need file:// at all

#

just absole path to file

gritty sinew
woeful shale
#

make sure you remove your header trick in production build

gritty sinew
#

alright, I 've set the check for development build. I'm now building one for production to check if it still works then

#

Wait but actually I don't get it then, so in development it doesn't work without the headers but in production it does?

woeful shale
#

in development you use dev server

#

you files load from it

#

look at request

gritty sinew
#

oh

#

yes, I see now

woeful shale
#

in production you use file protocol instead of http