How to set electron UserAgent

zchrykng picture zchrykng · Feb 27, 2016 · Viewed 19.2k times · Source

I need to set the UserAgent in electron to include the touch flag since I am writing the application for touch screens and it doesn't seem to auto detect that it is running on a touch screen.

Any help would be nice, I already tried setting it in the BrowserWindow.loadURL options param.

Answer

Eric Dela Cruz picture Eric Dela Cruz · Aug 31, 2016

Just use an option object when loading the URL.

function createWindow () {
   win = new BrowserWindow({width: 800, height: 600});
   win.loadURL('http://www.whoishostingthis.com/tools/user-agent/',
     {userAgent: 'Chrome'});

   win.on('closed', () => {
     win = null
   });
}