关闭弹出扩展后如何将数据保留在内存中

发布于 2025-01-19 13:36:06 字数 1146 浏览 4 评论 0原文

我正在构建一个Chrome扩展名,并且在用户打开浏览器时,我想在内存中存储一​​些敏感数据(不是磁盘)。即使用户关闭扩展名弹出窗口并重新打开弹出窗口,数据也应持续存在。 我该怎么做?

我相信这是可能的,因为在打开浏览器后首次打开其扩展程序时,MetAmask和Bitwarden都会要求您提供密码。然后,无论您关闭其扩展名并重新打开多少次,数据仍然存在,但是我怀疑它们是否将解密的数据保存到磁盘上,因此必须将其保存在内存中。我想做同样的事情,但是每当我尝试将任何内容保存在弹出窗口中。

{
  "manifest_version": 3,
  "name": "TEST",
  "version": "1.0.0",
  "permissions": [
    "storage",
    "activeTab",
    "cookies",
    "tabs"
  ],
  "action": {
    "default_popup": "popup.html",
    "default_title": "TEST",
    "default_icon": {
      "16": "./assets/images/icon16.png",
      "19": "./assets/images/icon19.png",
      "32": "./assets/images/icon32.png",
      "38": "./assets/images/icon38.png",
      "48": "./assets/images/icon48.png",
      "128": "./assets/images/icon128.png"
    }
  },
  "icons": {
    "16": "./assets/images/icon16.png",
    "19": "./assets/images/icon19.png",
    "32": "./assets/images/icon32.png",
    "38": "./assets/images/icon38.png",
    "48": "./assets/images/icon48.png",
    "128": "./assets/images/icon128.png"
  },
  "background": {
    "service_worker": "service-worker-loader.js",
    "type": "module"
  }

I'm building a chrome extension, and I'd like to have some sensitive data stored in memory (not disk) while the user has their browser open. The data should persist in the chrome extension even if the user closes the extension popup and re-opens the popup.
How can I do this?

I believe this is possible because both Metamask and Bitwarden ask you for your password when you first open their extension after opening the browser. Then no matter how many times you close their extension and re-open it, the data persists, but I doubt that they are saving decrypted data to disk, so it must be kept in memory. I'd like to do the same, but whenever I try to save anything in the popup.html's JS file to memory, it never persists after closing the popup.

{
  "manifest_version": 3,
  "name": "TEST",
  "version": "1.0.0",
  "permissions": [
    "storage",
    "activeTab",
    "cookies",
    "tabs"
  ],
  "action": {
    "default_popup": "popup.html",
    "default_title": "TEST",
    "default_icon": {
      "16": "./assets/images/icon16.png",
      "19": "./assets/images/icon19.png",
      "32": "./assets/images/icon32.png",
      "38": "./assets/images/icon38.png",
      "48": "./assets/images/icon48.png",
      "128": "./assets/images/icon128.png"
    }
  },
  "icons": {
    "16": "./assets/images/icon16.png",
    "19": "./assets/images/icon19.png",
    "32": "./assets/images/icon32.png",
    "38": "./assets/images/icon38.png",
    "48": "./assets/images/icon48.png",
    "128": "./assets/images/icon128.png"
  },
  "background": {
    "service_worker": "service-worker-loader.js",
    "type": "module"
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文