Dave Gordon
Dave Gordon

Reputation: 1835

What is the Scope of IndexedDb

I am writing a Browser Add-On designed to automatically remove known child sexual abuse images from the internet. Currently I am using LocalStorage to hold a list of image sources (src urls) the problem is this:

A user discovers a CSA image on http://Server1.com - right clicks on it and reports it. The src url (http://server3.com/image.jpg) is saved to the LocalStorage when the user goes to http://server2.com a new LocalStorage for that domain is used. So even if http://server2.com has the same image whose source is http://server3.com/image.jpg the extension won't know that it has already been reported. Or at least that is how it appears to work.

So to the question: Does IndexedDB share information across domains? and Do I understand the Scope of LocalStorage correctly?

Upvotes: 3

Views: 1338

Answers (1)

Eloims
Eloims

Reputation: 5224

You are using LocalStorage on a content script. Content-scripts execute in the context of the page you have injected it on. That's why you end up having separated LocalStorage instances for each domain.

The issue would be the same with IndexedDB.

If you want to share storage across all domains, you need to use LocalStorage/IndexedDB from your extension's background page, and then use Chrome's messaging API for access from the content scripts.

If you want to scale beyond thousands of urls, you will probably need to switch from LocalStorage to IndexedDB, which is more performant and has the search capabilities that you'll be needing.

Here is the messaging documentation: https://developer.chrome.com/extensions/messaging

Upvotes: 4

Related Questions