我正在使用“chrome.storage.sync.get/set
”来保存我的数据。我的问题是,当我关闭 Chrome 浏览器窗口并再次打开它时,使用此 API 保存的数据是否会被重置。有没有办法清除chrome退出时保存的数据?我知道有一个方法“chrome.storage.sync.clear()
”。但只有当用户退出 chrome 时才会发生这种情况。
最佳答案
will the data saved using this API will get reset when I close chrome browser window and open it again
不,它不仅会保存在本地,还可能会同步到用户的 Google 帐户。这就是sync
存储区域的要点。 The documentation说 sync
类似于 localStorage
,但同步到用户的帐户。
如果您将其用于临时数据,请不要使用它。请改用 local
(因为似乎没有与 session 存储等效的扩展),或者可能只是将数据存储在扩展的运行时环境中(尚不清楚您使用它的目的)。
I know there is a method
chrome.storage.sync.clear()
. But this should happen only when the user exits from chrome.
您必须从事件中触发clear
。不幸的是,目前还没有一种官方方式可以让扩展程序在 Chrome 关闭时收到通知 ( there's an open issue on it )。希望有一天会有办法,但目前还没有。
关于javascript - Chrome.storage.sync - 会保留他们的数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26250840/