如何在Firefox中禁用已访问链接隐私检查,让JS可访问已访问链接?
在Firefox中让Tampermonkey脚本访问已访问链接的方法
要在你自己的Firefox浏览器里突破检测已访问链接的安全限制,可通过以下步骤实现:
1. 调整Firefox核心配置
这些修改仅作用于你的本地浏览器,不会影响其他用户:
- 在地址栏输入
about:config,点击“接受风险并继续”进入配置页面 - 找到
privacy.resistFingerprinting,将其值设为false(如果原本是true)。该选项会强制统一所有链接的样式,隐藏已访问状态,必须关闭才能让脚本检测到差异 - 找到
layout.css.getComputedStyle.visited,将其值设为true。默认浏览器禁止脚本通过getComputedStyle读取已访问链接的样式,开启此配置即可解除该限制
2. 编写Tampermonkey脚本示例
配置完成后,你可以编写脚本来识别已访问/未访问链接:
// ==UserScript== // @name 识别未访问链接 // @namespace http://tampermonkey.net/ // @version 0.1 // @match https://目标域名/* // 替换成你需要的域名 // @grant none // ==/UserScript== (function() { 'use strict'; // 生成一个未访问的测试链接,获取默认未访问颜色 const testLink = document.createElement('a'); testLink.href = 'https://example.com/never-visited-link'; document.body.appendChild(testLink); const unvisitedColor = getComputedStyle(testLink).color; document.body.removeChild(testLink); // 遍历页面所有链接,筛选未访问的 document.querySelectorAll('a').forEach(link => { const linkColor = getComputedStyle(link).color; if (linkColor === unvisitedColor) { // 这里处理未访问链接,比如添加标记 link.style.borderLeft = '3px solid red'; console.log('未访问链接:', link.href); } }); })();
注意:开启layout.css.getComputedStyle.visited会让所有网站的脚本都能读取已访问链接状态,存在一定隐私风险,仅在你信任的网站上运行脚本即可。
内容的提问来源于stack exchange,提问作者Ariakas
相关产品推荐
相关产品推荐

