#Error with importing const {writeFile} = require('fs') in preload.js

50 messages · Page 1 of 1 (latest)

random sundial
#

Throws unable to load preload script.

sharp egret
#

sandbox: false in webPreferences

random sundial
#

how do you know this? And how do I find this myself?

sharp egret
#

One key security feature in Chromium is that processes can be executed within a sandbox. The sandbox limits the harm that malicious code can cause by limiting access to most system resources — sandboxed processes can only freely use CPU cycles and memory. In order to perform operations requiring additional privilege, sandboxed processes use dedi...

#

relatively new thing so everyone have issue with it

random sundial
#

I see, thanks again!

#

running into one last error.

#

async function handleStop(e) {
const blob = new Blob(recordedChunks, {
type: 'video/webm; codecs=vp9'
});

const buffer = await blob.arrayBuffer();
const filePath = window.electron.openFile();

if (filePath){
window.electron.saveFile(buffer, filePath);
}
}

#

Uncaught (in promise) Error: filePath is not defined

sharp egret
#

need full stacktrace

random sundial
#

as in how the function is running?

sharp egret
#

screenshot with error

#

not only error message

#

and how openFIle function looks like

random sundial
#

render.js:79 Uncaught (in promise) Error: filePath is not defined
at MediaRecorder.handleStop (render.js:79:19)
handleStop @ render.js:79

#

openFile: () => ipcRenderer.invoke('dialog:openFile'),

#

ipcMain.handle('dialog:openFile', handleFileOpen);

#

async function handleFileOpen() {
const { canceled, filePaths } = await dialog.showOpenDialog({
properties: ["openDirectory"],
});
if (canceled) {
return
} else {
return filePaths[0]
}
}

sharp egret
#

const filePath = await window.electron.openFile();

random sundial
#

Uncaught (in promise) Error: filePath is not defined
at MediaRecorder.handleStop (render.js:79:19)
handleStop @ render.js:79

#

now getting that

sharp egret
#

mm

random sundial
#

and 79 is window.electron.saveFile(buffer, filePath);

#

I also tried console.log(filePath)

#

and it printed the path just fine

sharp egret
#

show me saveFile function

random sundial
#

uh oh

#

I think I caught it

#

🤦‍♂️

#

I caught the first error

#

saveFile: () => writeFile(filePath, buffer, () => console.log('video saved successfully!')),

#

saveFile: (filePath, buffer) => writeFile(filePath, buffer, () => console.log('video saved successfully!')),

#

now getting render.js:80 Uncaught (in promise) Error: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of ArrayBuffer
at MediaRecorder.handleStop (render.js:80:19)

sharp egret
#

window.electron.saveFile(buffer, filePath)

random sundial
#

looks like need to convert arraybuffer

sharp egret
#

no

#

wrong arg order

random sundial
#

🤦‍♂️

#

I think I still need to convert to buffer

#

must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of ArrayBuffer
at MediaRecorder.handleStop

sharp egret
#

new Uint8Array(buffer)

#

const buffer = new Uint8Array(await blob.arrayBuffer());

random sundial
#

holy cow!

#

it worked!

#

@sharp egret thank you so much dude!

#

thank you for guiding me along. I'm brand new to this and it's very confusing. I really appreciate your help!

sharp egret
#

when you faced with freezing suggest you to move your recording code into preload