JavaScript 判断浏览器是否处于无痕模式
JavaScript Chrome 评论 1 大约 2110 字Chrome
版本74
前
!function () {
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
if (!fs) {
console.log("check failed?");
} else {
fs(window.TEMPORARY, 100, function () {
console.log('FileSystem#非无痕模式')
}, function () {
console.log('FileSystem#无痕模式');
});
}
}();
版本74
- 84.0.4147.135
!function () {
if ('storage' in navigator && 'estimate' in navigator.storage) {
navigator.storage.estimate().then(function (estimate) {
if (estimate.quota < 120000000) {
console.log('storage无痕模式');
} else {
console.log('storage#非无痕模式');
}
});
} else {
console.log('storage#此浏览器版本无法检测是否无痕');
}
}();
使用临时存储限制判断
try {
/*window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY,
function(used, remaining) {
console.log("Used quota: " + used + ", remaining quota: " + remaining);
if (remaining < 120000000) {
console.log('无痕模式');
} else {
console.log('非无痕模式');
}
}, function(e) {
console.log('Error', e);
}
);*/
navigator.webkitTemporaryStorage.queryUsageAndQuota(
function (used, remaining) {
console.log("Used quota: " + used + ", remaining quota: " + remaining);
if (remaining < 120000000) {
console.log('无痕模式');
} else {
console.log('非无痕模式');
}
}, function (e) {
console.log('Error', e);
}
);
} catch (e) {
console.log("window.webkitStorageInfo error#" + e.toLocaleString())
}
Safari
/**
* Safari浏览器判断是否无痕模式
*/
!function () {
let isPrivate = false;
try {
window.openDatabase(null, null, null, null);
} catch (_) {
isPrivate = true;
}
console.log("Safari是否无痕模式#" + isPrivate)
}()
备注
以上方法也可用于移动端。
参考
阅读 6393 · 发布于 2020-09-21
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
-
一枚假程序猿 1楼
Safari测试未通过
Chrome Generic | Win10 2021-01-13
随便看看
换一批
-
java.sql.SQLDataException: ORA-01861: literal does not match format string阅读 3402
-
Golang 创建模块阅读 795
-
OpenResty 中模板渲染引擎 lua-resty-template阅读 5254
-
软考-系统架构设计师:规范化理论-价值与用途阅读 1940
-
Docker 使用 dfimage 从镜像中提取 Dockerfile阅读 293
-
Prometheus+Grafana+rabbitmq_prometheus 监控 RabbitMQ阅读 1062
-
Spring Boot 分层构建 Docker 镜像阅读 273
-
Redis 提示没有权限阅读 2994
-
软考-系统架构设计师:关系代数阅读 1688
-
软考-系统架构设计师:电子商务阅读 1157