I'm trying to accessing localStorage in content scripts, so I use Message Passing (manifest v2). But I'm not so clear about one thing : where & when should chrome.extension.onMessage
(which is in my options.js) and chrome.extension.sendMessage
(in contentscript.js) be invoked?
For me I use jQuery and I wrap both them in the $(document).ready(function() { //... }
. But the extension will only run without exceptions when the options page and the injected page are opened at the same time, else it would give a exception like
*Port error: Could not establish connection. Receiving end does not exist.*
I searched Stack Overflow for a while and find that some people use background_page, but I think I just need a options page, not a background page. Is the background html/js really necessary that options page should use them together?