sobey-monitor-sdk 1.1.12 → 1.1.13

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/index.esm.js CHANGED
@@ -174,12 +174,30 @@ class ContextManager {
174
174
  this.breadcrumbs = [];
175
175
  }
176
176
  /**
177
- * 生成会话 ID
177
+ * 生成或获取会话 ID
178
+ * sessionId 保存在 sessionStorage 中,同一标签页会话期间保持不变
178
179
  */
179
180
  generateSessionId() {
181
+ const storageKey = '__sobey_monitor_session_id__';
182
+ try {
183
+ const existing = sessionStorage.getItem(storageKey);
184
+ if (existing) {
185
+ return existing;
186
+ }
187
+ }
188
+ catch {
189
+ // sessionStorage 不可用,继续生成新的
190
+ }
180
191
  const timestamp = Date.now().toString(36);
181
192
  const randomPart = Math.random().toString(36).substring(2, 10);
182
- return `${timestamp}-${randomPart}`;
193
+ const newSessionId = `${timestamp}-${randomPart}`;
194
+ try {
195
+ sessionStorage.setItem(storageKey, newSessionId);
196
+ }
197
+ catch {
198
+ // 忽略存储错误
199
+ }
200
+ return newSessionId;
183
201
  }
184
202
  /**
185
203
  * 收集设备信息