You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用indexedDB遇写入延迟问题:安装扩展后卡顿求助

IndexedDB安装其他扩展后出现严重写入延迟问题

在使用IndexedDB时遇到异常:每当安装其他扩展程序后,IndexedDB有时会出现严重的数据写入延迟。尝试过直接使用IndexedDB API以及基于IndexedDB的库,均无法解决该问题。

以下是使用的代码:

function updateRecord({
  sessionId,
  ...record
}) {
  return new Promise(async(resolve, reject) => {
    try {
      console.log(
        '%c Inside update record ',
        'background: #222; color: #bada55'
      );
      const dbPromise = await idb.openDB('testbuddyExtension', 1, {
        upgrade(db) {
          const store = db.createObjectStore('testbuddy', {
            keyPath: 'sessionId',
          });
          store.createIndex('keyIndex', 'tabId');
        },
      });

      const existingRecord = await dbPromise.get('testbuddy', sessionId);

      const updatedPayload = {
        ...record,
        ...(existingRecord ? existingRecord : {}),
      };

      await dbPromise.put('testbuddy', { ...updatedPayload,
        sessionId
      });
      console.log(
        '%c Everything is now done! ',
        'background: #222; color: #bada55'
      );
      resolve(true);
    } catch (error) {
      console.log('%c Error found! ', 'background: #222; color: #bada55');
      console.log({
        error
      });
      reject(false);
    }
  });
}

需要说明的是,该延迟并非因一次性写入大量数据导致,我曾用同一脚本一次性写入过数兆字节的数据,未出现此类问题。

内容的提问来源于stack exchange,提问作者Joy Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 23:22:41