Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda