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.
@@ -68,28 +68,50 @@ class BrowserCheck extends HTMLElement {
68
68
  return { name: browserName, version:parseInt(browserVersion) }
69
69
  }
70
70
 
71
- isCookieEnabled () {
72
- const testKey = 'test_cookie';
73
- const testValue = 'test_value';
74
- // 设置测试 Cookie
75
- document.cookie = `${testKey}=${testValue};path=/`;
76
- const cookies = document.cookie.split('; ');
77
- for (let i = 0; i < cookies.length; i++) {
78
- const parts = cookies[i].split('=');
79
- if (parts[0] === testKey && parts[1] === testValue) {
80
- // 删除测试 Cookie
81
- document.cookie = `${testKey}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
82
- return true;
83
- }
84
- }
85
- return false;
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 cookieStatus = this.isCookieEnabled()
91
- console.log(cookieStatus, 'cookieStatus')
92
- if (!cookieStatus) {
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hcui-package",
3
- "version": "1.9.48",
3
+ "version": "1.9.49",
4
4
  "main": "./dist/hcui-package.umd.js",
5
5
  "module": "./dist/hcui-package.es.js",
6
6
  "style": "./dist/hcui-package.css",