Closed dotherightthing closed 1 year ago
Tried:
// main.js
const { app, net, protocol } = require('electron');
// tried with and without this:
protocol.registerSchemesAsPrivileged([ {
scheme: 'file',
privileges: {
standard: true,
secure: true
}
} ]);
const createWindow = () => {
...
mainWindow.loadURL('file:///Users/dan/Websites/crop-renamer/index.html'); // replaces mainWindow.loadFile('index.html');
};
app.whenReady().then(() => {
protocol.handle('file', (request) => {
console.log('file://' + request.url.substring(7));
return net.fetch('file://' + request.url.substring(7));
});
...
createWindow();
});
// CrFile.selectFolder
const cookie = {
url: 'file://index.html', // also tried file:///, file:///Users/dan/Websites/crop-renamer/, file:///Users/dan/Websites/crop-renamer/index.html, file:///Users/dan/Websites/crop-renamer
name: 'test', // cookieName,
value: 'test' // folderPath
};
session.defaultSession.cookies.set(cookie)
.then(() => {
console.log('cookie set');
}, (error) => {
console.log(error); // [Error: Cannot set cookie for current scheme]
});
Resolved by writing to a JSON file using https://cameronnokes.com/blog/how-to-store-user-data-in-electron/
Cookies would be ideal, but cannot get these to work with the
file://
protocol.See: