--- title: storage slug: Mozilla/Add-ons/WebExtensions/API/storage tags: - Add-ons - Extensions - Strorage translation_of: Mozilla/Add-ons/WebExtensions/API/storage ---
此存储系统API基于 Web Storage API, 并有少许不同。
为了使用该API,您需要在manifest.json文件包含"storage"权限。每一个浏览器扩展有自己的储存区域,每一个储存区域又分为几种不同的存储类型。
虽然此API类似于{{domxref("Window.localStorage")}},但仍建议您不要在插件中使用Window.localStorage。当用户由于隐私原因清除历史浏览记录及数据时,火狐会将在浏览器扩展使用
localStorage API存储的数据一并清除。而使用 storage.localAPI存储的数据将会恰当保留。
storage有3个属性,每一个代表不同的存储区域。
{{Compat("webextensions.api.storage")}}
"Chrome不兼容"这部分来源于 https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities 使用WebExtChromeCompat macro.
如果需要更新这部分,请编辑 https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities, 然后刷新页面即可看见所做更改。
Promises在Edge中不被支持,使用callbacks代替。
{{WebExtExamples("h2")}}
这个API基于Chromium的 chrome.storage
API. 这篇文档也来源于Chromium 代码中的 storage.json
.
Microsoft Edge的适配数据由Microsoft Corporation提供并且被包含在Creative Commons Attribution 3.0 United States License许可证下.
// Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.