Question

I am trying to call sessionStorage in my addon (here is the demo https://builder.addons.mozilla.org/package/154290/latest/), but nothing gets stored. Any tips?

 var menuItem = contextMenu.Item({
    label: "Check with Proofread Bot",
    context: contextMenu.SelectionContext(),
    contentScript: 'self.on("click", function () {' +
               '  var text = window.getSelection().toString();' +
                '  sessionStorage.setItem("proofread_bot_chrome", text);' +
                '  self.postMessage(text);' +
                        '});',
    onMessage: function(text) {
        tabs.open("http://proofreadbot.com");                    }                        
    }) ;
Était-ce utile?

La solution

sessionStorage and localStorage are never shared across different domains. That also applies to content scripts injected into pages from different domains, content scripts run with the privileges of these pages and only have access to the same sessionStorage as the pages themselves. You need to use proper messaging as explained in the answer to your other question.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top