OLD | NEW |
1 <h2 id="overview">Overview</h2> | 1 <h2 id="overview">Overview</h2> |
2 | 2 |
3 <p> | 3 <p> |
4 This API has been optimized | 4 This API has been optimized |
5 to meet the specific storage needs of extensions. | 5 to meet the specific storage needs of extensions. |
6 It provides the same storage capabilities as the | 6 It provides the same storage capabilities as the |
7 <a href="https://developer.mozilla.org/en/DOM/Storage#localStorage">localStorage
API</a> | 7 <a href="https://developer.mozilla.org/en/DOM/Storage#localStorage">localStorage
API</a> |
8 with the following key differences: | 8 with the following key differences: |
9 </p> | 9 </p> |
10 | 10 |
11 <ul> | 11 <ul> |
12 <li>User data can be automatically synced with Chrome sync | 12 <li>User data can be automatically synced with Chrome sync |
13 (using <code>storage.sync</code>).</li> | 13 (using <code>storage.sync</code>).</li> |
14 <li>Your {{platform}}'s content scripts can directly access user data | 14 <li>Your {{platform}}'s content scripts can directly access user data |
15 without the need for a background page.</li> | 15 without the need for a background page.</li> |
16 <li>A user's extension settings can be persisted | 16 <li>A user's extension settings can be persisted |
17 even when using | 17 even when using |
18 <a href="manifest/incognito.html">split incognito behavior</a>.</li> | 18 <a href="manifest/incognito">split incognito behavior</a>.</li> |
19 <li>It's asynchronous with bulk read and write operations, and therefore | 19 <li>It's asynchronous with bulk read and write operations, and therefore |
20 faster than the blocking and serial <code>localStorage API</code>. | 20 faster than the blocking and serial <code>localStorage API</code>. |
21 <li>User data can be stored as objects | 21 <li>User data can be stored as objects |
22 (the <code>localStorage API</code> stores data in strings).</li> | 22 (the <code>localStorage API</code> stores data in strings).</li> |
23 <li>Enterprise policies configured by the administrator for the extension | 23 <li>Enterprise policies configured by the administrator for the extension |
24 can be read (using <code>storage.managed</code> with a | 24 can be read (using <code>storage.managed</code> with a |
25 <a href="manifest/storage.html">schema</a>).</li> | 25 <a href="manifest/storage">schema</a>).</li> |
26 </ul> | 26 </ul> |
27 | 27 |
28 <h2 id="manifest">Manifest</h2> | 28 <h2 id="manifest">Manifest</h2> |
29 <p>You must declare the "storage" permission in the <a | 29 <p>You must declare the "storage" permission in the <a |
30 href="manifest.html">extension manifest</a> | 30 href="manifest">extension manifest</a> |
31 to use the storage API. | 31 to use the storage API. |
32 For example:</p> | 32 For example:</p> |
33 <pre data-filename="manifest.json"> | 33 <pre data-filename="manifest.json"> |
34 { | 34 { |
35 "name": "My extension", | 35 "name": "My extension", |
36 ... | 36 ... |
37 <b>"permissions": [ | 37 <b>"permissions": [ |
38 "storage" | 38 "storage" |
39 ]</b>, | 39 ]</b>, |
40 ... | 40 ... |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 var storageChange = changes[key]; | 137 var storageChange = changes[key]; |
138 console.log('Storage key "%s" in namespace "%s" changed. ' + | 138 console.log('Storage key "%s" in namespace "%s" changed. ' + |
139 'Old value was "%s", new value is "%s".', | 139 'Old value was "%s", new value is "%s".', |
140 key, | 140 key, |
141 namespace, | 141 namespace, |
142 storageChange.oldValue, | 142 storageChange.oldValue, |
143 storageChange.newValue); | 143 storageChange.newValue); |
144 } | 144 } |
145 }); | 145 }); |
146 </pre> | 146 </pre> |
OLD | NEW |