Skip to content

Instantly share code, notes, and snippets.

@t57ser
Created June 4, 2021 09:39
Show Gist options
  • Save t57ser/591ace911d2274f5500a702d178d7b96 to your computer and use it in GitHub Desktop.
Save t57ser/591ace911d2274f5500a702d178d7b96 to your computer and use it in GitHub Desktop.
Electron crashes when navigating to custom file protocol
const electron = require("electron");
const path = require("path");
function init() {
let browserWindow1 = new electron.BrowserWindow({
show: true,
x: 500,
y: 100,
width: 900,
height: 900,
webPreferences: {
partition: "persist:test",
}
});
electron.session.fromPartition("persist:test").protocol.registerFileProtocol("test", function (request, callback) {
let finalUrl = path.join(electron.app.getAppPath(), "/test.html");
finalUrl = path.normalize(finalUrl);
callback(finalUrl);
});
browserWindow1.webContents.loadURL("https://example.com");
}
electron.app.on("ready", () => {
init();
});
{
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "13.1.0"
},
"dependencies": {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment