How can I override navigator.plugins in javascript or how can I set it to null?

navigator.plugins

in javascript provides an array plugin for the browser. Is it possible to set this array to zero? I tried this ( navigator.plugins = null;

) but it didn't set to null. Also, I tried to set it to an empty array ( navigator.plugins = new Array();

)

Also, if possible, is it good practice?

+3


source to share


3 answers


In Chrome, this can be done by setting window.navigator

to null. However, I'm not sure why you would do this. Since you are dealing with JavaScript, it would be possible for someone to use a debugger to stop your code from running and intercept that code before you can set it to null.

Also, the navigator object usually contains information about the client machine, and if I am a user, I most likely know more about my computer than your server, so disabling this will not have any measurable benefit you can see.

Also, this should happen on every page.



Finally, I don't know how other browsers will handle this, but you might very well run into difficulties trying to do this in other browsers.

In short, I don’t think it’s good practice; however, you have not provided details as to why you want to do this. Without this information, I cannot give you a fair answer, except that it is not a good idea. So, of course, you will need to research why you want to do this and determine if it is really worth it.

+2


source


There are several web applications that get the browser name first. The navigator object UIWebView is not returning enough information. eg. navigator.userAgent returns

Mozilla / 5.0 (iPad, OS OS 9_2 like Mac OS X) AppleWebKit / 601.1.46 (KHTML like Gecko) Mobile / 13C75

These web applications were unable to detect the browser name from the above information and exclude the unsupported browser.



To handle such a situation, I override the navigator object as below and yes, the web app could work fine. This failed in firefox, but my requirement was to only support UIWebView

var __originalNavigator = navigator;
navigator = new Object();
navigator.__proto__ = __originalNavigator;
navigator.__defineGetter__('userAgent', function () { return "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"; });
navigator.__defineGetter__('plugins', function () { return []; });

      

+1


source


I've never heard of anyone wanting to set an array of plugins to zero, and to be honest, I don't understand what benefit it would bring if you did. Like jmort253, you can set it to null in chrome, but in other browsers you might not be able to. Be aware that navigator.plugin is not a JavaScript array, but a pluginArray

-2


source







All Articles