Reputation: 4541
Hello guys,
I want to be able to access informations stored in chrome.storage.sync from an inline script within a web page, injected by my extension.
When trying to use chrome.storage.sync, sync can't be called from "undefined". In the same way, I couldn't call chrome.runtime.sendMessage. This answer taught me I can't access Chrome APIs from an injected script.
I found out that I could eventually call sendMessage using this technique : https://developer.chrome.com/extensions/messaging#external-webpage and then I could return the wanted data in the callback.
But I wanted to know, is there a better way to do this ? Accessing chrome.storage data from the injected script ? The fact that I need to use my extension's as an argument is really not great...
Thanks !
Upvotes: 1
Views: 2500
Reputation: 77571
Since your injected script is essentially the same as the page's own code from a security perspective, there's no way to make this task easy.
externally_connectable
that you found is one of the ways to do it.
The other way is to talk with the content script itself. You can do so with custom events or window.postMessage
.
Upvotes: 3