覆盖浏览器API' s

时间:2017-03-11 12:29:48

标签: javascript firefox-webextensions

我正在为Firefox,Chrome等javascript开发一个webextension。

它旨在防止用户浏览器被指纹识别。

由于用于构建浏览器指纹的大部分信息来自浏览器本身的javascript API,是否可以更改/欺骗常见API可能在webextension / addon中返回的值?

如果这不是直接可行的,那么有没有办法控制这些API返回到网站进行指纹识别以保护用户隐私的价值?

我所说的API的例子是:

user agent
screen print
color depth
current resolution
available resolution
device XDPI
device YDPI
plugin list
font list
local storage
session storage
timezone
language
system language
cookies
canvas print

1 个答案:

答案 0 :(得分:3)

您可以尝试使用Object.defineProperty()

  

Object.defineProperty()方法直接在对象上定义新属性,或修改对象上的现有属性,并返回该对象。

console.log(window.screen.colorDepth); // 24

Object.defineProperty(window.screen, 'colorDepth', {
  value: 'hello world',
  configurable: true 
});

console.log(window.screen.colorDepth); // hello world

在上面我们使用Object.defineProperty来更改属性window.screen.colorDepth的值。这是您使用任何方法欺骗值的地方。您可以使用相同的逻辑来修改您想要欺骗的任何属性(例如navigator.userAgent

但是页面的全局对象和插件全局对象之间存在分离。您应该能够通过将脚本注入文档来克服这个问题:

var code = function() {
    console.log(window.screen.colorDepth); // 24

    Object.defineProperty(window.screen, 'colorDepth', {
      value: 'hello world',
      configurable: true 
    });

    console.log(window.screen.colorDepth); // hello world
};

var script = document.createElement('script');
script.textContent = '(' + code + ')()';
(document.head||document.documentElement).appendChild(script);

有关详细信息,请参阅herehere。 您可以使用上面的代码here下载正常工作的Chrome扩展程序(解压缩文件夹,导航到chrome中的chrome://扩展程序并将文件夹拖放到窗口中)

相关问题