I'm looking to send data from a website to the LocalStorage of a chrome extension.
I've tried the below answer which is what I'm looking for, however it appears to not be functioning at all on Chrome 29 stable. Could anyone advise as to why this may be/tweaks?
It's not possible to manage extension's localstorage from a website because of security rules.
But there is a method that allows you to send message from a website to an extension.
Consequently, you may send your data to extension with this method and get this data on extension's background page then do whatever you want with it (saving to exension's localstorage).
It's really well explained in DOCs,
manifest.json
, you will let your website to allow sending message."externally_connectable": {
"matches": ["*://*.example.com/*"]
}
chrome.runtime.sendMessage
will be available on your website. (javascript)chrome.runtime.sendMessage("your extension id will be here",
{data: { anyDataKey : "example"}});
background.js
create a message listener for external messages.chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (request.data)
alert("Hi, there is message from the website");
var data = request.data;
// now the data is on your extension side, just save it to extension's localstorage.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With