Reputation: 193
I'm developing an extension for google chrome, where I hear the commands CTRL + SHIFT + 1 and CTRL + SHIFT + 2 and I store the text of the mouse selection. When the user hits CTRL + SHIFT + 3 or CTRL + SHIFT + 4 I would like to check if the element is editable, input or textarea and insert the text stored in a Storage Location.
The problem is that I can only access the window elements through my background.js where I create the LocalStorage with texts, but I can not access this data through my content_script.js.
I think the most correct way to solve it is every time the user presses CTRL + SHIFT + 1 and CTRL + SHIFT + 2, the background.js send a message to the content_script.js with the data necessary to store the LocalStorage in content_script.js.
How can I do this with the api Google Chrome Extension? I found nothing to help me yet ...
Upvotes: 0
Views: 46
Reputation: 77571
If your problem is sharing storage with your content script, you should look into chrome.storage
API. It's a storage area that is accessible both to your background and content scripts.
The transition from localStorage
is not painless though, since the API is asynchronous.
As for messaging, well, use Messaging. The API to send a message to content scripts is chrome.tabs.sendMessage
. Your question it too vague for more detailed advice.
Upvotes: 1