Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
How to make a custom url for a file in electron

I am trying to build a mini browser using Electron.js. Is it possible to make urls like chrome://settings or about:config, so that when the user goes to that link I can show an html file? I basically want to associate a url with a file in electron.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You could use Data URIs, and base64-encode the contents of your data as a link. You can use Javascript to encode and decode binary data, then you just specify the MIME type at the start.

If you go to the following URL in a browser for example you'll see a png decoded and rendered:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==

The MDN Web doc in the first link mentions the process of base64 encoding an HTML file.

Alternatively, if you just want to force the download of a link you could add the download attribute to your anchor.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use did-start-navigation to detect when they go to chrome://settings/ then intercept that and tell it to go to https://stackoverflow.com/ instead.

Here's the code:

mainWin.webContents.on('did-start-navigation', function (evt, navigateUrl) {
    if (navigateUrl == 'chrome://settings/') {
        evt.preventDefault();
        setTimeout(function () { // Without this it just crashes, no idea why.
            mainWin.loadURL('https://stackoverflow.com/');
        }, 0);
    }
});
I tried the `will-navigate` event, but it didn't work.

Docs for: did-start-navigation

about 4 years ago · Juan Pablo Isaza Denunciar

0

After a little searching at npm, I found a package that does exactly what I want, it's electron protocols. It's a simple way to add custom protolcs in Electron, Here's an example"

const protocols = require('electron-protocols');
const path = require('path');    
protocols.register('browser', uri => {
   let base = app.getAppPath();
      if(uri.hostname == "newtab"){
            return path.join(base,"newtab.html")
      }
 });

In this example, if you go to the link browser://newtab, it opens newtab.html. And if you type location.href the DevTools it shows browser://newtab there too

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda