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