Chrome extension - write to local storage of another domain

How can I write the local memory of another domain. The idea is that I need a chrome extension to write something to the local store, and when a user visits the corresponding site, the site site can read the contents of the local store. I am trying to synchronize between user personal data without storing it on the server.

+5
source share
2 answers

Content scripts have direct access to the localStorage page.

If you want to save the value for a specific domain, simply open a window or frame, and then write to the local storage of the window / page.

. API tabs, chrome.tabs.executeScript. , , , .

chrome.tabs.create({
    active: false,
    url: 'http://stackoveflow.com/robots.txt'
}, function(tab) {
    chrome.tabs.executeScript(tab.id, {
        code: 'localStorage.setItem("key", "value");'
    }, function() {
        chrome.tabs.remove(tab.id);
    });
});
+6

, script - .

var s = document.createElement('script');
s.src = chrome.extension.getURL("script.js");
s.onload = function() {
    this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);

script.js , localStorage, script.js "web_accessible_resources" .

, script script, , , , .

+2

All Articles