hcui-package 1.9.48 → 1.9.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/BrowserCheck.js +41 -19
- package/package.json +1 -1
|
@@ -68,28 +68,50 @@ class BrowserCheck extends HTMLElement {
|
|
|
68
68
|
return { name: browserName, version:parseInt(browserVersion) }
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
isPrivateBrowsing () {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
|
|
74
|
+
// 尝试写入 localStorage 检测无痕模式
|
|
75
|
+
const testKey = 'test_local_storage';
|
|
76
|
+
try {
|
|
77
|
+
localStorage.setItem(testKey, testKey);
|
|
78
|
+
localStorage.removeItem(testKey);
|
|
79
|
+
// 进一步检测第三方 Cookie
|
|
80
|
+
const iframe = document.createElement('iframe');
|
|
81
|
+
iframe.style.display = 'none';
|
|
82
|
+
iframe.src = 'https://www.baidu.com'; // 替换为实际的第三方测试页面
|
|
83
|
+
document.body.appendChild(iframe);
|
|
84
|
+
iframe.onload = () => {
|
|
85
|
+
try {
|
|
86
|
+
const doc = iframe.contentDocument;
|
|
87
|
+
if (doc && doc.cookie) {
|
|
88
|
+
resolve(false); // 不是无痕模式且允许第三方 Cookie
|
|
89
|
+
} else {
|
|
90
|
+
resolve(true); // 可能处于无痕模式或阻止第三方 Cookie
|
|
91
|
+
}
|
|
92
|
+
} catch (e) {
|
|
93
|
+
resolve(true); // 捕获错误,可能处于无痕模式或阻止第三方 Cookie
|
|
94
|
+
}
|
|
95
|
+
document.body.removeChild(iframe);
|
|
96
|
+
};
|
|
97
|
+
iframe.onerror = () => {
|
|
98
|
+
resolve(true); // 加载失败,可能处于无痕模式或阻止第三方 Cookie
|
|
99
|
+
document.body.removeChild(iframe);
|
|
100
|
+
};
|
|
101
|
+
} catch (e) {
|
|
102
|
+
resolve(true); // 写入失败,可能处于无痕模式
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
resolve(true); // 不支持 localStorage,可能处于无痕模式
|
|
106
|
+
}
|
|
107
|
+
});
|
|
86
108
|
}
|
|
87
109
|
|
|
88
|
-
connectedCallback() {
|
|
110
|
+
async connectedCallback() {
|
|
89
111
|
// 若浏览器cookie被禁用
|
|
90
|
-
const
|
|
91
|
-
console.log(
|
|
92
|
-
if (
|
|
112
|
+
const cookieStatusDisabled = await this.isCookieEnabled()
|
|
113
|
+
console.log(cookieStatusDisabled, 'cookieStatusDisabled')
|
|
114
|
+
if (cookieStatusDisabled) {
|
|
93
115
|
this.shadowRoot.querySelector('.browerWarning').textContent = '浏览器cookie被禁用,请放开cookie权限(或联系管理员)'
|
|
94
116
|
this.shadowRoot.querySelector('.browerWarning').style.display = 'block'
|
|
95
117
|
return
|