Skip to content

Instantly share code, notes, and snippets.

@jmercouris
Created March 15, 2024 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmercouris/5682e62e11b73c8b2e99c303d51eacd0 to your computer and use it in GitHub Desktop.
Save jmercouris/5682e62e11b73c8b2e99c303d51eacd0 to your computer and use it in GitHub Desktop.
test_scheme.js
const { app, net, protocol, BrowserWindow } = require('electron')
const path = require('path')
const { pathToFileURL } = require('url')
protocol.registerSchemesAsPrivileged([
{
scheme: 'a',
privileges: {
standard: true
}
}
]);
protocol.registerSchemesAsPrivileged([
{
scheme: 'b',
privileges: {
standard: false
}
}
]);
app.whenReady().then(() => {
protocol.handle('a', (req) => {
const { host, pathname } = new URL(req.url);
return new Response('<p>Hello</p>', {
headers: { 'content-type': 'text/html' }
})
})
});
app.whenReady().then(() => {
protocol.handle('b', (req) => {
const { host, pathname } = new URL(req.url);
return new Response('<p>world</p>', {
headers: { 'content-type': 'text/html' }
})
})
});
function createWindow() {
const aWindow = new BrowserWindow()
aWindow.loadURL('a:')
const bWindow = new BrowserWindow()
bWindow.loadURL('b:')
}
app.whenReady().then(() => {
createWindow()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment