Using an SQL Db is not similar to using the 50MB localStorage per file
(which is way easier to use) but it does provide you with much more
storage. Even unlimited storage, as long as you use the permission
'unlimited_storage' in your manifest file. Notice that official Google
extensions API suggests the keyword unlimitedStorage, but this does
not work for some reason.
> What do you mean with, inside content script?
>
At a high-level, an extension can have three separate units: code that
runs in the background (like in background.html), a popup that
activates when your extension's icon on the browser is clicked, and a
content script that has access to the page DOM. Each of these units
can communicate with each other using the messaging API (see official
developer's guide at
http://code.google.com/chrome/extensions/devguide.html). The popup
does not have access to any other page but itself, the content script
only has access to those pages that it takes permissions for in the
manifest file, and the background code has access to the extension but
not any other pages e.g. in a browser tab (this is what the content
script is for).
The only unit of your extension that can access local storage (or
database) is the background code, so if other units of your extension
e.g. popup, or a content script that activates when some URL is
visited, wants to store some data, they need to send a message with
that data to the background page.
> Basically what I'm trying to do is save/load from localStorage from
> the popup page (on load and on unload).
> Could it work by accessing from the popup to the background and save/
> load into the background one?
>
Yes, that's how it will work. Send a message from popup to background.
> (so I could just change the code to add: 'var bg =
> chrome.extension.getBackgroundPage()' , and then do as I'm doing
> already?)
>
>
Nope. You need to use the messaging API.
http://code.google.com/chrome/extensions/messaging.html
--Daku
>
> On Sep 7, 5:22 pm, Dan Silivestru <dan.silives...@gmail.com> wrote:
>> Hi Pedro,
>>
>> In the file:/// scheme in Chrome, localStorage is per file. so if you
>> got to file:///foo.html and save something, it won't be available in
>> file:///bar.html.
>>
>> You can consider using SQLite storage, that database is the same for
>> the entire file:/// scheme.
>>
>> the background page local storage is also a good option, but keep in
>> mind that you don't have access to save to the background page's local
>> storage from inside a content script.
>>
>> Hope this helps,
>>
>> Dan.
>>
>> On Sep 6, 5:32 pm, Pedro Ferreira <darkiii...@gmail.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>> > Hi, I'm currently working on a extension for chrome, and until now
>> > I've been working on it as a local file(and opening with chrome).
>>
>> > I'm trying now as an extension, I've loaded it and it opens fine, the
>> > extension saves data to localStorage, but when I reopen the extension
>> > everything is gone, nothing is saved, but it works fine when I open it
>> > as a file.
>>
>> > I've been reading a bit and it seems I have to have a background.html
>> > page, where I'm guessing here is where localStorage is allowed?
>>
>> > Could someone point me to, or explain how to make this working.
>> > thanks
>
> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.
> For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
>
That should work.
Also, everyone, in the case of local storage, there is no need to get
the background page's local storage. getBackgroundPage().localStorage
is equivalent to just localStorage because localStorage is
per-extension.
- a
-- Akshay
http://web.cecs.pdx.edu/~akshay/