I am trying to create a Desktop app using Electron JS. The app is supposed to request a video (mp4) file using specific headers and then set the source of the video to the response I get.
My render.js file:
var request = require("request");
const video = document.querySelector("video");
const options = {
url: 'http://somesite.site/resource.mp4',
headers: {
'Referer': 'https://somereferrer.site/'
}
};
request(options).pipe(video.srcObject);
My index.html file:
<script defer src="render.js"></script>
<video controls></video>
My main.js file:
const { app, BrowserWindow } = require('electron')
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors');
function createWindow () {
const win = new BrowserWindow({
title: "Anime Viewer",
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
webSecurity: false
}
})
win.removeMenu();
win.webContents.openDevTools();
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
However, I get the following errors on the console and the video element remains the same:
Uncaught TypeError: Cannot read property 'on' of null
at Request.Stream.pipe (internal/streams/legacy.js:32:8)
at Request.pipe
Uncaught TypeError: Cannot read property 'headers' of null
at Request.pipeDest
Uncaught Error: Parse Error: User callback error
at Socket.socketOnData
Does anyone know what am I doing wrong?