customer-chat-sdk 1.0.68 → 1.0.71

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.
@@ -14340,9 +14340,6 @@ class ScreenshotManager {
14340
14340
  this.scheduleNextFn = null;
14341
14341
  // 图片代理缓存(带过期时间)
14342
14342
  this.imageProxyCache = new Map();
14343
- // IndexedDB 缓存(持久化)
14344
- this.indexedDBCache = null;
14345
- this.indexedDBReady = false;
14346
14343
  // Intersection Observer(用于高效检测可见性)
14347
14344
  this.intersectionObserver = null;
14348
14345
  this.visibleElementsCache = new Set();
@@ -14377,13 +14374,10 @@ class ScreenshotManager {
14377
14374
  maxConcurrentDownloads: options.maxConcurrentDownloads ?? 10, // 增加并发数
14378
14375
  onlyVisibleImages: options.onlyVisibleImages ?? true, // 默认只处理可视区域
14379
14376
  imageCacheTTL: options.imageCacheTTL ?? 600000, // 默认10分钟(600000ms)
14380
- useIndexedDB: options.useIndexedDB ?? true, // 默认启用 IndexedDB 持久化缓存
14381
14377
  usePreconnect: options.usePreconnect ?? true, // 默认预连接代理服务器
14382
14378
  imageLoadTimeout: options.imageLoadTimeout ?? 5000, // 默认5秒超时
14383
14379
  useIntersectionObserver: options.useIntersectionObserver ?? true, // 默认使用 Intersection Observer
14384
14380
  fetchPriority: options.fetchPriority ?? 'high', // 默认高优先级
14385
- maxCacheSize: options.maxCacheSize ?? 50, // 默认最大50MB
14386
- maxCacheAge: options.maxCacheAge ?? 86400000, // 默认24小时(86400000ms)
14387
14381
  maxImageSize: options.maxImageSize ?? 5, // 不使用代理时,单个图片最大尺寸(MB),默认5MB
14388
14382
  skipLargeImages: options.skipLargeImages ?? true, // 不使用代理时,是否跳过过大的图片,默认true(跳过)
14389
14383
  workerNumber: options.workerNumber ?? undefined // modern-screenshot Worker 数量,默认自动计算(undefined 表示自动)
@@ -14406,15 +14400,6 @@ class ScreenshotManager {
14406
14400
  if (this.options.useIntersectionObserver && this.options.onlyVisibleImages) {
14407
14401
  this.initIntersectionObserver();
14408
14402
  }
14409
- // 初始化 IndexedDB(如果启用)
14410
- if (this.options.useIndexedDB) {
14411
- this.initIndexedDB().catch(() => {
14412
- // IndexedDB 初始化失败,回退到内存缓存
14413
- if (!this.options.silentMode) {
14414
- console.warn('📸 IndexedDB 初始化失败,使用内存缓存');
14415
- }
14416
- });
14417
- }
14418
14403
  }
14419
14404
  /**
14420
14405
  * 设置目标元素
@@ -14879,20 +14864,12 @@ class ScreenshotManager {
14879
14864
  if (this.options.preloadImages && this.options.enableCORS && selectedEngine === 'modern-screenshot') {
14880
14865
  // 清理过期缓存
14881
14866
  this.cleanExpiredCache();
14882
- // 如果启用 IndexedDB,也清理 IndexedDB 缓存
14883
- if (this.options.useIndexedDB) {
14884
- await this.cleanIndexedDBCache();
14885
- }
14886
14867
  await this.preprocessNetworkImages(this.targetElement);
14887
14868
  await this.waitForImagesToLoad(this.targetElement);
14888
14869
  }
14889
14870
  else {
14890
14871
  // 即使不预加载,也清理一下过期缓存
14891
14872
  this.cleanExpiredCache();
14892
- // 如果启用 IndexedDB,也清理 IndexedDB 缓存
14893
- if (this.options.useIndexedDB) {
14894
- await this.cleanIndexedDBCache();
14895
- }
14896
14873
  }
14897
14874
  let dataUrl;
14898
14875
  // 根据选择的引擎进行截图
@@ -15685,18 +15662,6 @@ class ScreenshotManager {
15685
15662
  }
15686
15663
  return cachedDataUrl;
15687
15664
  }
15688
- // 检查 IndexedDB 缓存(如果启用)
15689
- if (this.options.useIndexedDB) {
15690
- const indexedDBCache = await this.getIndexedDBCache(url);
15691
- if (indexedDBCache) {
15692
- // 同步到内存缓存
15693
- this.setCachedImage(url, indexedDBCache);
15694
- if (!this.options.silentMode) {
15695
- console.log(`📸 ✅ 使用 IndexedDB 缓存图片: ${url.substring(0, 50)}...`);
15696
- }
15697
- return indexedDBCache;
15698
- }
15699
- }
15700
15665
  try {
15701
15666
  // 构建代理请求参数
15702
15667
  const params = new URLSearchParams({
@@ -15736,10 +15701,6 @@ class ScreenshotManager {
15736
15701
  const dataUrl = await this.blobToDataUrl(blob);
15737
15702
  // 缓存结果(带时间戳,10分钟有效)
15738
15703
  this.setCachedImage(url, dataUrl);
15739
- // 如果启用 IndexedDB,也保存到 IndexedDB
15740
- if (this.options.useIndexedDB) {
15741
- await this.setIndexedDBCache(url, dataUrl);
15742
- }
15743
15704
  return dataUrl;
15744
15705
  }
15745
15706
  catch (fetchError) {
@@ -15755,66 +15716,9 @@ class ScreenshotManager {
15755
15716
  return url;
15756
15717
  }
15757
15718
  }
15758
- // 如果没有配置代理,需要添加内存保护机制
15759
- // 不使用代理时,modern-screenshot 会直接下载图片,可能导致内存问题
15760
- // 由于已配置 CORS,可以直接下载并检查大小
15761
- if (this.options.enableCORS) {
15762
- // 对于不使用代理的情况,添加内存保护和缓存机制:
15763
- // 1. 先检查内存缓存(避免重复下载)
15764
- // 2. 检查 IndexedDB 缓存
15765
- // 3. 使用下载队列避免并发重复下载
15766
- // 4. 下载时检查大小,如果过大则使用占位符
15767
- // 先检查内存缓存(优先使用缓存,避免重复下载)
15768
- const cachedDataUrl = this.getCachedImage(url);
15769
- if (cachedDataUrl) {
15770
- if (!this.options.silentMode) {
15771
- console.log(`📸 ✅ 使用内存缓存图片(无代理模式): ${url.substring(0, 50)}...`);
15772
- }
15773
- return cachedDataUrl;
15774
- }
15775
- // 检查 IndexedDB 缓存(如果启用)
15776
- if (this.options.useIndexedDB) {
15777
- const indexedDBCache = await this.getIndexedDBCache(url);
15778
- if (indexedDBCache) {
15779
- // 同步到内存缓存
15780
- this.setCachedImage(url, indexedDBCache);
15781
- if (!this.options.silentMode) {
15782
- console.log(`📸 ✅ 使用 IndexedDB 缓存图片(无代理模式): ${url.substring(0, 50)}...`);
15783
- }
15784
- return indexedDBCache;
15785
- }
15786
- }
15787
- // 检查是否正在下载(避免重复下载)
15788
- if (this.imageDownloadQueue.has(url)) {
15789
- // 如果已经在下载队列中,等待现有下载完成
15790
- if (!this.options.silentMode) {
15791
- console.log(`📸 ⏳ 等待图片下载完成: ${url.substring(0, 50)}...`);
15792
- }
15793
- return await this.imageDownloadQueue.get(url);
15794
- }
15795
- // 检查并发下载数限制
15796
- if (this.activeDownloads.size >= this.maxConcurrentImageDownloads) {
15797
- // 并发数已满,返回原 URL,让 modern-screenshot 自己处理(可能会失败,但不阻塞)
15798
- if (!this.options.silentMode) {
15799
- console.warn(`📸 ⚠️ 并发下载数已满(${this.activeDownloads.size}/${this.maxConcurrentImageDownloads}),跳过: ${url.substring(0, 50)}...`);
15800
- }
15801
- return url;
15802
- }
15803
- // 创建下载 Promise 并加入队列
15804
- const downloadPromise = this.downloadImageWithoutProxy(url);
15805
- this.imageDownloadQueue.set(url, downloadPromise);
15806
- this.activeDownloads.add(url);
15807
- try {
15808
- const result = await downloadPromise;
15809
- return result;
15810
- }
15811
- finally {
15812
- // 下载完成后清理
15813
- this.imageDownloadQueue.delete(url);
15814
- this.activeDownloads.delete(url);
15815
- }
15816
- }
15817
- // 默认返回原 URL
15719
+ // 如果没有配置代理,直接返回原 URL,让 modern-screenshot 自己处理
15720
+ // 不再主动下载图片,避免阻塞和耗时过长
15721
+ // 如果 modern-screenshot 无法处理跨域图片,建议配置代理服务器
15818
15722
  return url;
15819
15723
  };
15820
15724
  // 检查元素是否可见且有尺寸
@@ -15911,14 +15815,10 @@ class ScreenshotManager {
15911
15815
  console.log(`📸 使用元素实际尺寸: ${elementWidth}x${elementHeight}`);
15912
15816
  }
15913
15817
  }
15914
- // 缩放配置:移动设备使用更低的缩放比例,进一步减少图片大小
15818
+ // 缩放配置:使用外部传递的参数
15915
15819
  // scale < 1 会降低图片分辨率,减少 base64 大小
15916
- if (this.options.scale !== 1) {
15917
- contextOptions.scale = isMobile ? 0.7 : this.options.scale; // 移动设备:0.8 -> 0.7
15918
- }
15919
- else if (isMobile) {
15920
- // 如果未指定 scale,移动设备默认使用 0.7
15921
- contextOptions.scale = 0.7;
15820
+ if (this.options.scale !== undefined && this.options.scale !== 1) {
15821
+ contextOptions.scale = this.options.scale;
15922
15822
  }
15923
15823
  // 优化:复用 context,避免频繁创建和销毁(性能提升 20%+)
15924
15824
  // 只在元素变化、配置变化或内容变化时重新创建 context
@@ -16116,28 +16016,83 @@ class ScreenshotManager {
16116
16016
  if (!this.options.silentMode) {
16117
16017
  console.log(`📸 使用 ${outputFormat.toUpperCase()} 格式截图(直接输出,无需转换)...`);
16118
16018
  }
16119
- // 根据输出格式选择对应的 API
16120
- // modern-screenshot 内部已经处理了超时,不需要额外的 Promise.race
16121
- if (outputFormat === 'webp') {
16122
- // 使用 domToWebp,直接输出 WebP 格式,无需转换
16123
- dataUrl = await domToWebp(this.screenshotContext);
16124
- }
16125
- else if (outputFormat === 'jpeg') {
16126
- // 使用 domToJpeg,直接输出 JPEG 格式,无需转换
16127
- dataUrl = await domToJpeg(this.screenshotContext);
16128
- }
16129
- else {
16130
- // 默认使用 domToPng
16131
- dataUrl = await domToPng(this.screenshotContext);
16132
- }
16133
- // 验证截图结果
16134
- if (!dataUrl || dataUrl.length < 100) {
16135
- throw new Error('生成的截图数据无效或过短');
16019
+ // 尝试使用 Worker 模式(context)
16020
+ try {
16021
+ // 根据输出格式选择对应的 API
16022
+ // modern-screenshot 内部已经处理了超时,不需要额外的 Promise.race
16023
+ if (outputFormat === 'webp') {
16024
+ // 使用 domToWebp,直接输出 WebP 格式,无需转换
16025
+ dataUrl = await domToWebp(this.screenshotContext);
16026
+ }
16027
+ else if (outputFormat === 'jpeg') {
16028
+ // 使用 domToJpeg,直接输出 JPEG 格式,无需转换
16029
+ dataUrl = await domToJpeg(this.screenshotContext);
16030
+ }
16031
+ else {
16032
+ // 默认使用 domToPng
16033
+ dataUrl = await domToPng(this.screenshotContext);
16034
+ }
16035
+ // 验证截图结果
16036
+ if (!dataUrl || dataUrl.length < 100) {
16037
+ throw new Error('生成的截图数据无效或过短');
16038
+ }
16039
+ if (!this.options.silentMode) {
16040
+ console.log(`📸 ✅ modern-screenshot 截图成功(Worker 模式,${outputFormat.toUpperCase()} 格式)`);
16041
+ }
16042
+ return dataUrl;
16136
16043
  }
16137
- if (!this.options.silentMode) {
16138
- console.log(`📸 modern-screenshot 截图成功(${outputFormat.toUpperCase()} 格式,直接输出,无需转换)`);
16044
+ catch (workerError) {
16045
+ // Worker 模式失败,回退到普通模式(参考用户代码)
16046
+ if (!this.options.silentMode) {
16047
+ console.warn('📸 Worker 模式失败,回退到普通模式:', workerError);
16048
+ }
16049
+ // 销毁失败的 context
16050
+ if (this.screenshotContext) {
16051
+ try {
16052
+ destroyContext(this.screenshotContext);
16053
+ }
16054
+ catch {
16055
+ // 忽略销毁错误
16056
+ }
16057
+ this.screenshotContext = null;
16058
+ }
16059
+ // 回退到普通模式(直接使用 domToWebp,不传 context)
16060
+ // 使用外部传递的参数,并给出合理的默认值
16061
+ const fallbackOptions = {
16062
+ scale: this.options.scale ?? 1, // 使用外部参数,默认 1
16063
+ backgroundColor: '#ffffff', // 默认白色背景
16064
+ type: `image/${outputFormat}`, // 使用配置的输出格式
16065
+ quality: this.options.quality ?? 0.8, // 使用外部参数,默认 0.4
16066
+ drawImageInterval: 20, // 默认 20ms,减少主线程阻塞
16067
+ features: {
16068
+ copyScrollbar: false,
16069
+ removeAbnormalAttributes: true,
16070
+ removeControlCharacter: true,
16071
+ fixSvgXmlDecode: true,
16072
+ restoreScrollPosition: false,
16073
+ },
16074
+ timeout: Math.max((this.options.interval ?? 5000) * 6, 10000), // 使用外部参数计算超时,默认 10 秒
16075
+ };
16076
+ // 限制 timeout 最多 15 秒
16077
+ fallbackOptions.timeout = Math.min(fallbackOptions.timeout, 15000);
16078
+ if (outputFormat === 'webp') {
16079
+ dataUrl = await domToWebp(element, fallbackOptions);
16080
+ }
16081
+ else if (outputFormat === 'jpeg') {
16082
+ dataUrl = await domToJpeg(element, fallbackOptions);
16083
+ }
16084
+ else {
16085
+ dataUrl = await domToPng(element, fallbackOptions);
16086
+ }
16087
+ // 验证截图结果
16088
+ if (!dataUrl || dataUrl.length < 100) {
16089
+ throw new Error('生成的截图数据无效或过短');
16090
+ }
16091
+ if (!this.options.silentMode) {
16092
+ console.log(`📸 ✅ modern-screenshot 截图成功(普通模式,${outputFormat.toUpperCase()} 格式)`);
16093
+ }
16094
+ return dataUrl;
16139
16095
  }
16140
- return dataUrl;
16141
16096
  }
16142
16097
  catch (error) {
16143
16098
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -16249,94 +16204,6 @@ class ScreenshotManager {
16249
16204
  threshold: 0.01
16250
16205
  });
16251
16206
  }
16252
- /**
16253
- * 初始化 IndexedDB(持久化缓存)
16254
- */
16255
- async initIndexedDB() {
16256
- return new Promise((resolve, reject) => {
16257
- const request = indexedDB.open('screenshot-cache', 1);
16258
- request.onerror = () => reject(request.error);
16259
- request.onsuccess = () => {
16260
- this.indexedDBCache = request.result;
16261
- this.indexedDBReady = true;
16262
- // 初始化后立即清理过期和超大小的缓存
16263
- this.cleanIndexedDBCache().catch(() => {
16264
- // 清理失败不影响功能
16265
- });
16266
- resolve();
16267
- };
16268
- request.onupgradeneeded = (event) => {
16269
- const db = event.target.result;
16270
- if (!db.objectStoreNames.contains('images')) {
16271
- const store = db.createObjectStore('images', { keyPath: 'url' });
16272
- // 创建索引用于按时间排序
16273
- store.createIndex('timestamp', 'timestamp', { unique: false });
16274
- }
16275
- };
16276
- });
16277
- }
16278
- /**
16279
- * 从 IndexedDB 获取缓存
16280
- */
16281
- async getIndexedDBCache(url) {
16282
- if (!this.indexedDBReady || !this.indexedDBCache) {
16283
- return null;
16284
- }
16285
- try {
16286
- const transaction = this.indexedDBCache.transaction(['images'], 'readonly');
16287
- const store = transaction.objectStore('images');
16288
- const request = store.get(url);
16289
- return new Promise((resolve) => {
16290
- request.onsuccess = () => {
16291
- const result = request.result;
16292
- if (result) {
16293
- const now = Date.now();
16294
- const age = now - result.timestamp;
16295
- // 检查是否超过最大缓存时间
16296
- if (age > this.options.maxCacheAge) {
16297
- // 缓存过期,删除
16298
- this.deleteIndexedDBCache(url);
16299
- resolve(null);
16300
- return;
16301
- }
16302
- // 返回缓存数据(即使超过 imageCacheTTL,只要未超过 maxCacheAge 仍可使用)
16303
- resolve(result.dataUrl);
16304
- }
16305
- else {
16306
- resolve(null);
16307
- }
16308
- };
16309
- request.onerror = () => resolve(null);
16310
- });
16311
- }
16312
- catch {
16313
- return null;
16314
- }
16315
- }
16316
- /**
16317
- * 设置 IndexedDB 缓存(带大小和时间控制)
16318
- */
16319
- async setIndexedDBCache(url, dataUrl) {
16320
- if (!this.indexedDBReady || !this.indexedDBCache) {
16321
- return;
16322
- }
16323
- try {
16324
- // 计算当前缓存大小
16325
- const currentSize = await this.getIndexedDBCacheSize();
16326
- const newItemSize = this.estimateDataUrlSize(dataUrl);
16327
- const maxSizeBytes = (this.options.maxCacheSize || 50) * 1024 * 1024; // 转换为字节
16328
- // 如果添加新项后超过限制,清理最旧的数据
16329
- if (currentSize + newItemSize > maxSizeBytes) {
16330
- await this.cleanIndexedDBCacheBySize(maxSizeBytes - newItemSize);
16331
- }
16332
- const transaction = this.indexedDBCache.transaction(['images'], 'readwrite');
16333
- const store = transaction.objectStore('images');
16334
- store.put({ url, dataUrl, timestamp: Date.now() });
16335
- }
16336
- catch {
16337
- // IndexedDB 写入失败,忽略
16338
- }
16339
- }
16340
16207
  /**
16341
16208
  * 估算 data URL 的大小(字节)
16342
16209
  */
@@ -16347,156 +16214,32 @@ class ScreenshotManager {
16347
16214
  return Math.ceil(base64Data.length * 0.75) + 30;
16348
16215
  }
16349
16216
  /**
16350
- * 获取 IndexedDB 当前缓存大小(字节)
16217
+ * 获取 IndexedDB 当前缓存大小(已移除,不再使用)
16218
+ * @deprecated IndexedDB 已移除,不再使用
16351
16219
  */
16352
16220
  async getIndexedDBCacheSize() {
16353
- if (!this.indexedDBReady || !this.indexedDBCache) {
16354
- return 0;
16355
- }
16356
- try {
16357
- const transaction = this.indexedDBCache.transaction(['images'], 'readonly');
16358
- const store = transaction.objectStore('images');
16359
- const request = store.getAll();
16360
- return new Promise((resolve) => {
16361
- request.onsuccess = () => {
16362
- const items = request.result || [];
16363
- let totalSize = 0;
16364
- items.forEach((item) => {
16365
- totalSize += this.estimateDataUrlSize(item.dataUrl);
16366
- });
16367
- resolve(totalSize);
16368
- };
16369
- request.onerror = () => resolve(0);
16370
- });
16371
- }
16372
- catch {
16373
- return 0;
16374
- }
16221
+ return 0;
16375
16222
  }
16376
16223
  /**
16377
- * 清理 IndexedDB 缓存(按时间和大小)
16224
+ * 清理 IndexedDB 缓存(已移除,不再使用)
16225
+ * @deprecated IndexedDB 已移除,不再使用
16378
16226
  */
16379
16227
  async cleanIndexedDBCache() {
16380
- if (!this.indexedDBReady || !this.indexedDBCache) {
16381
- return;
16382
- }
16383
- try {
16384
- const transaction = this.indexedDBCache.transaction(['images'], 'readwrite');
16385
- const store = transaction.objectStore('images');
16386
- const index = store.index('timestamp');
16387
- const request = index.getAll();
16388
- return new Promise((resolve) => {
16389
- request.onsuccess = () => {
16390
- const items = request.result || [];
16391
- const now = Date.now();
16392
- const expiredUrls = [];
16393
- let currentSize = 0;
16394
- const maxSizeBytes = (this.options.maxCacheSize || 50) * 1024 * 1024;
16395
- // 按时间排序(最旧的在前)
16396
- items.sort((a, b) => a.timestamp - b.timestamp);
16397
- // 清理过期数据
16398
- items.forEach((item) => {
16399
- const age = now - item.timestamp;
16400
- if (age > this.options.maxCacheAge) {
16401
- expiredUrls.push(item.url);
16402
- }
16403
- else {
16404
- currentSize += this.estimateDataUrlSize(item.dataUrl);
16405
- }
16406
- });
16407
- // 如果仍然超过大小限制,删除最旧的数据
16408
- const urlsToDelete = [...expiredUrls];
16409
- if (currentSize > maxSizeBytes) {
16410
- for (const item of items) {
16411
- if (expiredUrls.includes(item.url))
16412
- continue;
16413
- currentSize -= this.estimateDataUrlSize(item.dataUrl);
16414
- urlsToDelete.push(item.url);
16415
- if (currentSize <= maxSizeBytes) {
16416
- break;
16417
- }
16418
- }
16419
- }
16420
- // 删除过期和超大小的数据
16421
- urlsToDelete.forEach((url) => {
16422
- store.delete(url);
16423
- });
16424
- if (urlsToDelete.length > 0 && !this.options.silentMode) {
16425
- console.log(`📸 IndexedDB 清理了 ${urlsToDelete.length} 个缓存项(过期或超大小)`);
16426
- }
16427
- resolve();
16428
- };
16429
- request.onerror = () => resolve();
16430
- });
16431
- }
16432
- catch {
16433
- // 清理失败,忽略
16434
- }
16228
+ // IndexedDB 已移除,不再使用
16435
16229
  }
16436
16230
  /**
16437
- * 按大小清理 IndexedDB 缓存
16231
+ * 按大小清理 IndexedDB 缓存(已移除,不再使用)
16232
+ * @deprecated IndexedDB 已移除,不再使用
16438
16233
  */
16439
- async cleanIndexedDBCacheBySize(targetSize) {
16440
- if (!this.indexedDBReady || !this.indexedDBCache) {
16441
- return;
16442
- }
16443
- try {
16444
- const transaction = this.indexedDBCache.transaction(['images'], 'readwrite');
16445
- const store = transaction.objectStore('images');
16446
- const index = store.index('timestamp');
16447
- const request = index.getAll();
16448
- return new Promise((resolve) => {
16449
- request.onsuccess = () => {
16450
- const items = request.result || [];
16451
- // 按时间排序(最旧的在前)
16452
- items.sort((a, b) => a.timestamp - b.timestamp);
16453
- let currentSize = 0;
16454
- const urlsToDelete = [];
16455
- // 计算当前大小
16456
- items.forEach((item) => {
16457
- currentSize += this.estimateDataUrlSize(item.dataUrl);
16458
- });
16459
- // 如果超过目标大小,删除最旧的数据
16460
- if (currentSize > targetSize) {
16461
- for (const item of items) {
16462
- if (currentSize <= targetSize) {
16463
- break;
16464
- }
16465
- currentSize -= this.estimateDataUrlSize(item.dataUrl);
16466
- urlsToDelete.push(item.url);
16467
- }
16468
- }
16469
- // 删除数据
16470
- urlsToDelete.forEach((url) => {
16471
- store.delete(url);
16472
- });
16473
- if (urlsToDelete.length > 0 && !this.options.silentMode) {
16474
- console.log(`📸 IndexedDB 清理了 ${urlsToDelete.length} 个缓存项(超过大小限制)`);
16475
- }
16476
- resolve();
16477
- };
16478
- request.onerror = () => resolve();
16479
- });
16480
- }
16481
- catch {
16482
- // 清理失败,忽略
16483
- }
16234
+ async cleanIndexedDBCacheBySize(_targetSize) {
16235
+ // IndexedDB 已移除,不再使用
16484
16236
  }
16485
16237
  /**
16486
- * 删除 IndexedDB 缓存
16238
+ * 删除 IndexedDB 缓存(已移除,不再使用)
16239
+ * @deprecated IndexedDB 已移除,不再使用
16487
16240
  */
16488
- async deleteIndexedDBCache(url) {
16489
- if (!this.indexedDBReady || !this.indexedDBCache) {
16490
- return;
16491
- }
16492
- try {
16493
- const transaction = this.indexedDBCache.transaction(['images'], 'readwrite');
16494
- const store = transaction.objectStore('images');
16495
- store.delete(url);
16496
- }
16497
- catch {
16498
- // 忽略错误
16499
- }
16241
+ async deleteIndexedDBCache(_url) {
16242
+ // IndexedDB 已移除,不再使用
16500
16243
  }
16501
16244
  /**
16502
16245
  * 检查元素是否在可视区域内(优化:使用 Intersection Observer 或 getBoundingClientRect)
@@ -16711,10 +16454,6 @@ class ScreenshotManager {
16711
16454
  const dataUrl = await this.blobToDataUrl(blob);
16712
16455
  // 缓存结果(带时间戳,10分钟有效)
16713
16456
  this.setCachedImage(url, dataUrl);
16714
- // 如果启用 IndexedDB,也保存到 IndexedDB
16715
- if (this.options.useIndexedDB) {
16716
- await this.setIndexedDBCache(url, dataUrl);
16717
- }
16718
16457
  return dataUrl;
16719
16458
  }
16720
16459
  // 如果下载失败,返回原 URL,让 modern-screenshot 自己处理
@@ -17744,12 +17483,7 @@ class ScreenshotManager {
17744
17483
  this.intersectionObserver = null;
17745
17484
  this.visibleElementsCache.clear();
17746
17485
  }
17747
- // 关闭 IndexedDB
17748
- if (this.indexedDBCache) {
17749
- this.indexedDBCache.close();
17750
- this.indexedDBCache = null;
17751
- this.indexedDBReady = false;
17752
- }
17486
+ // IndexedDB 已移除,不再使用
17753
17487
  // 清理图片代理缓存
17754
17488
  this.imageProxyCache.clear();
17755
17489
  // 清理截图历史记录(释放大量内存)
@@ -17838,12 +17572,6 @@ class ScreenshotManager {
17838
17572
  // 每2分钟清理一次过期缓存(从5分钟改为2分钟,更频繁)
17839
17573
  setInterval(() => {
17840
17574
  this.cleanExpiredCache();
17841
- // 如果启用 IndexedDB,也清理 IndexedDB 缓存
17842
- if (this.options.useIndexedDB) {
17843
- this.cleanIndexedDBCache().catch(() => {
17844
- // 清理失败,忽略
17845
- });
17846
- }
17847
17575
  if (!this.options.silentMode) {
17848
17576
  const memoryCacheSize = this.imageProxyCache.size;
17849
17577
  const memoryCacheSizeMB = Array.from(this.imageProxyCache.values())