Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!