Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website and extension using same model #182

Open
escottgoodwin opened this issue Jul 6, 2023 · 5 comments
Open

Website and extension using same model #182

escottgoodwin opened this issue Jul 6, 2023 · 5 comments
Labels
question Further information is requested

Comments

@escottgoodwin
Copy link

Per the chrome extension example, you pack the model with the extension. Is there a way for a website and chrome extension to use the same cached model? If my project has both a website and extension, I hope they could use a single model instead of having store 2 on the user's machine.

@escottgoodwin escottgoodwin added the question Further information is requested label Jul 6, 2023
@xenova
Copy link
Collaborator

xenova commented Jul 9, 2023

Could you maybe explain a little more about your intended use-case (and why you need the model to run on both a website and a chrome extension)? If there's a way to access the cache of a specific website from your chrome extension (assuming permissions are set correctly), there might be a sneaky way to fix your problem. Basically, you would only load (and cache) the model under your website domain, and then access this cached model from the chrome extension. However, I don't think you'll be able to do this if you aren't actively visiting the page (but feel free to try yourself).

Usually, the answer to "shared models" across domains/extensions is that it isn't possible due security protocols put in place by browsers to restrict cross-domain sharing of cached resources. Allowing one website to read the cache of another can most certainly be abused, so, this is a hard limitation for sharing cached models across websites.

@xenova
Copy link
Collaborator

xenova commented Jul 16, 2023

I've been working on a small proof-of-concept extension where the model is downloaded separately: https://github.com/xenova/transformers.js/tree/extension/examples/extension

Let me know if that solves your problem!

@escottgoodwin
Copy link
Author

escottgoodwin commented Jul 16, 2023 via email

@xenova
Copy link
Collaborator

xenova commented Jul 16, 2023

Isn't local storage reserved by domain and/or extension.

The naming is a bit confusing (since the localStorage property is - as you said - reserved by domain), but the extensions API calls this the Storage API which is divided into four buckets ("storage areas"), one of which is storage.local. So my proof-of-concept is able to use the same model across different domains (or even across extensions; see here).

But you can use the same model to process text while browsing the web and save the results to your logged in account.

In this case, you could look into the externally_connectable option (https://developer.chrome.com/docs/extensions/mv3/messaging/#external-webpage), which allows you to receive and respond to messages from your website. For more info, see this twitter thread.

It seems a this would require two copies of the same model being cached on the user's computer.

Combining my proof-of-concept with externally_connectable should mean you only need one copy (which is stored/managed by the extension).

@escottgoodwin
Copy link
Author

escottgoodwin commented Jul 16, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants