How to set custom HTTP request headers?



I would like to set custom http headers on all requests coming from my app.

After doing some research I’ve found the protocol API with the method registerHttpProtocol but i’m a bit unsure how to use it.

Would it be possible to get an example?

Many thanks,

P.S: Protocol docs


I am also curious about this. Did you ever find a solution?



Protocol is for an other things !
You must used WebRequest to modify/add/remove request headers HTTP


const {session} = require('electron')
    const filter = {
            urls: ["http://*/*", "https://*/*"]
session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
        details.requestHeaders['DNT'] = "1";
        details.requestHeaders["Referer"] = "";
        details.requestHeaders["Origin"] = "";
        callback({ cancel: false, requestHeaders: details.requestHeaders })