javascript - window.localStorage vs chrome.storage.local -



javascript - window.localStorage vs chrome.storage.local -

i'm developing chrome extension , need store info , in point. did investigation on available storages , came across next ones: window.localstorage , chrome.storage.local.

so question best selection me utilize within chrome extension?

window.localstorage or chrome.storage.local?

note: know, latter 1 works asynchronously (which not preferred me).

p.s. i'm using browser action load local html in iframe. i'm not using popup.js.

it depends exclusively on chrome extension doing. window.localstorage html5 storage. unless you're running in background page, can allow , set info storage specific domain. true code injected dom, since utilize localstorage on web page.

in other words, won't able share info across different web pages unless utilize localstorage in background page, operates independently of web pages, since has chrome:// uri domain.

chrome.storage.local, on other hand, designed chrome extensions , chrome apps store info in more central location. since isn't accessible normal web pages, each extension gets own storage. 1 possibility background page handle dealing setting , getting of data, while content scripts deal modifying , interacting web page.

however, these api's work in content scripts well, , both of extensions i've written utilize chrome.storage.local called content scripts.

as example, built stack app preserves inbox items in stack exchange until you've read them, called stackinbox. since stack exchange sites span across hundreds of domains, chose chrome.storage.local because save user's accountid , reuse across sites, ensuring inbox info synchronized, while using straight in content script.

as simple test, set info in localstorage on 1 domain, in content script, , seek pull another, , you'll see info won't there. chrome.storage.local, isn't problem.

lastly, chrome extensions , chrome apps whitelisted, since user chose install it, typically can more things normal website. instance, specifying "unlimitedstorage" permission in manifest, can store info beyond 5mb limit placed upon html5 localstorage.

for more information, see google's documentation on chrome storage.

javascript google-chrome-extension local-storage google-chrome-storage

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -