-
Notifications
You must be signed in to change notification settings - Fork 1
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
Accessing storage from content_scripts directly (plain JS) #2
Comments
According to Chrome's content scripts docs, content scripts are allowed to access the How is your extension declaring its content scripts? What do you mean when you say, "nothing seems to work?" |
I'm building an extension that allows you to create profiles (each has a name, surname and some other data) this profile manager is written in React and Redux. I used your package in order to save data to I then created a content script called "content_scripts": [
{
"matches": [
"https://*/*", "http://*/*"
],
"exclude_matches": [
"https://www.google.com/*",
],
"js": [
"js/content_scripts/inject.js"
],
"all_frames": true
}
] Now inside of this script I would like to fetch these profiles using plain JavaScript, but I can't figure out where the data is saved or how to access it. I tried dumping chrome.storage.local.get(['profiles'], function(result) {
console.log('Value currently is ' + result.profiles);
}); |
I am having the same issue with figuring out where the data is saved, similar as duplxey described... |
After quite a while I figured out a "hacky" way how to access it thanks to By debugging a bit I figured out that chrome.storage.local.get(['persist:localStorage'], function(items) {
const parsed = JSON.parse(items['persist:localStorage']);
// Keep in mind that you need to parse each reducer separately like this:
const someReducer = JSON.parse(parsed.someReducer);
console.log("someKey: " + someReducer.someKey);
}); This is far from the most optimal/perfect solution, but hey at least it works! |
Thanks for writing that up, @duplxey. I will add a section to the README about accessing the stored values from the |
Add description from #2 about so future readers can find this info quickly.
I added a section called Accessing local/sync storage directly to the README for any future clients of the lib who are also interested. Thanks for the question and for the write up. |
The storage engine itself works great when using it with Redux. But how do I access it directly in content scripts using plain JavaScript? I've tried accessing it through
chrome.storage.local
,localStorage
,storage
, but nothing seems to work?The text was updated successfully, but these errors were encountered: