How to send Do Not Track header in electron webview


#1

Hi,

I open lot of websites in my app using webview.
I need to set do not track header for all request .
how to do that, did any one tried this

Thanks
Jk


#2

Hello,
In your main file, add a WebRequest https://electron.atom.io/docs/api/web-request/#webrequestonbeforesendheadersfilter-listener

const electron = require('electron')
const session = electron.session

And after your Browser created mainWindow = new BrowserWindow(… insert that :

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

Shmuel


#3

Hi,

Thanks for the suggestion.
I tried this but it seems it dont have any effect.
I have separate session for webview so i am using following code

session.fromPartition('persist:webviewsession').webRequest.onBeforeSendHeaders(['*://*./*'], (details,callback)=> {
    details.requestHeaders['DNT'] = "1";
callback({cancel: false, requestHeaders: details.requestHeaders})
})

when I visit https://allaboutdnt.com/
It is saying my DNT is disabled

Thanks
Jk


#4

Hello,
Thant you for your link to test.
In my app, that’s run.

Maybe, Do you can used extraHeaders in your webview ?
https://electron.atom.io/docs/api/webview-tag/#webviewloadurlurl-options