覆盖浏览器 API

4 javascript firefox-addon-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
Run Code Online (Sandbox Code Playgroud)

Bre*_*son 5

您可以尝试使用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
Run Code Online (Sandbox Code Playgroud)

在上面我们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);
Run Code Online (Sandbox Code Playgroud)

请参阅此处此处了解更多信息。您可以在此处使用上述代码下载可用的 chrome 扩展程序(解压缩文件夹,导航到 chrome://extensions in chrome 并将文件夹放入窗口中)