How to override navigator property in electron app


#1

Hi,

Is there a way to override navigator property in electron app.
I want to spoof navigator.platform while accessing few website

Thanks


#2

IF you are using a single page app, you could try load a preload script which runs as follow

    Object.defineProperty(navigator,'platform',{
        value:'hkuc',
        configurable: false,
        writable: false,
    })

But if you have reload, or navigate actions, you will need to find other methods.


#3

Hi,

Thanks for suggestion
preload is the only way to do this?I tried this and it is working
However it is difficult to randomize this attribute if we change platform in preload.js

For first hit I use win32 and next mac , linux etc.
Is there a way I can do that programmatically from render process?


#4

just change writable: false to writable: true and you will be able to change its value in render process