Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript delete navigator object

Tags:

javascript

In a JavaScript window object, there's a navigator object, which has lots of properties describing the clients browser, one of which is an array called plugins. I'm trying to disable this in my personal browser (chrome) by having JavaScript injected after the execution of every webpage I view. In other words, I don't want my plugins to be exposed to the websites I visit.

So I wrote this to be included with every HTTP(S) response on Chrome:

(function(window) {
    delete window.navigator;
}(window));

But the navigator is still there, because in the console when I test it I see:

enter image description here

However, when I manually type delete navigator in the console, it works!

enter image description here

So why is it not working with my JavaScript? It's not a matter of if the script is executing, I've confirmed that it is, its just not removing the navigator object. Any ideas? I've also tried setting it to an empty object, but nothing is unsetting it...

like image 512
Zack Avatar asked Jan 29 '26 17:01

Zack


1 Answers

As of now in Chrome, window.navigator and apis exposed via window.navigator seem to be read-only and simply calling delete on them won't have any effect.

For testing purposes I've been using Object.defineProperty to define a getter that returns null. this works well when a script or polyfill on the page tries to test for the existance of a specific browser api:

Object.defineProperty(window, 'navigator', {
          get() {
            return null;
          },
        });
like image 148
Giulio Dellorbo Avatar answered Jan 31 '26 06:01

Giulio Dellorbo