Created
June 4, 2021 09:39
-
-
Save t57ser/591ace911d2274f5500a702d178d7b96 to your computer and use it in GitHub Desktop.
Electron crashes when navigating to custom file protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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