Uncaught (inpromise) Error on Electron: An object could not be cloned

Asked 1 years ago, Updated 1 years ago, 639 views

Creating part of file upload in Electron (v22).

when going from render.ts to preload.ts to background.ts Uncaught(inpromise)Error:An object could not be cloned.
occurs in the render.ts part.

I don't know the cause, and I can't predict which part is the problem, so I can't fix it.
I would appreciate it if you could advise me on the point of the problem, the cause, and, if possible, how to deal with it.

holder.addEventListener('drop', (event)=>{
    event.preventDefault();
    event.stopPropagation();

    const files = event.dataTransfer.files;

    const file=files[0];
    window.electronAPI.uploadFile(file)
    // ↑ Uncaught (inpromise) Error: An object could not be cloned.

    holder.innerText="Processing..."
});
const{contextBridge, ipcRender}=require('electron')

contextBridge.exoseInMainWorld('electronAPI',{
    // @ts-ignore
    uploadFile:(file)=>ipcRenderer.invoke('file:upload',file)
})
 async function handleFileUpload(event,file){
    let text = wait fs.readFileSync(file.path, 'utf8');
    json=jsonFromText(text); // json is a global variable
}
ipcMain.handle('file:upload', handleFileUpload')

I installed a breakpoint in background.ts using phpstorm.
It doesn't stop, so I don't think I've reached background.ts.

Thank you for your cooperation.

javascript electron

2023-01-02 08:59

1 Answers

ipcRender.invoke() copies arguments using structured replication algorithm, so the File object is not covered.Wouldn't it be better for the renderer to load it into TypedArray before sending it?


2023-01-02 09:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.