Differences between Chrome.storage and localStorage in HTML5

Differences between Chrome.storage and localStorage in HTML5





Chrome provides a storage API for extension applications to write data that the extension needs to save to local disk. The storage API provided by Chrome can be said to be an improvement to localStorage. Compared with localStorage, it has the following differences:

If the storage area is specified as sync, the data can be automatically synchronized;

Content_scripts can directly read the data without going through the background page

; Previously stored data can still be read out in stealth mode;

· Faster read and write speeds;

· User data can be saved as objects.

The second point needs to be further explained. First of all localStorage is based on the domain name, which has been mentioned in the previous section. The content_scripts is injected into the user's current browsing page. If content_scripts directly reads localStorage, the read data is in the domain where the user is currently browsing the page. So the usual solution is that content_scripts communicate with the background through runtime.sendMessage, and the background reads and writes the localStorage of the extension domain (usually chrome-extension://extension-id/), and then passes it to content_scripts.




















http://blog.csdn.net/talking12391239/article/details/41114693

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326713870&siteId=291194637