如何让我的记事本 chrome 扩展在关闭时不会丢失用户的笔记?

How to make my notepad chrome extension not lose the user's note when they close it?

我正在制作记事本,我希望 chrome 扩展程序在用户关闭文本区域时保留用户键入的内容...我该怎么做?我试了很多次都失败了

您可以使用 chrome.storage.localchrome.storage.sync 来存储扩展数据。

请注意,您需要将其添加到 permissions 部分内的扩展清单:

  "permissions": [
    "storage"
  ],

它是异步的 API - 您可以像这样将它与回调一起使用:

chrome.storage.sync.set({key: value}, function() {
  console.log('Value is set to ' + value);
});

chrome.storage.sync.get(['key'], function(result) {
  console.log('Value currently is ' + result.key);
});

我还建议查看官方文档:https://developer.chrome.com/docs/extensions/reference/storage/