Rod*_*own 107 javascript google-chrome incognito-mode
是否可以通过脚本确定Google Chrome是否处于隐身模式?
编辑: 我实际上是指可以通过用户脚本,但答案假设JavaScript正在网页上运行.我在这里重新询问了有关用户脚本的问题.
Alo*_*lok 227
是.在隐身模式下禁用FileSystem API.查看http://jsfiddle.net/w49x9f1a/,当你在并且不处于隐身模式时.
示例代码:
var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
if (!fs) {
console.log("check failed?");
} else {
fs(window.TEMPORARY,
100,
console.log.bind(console, "not in incognito mode"),
console.log.bind(console, "incognito mode"));
}Run Code Online (Sandbox Code Playgroud)
Vin*_*mes 22
在 Chrome 74 到 84.0.4147.135 中,您可以通过估计可用的文件系统存储空间来确定这一点
查看jsfiddle
if ('storage' in navigator && 'estimate' in navigator.storage) {
const {usage, quota} = await navigator.storage.estimate();
console.log(`Using ${usage} out of ${quota} bytes.`);
if(quota < 120000000){
console.log('Incognito')
} else {
console.log('Not Incognito')
}
} else {
console.log('Can not detect')
}
Run Code Online (Sandbox Code Playgroud)
JHu*_*rah 18
一种方法是访问唯一的URL,然后检查是否将该URL的链接视为CSS访问.
您可以在"检测隐身" (死链接)中看到此示例.
同一作者的研究论文取代上面的Detecting Incognito链接
在main.html添加一个iframe,
<iframe id='testFrame' name='testFrame' onload='setUniqueSource(this)' src='' style="width:0; height:0; visibility:hidden;"></iframe>
Run Code Online (Sandbox Code Playgroud)
,以及一些JavaScript代码:
function checkResult() {
var a = frames[0].document.getElementById('test');
if (!a) return;
var color;
if (a.currentStyle) {
color = a.currentStyle.color;
} else {
color = frames[0].getComputedStyle(a, '').color;
}
var visited = (color == 'rgb(51, 102, 160)' || color == '#3366a0');
alert('mode is ' + (visited ? 'NOT Private' : 'Private'));
}
function setUniqueSource(frame) {
frame.src = "test.html?" + Math.random();
frame.onload = '';
}
Run Code Online (Sandbox Code Playgroud)
然后在test.html那里加载到iFrame中:
<style>
a:link { color: #336699; }
a:visited { color: #3366A0; }
</style>
<script>
setTimeout(function() {
var a = document.createElement('a');
a.href = location;
a.id = 'test';
document.body.appendChild(a);
parent.checkResult();
}, 100);
</script>
Run Code Online (Sandbox Code Playgroud)
注意:从文件系统中尝试此操作可能会让Chrome因"不安全的Javascript"而哭泣.但是,它将通过网络服务器提供服务.
小智 5
对于那些寻求解决方案的人来说,以下是截至 2021 年 10 月在各种浏览器中检测隐私浏览模式的当前方法的简要概述:
Chromium:与 Vinnie James 的答案类似,调用 navigator.storage.estimate(),获取配额属性并将其与 Performance.memory.jsHeapSizeLimit 进行比较。如果配额属性小于 jsHeapSizeLimit,则为隐身。如果 jsHeapSizeLimit 未定义,请使用 1073741824 (1 GiB)。
macOS 版 Safari:在不存在的推送服务器上使用 safari.pushNotification.requestPermission 并捕获错误。如果错误中没有出现“手势”,则说明它处于私密模式。
iOS 版 Safari:创建一个 iframe 并在 iframe 上使用 contentWindow.applicationCache 添加错误事件侦听器。如果出现错误,则说明它处于私有模式。
Firefox:navigator.serviceWorker 在私有窗口中将是未定义的。
Internet Explorer:window.indexedDB 在 InPrivate 模式下将是未定义的。
您可以在我在 GitHub 上提供的detectorIncognito脚本中查看这些方法的实现。
| 归档时间: |
|
| 查看次数: |
65482 次 |
| 最近记录: |