如何在带有清单版本2的Chrome扩展程序中使用选项的localStorage?

时间:2012-09-07 14:45:08

标签: javascript google-chrome-extension manifest

  

可能重复:
  Port error while changing chrome extension from manifest v1 to v2

想要制作我的第一个Chrome扩展程序,但当我开始考虑使用option页面的localStoragewww.example.com/example.html的{​​{1}时,我遇到了腌菜}}。我已经四处查看如何在Message Passing上将此页面在两者之间来回传递,但似乎我需要设置eventListener,并在localStorage中使用SendRequest {1}}中不允许使用{1}}:

background.html

修改:您需要对manifest : 2 as seen here进行更改,才能使用`bac

Message Passing页面讨论了如何创建端口,但不清楚将侦听器放在何处。如果我将前半部分放入There were warnings when trying to install this extension: 'background_page' requires manifest version of 1 or lower. 脚本,然后将另一半放入manifest,则监听器仅在content.js打开时才会激活。

所以我的问题是:如何传递我在options.js中选择的设置,以便在我操作当前网页的options.html中使用?


这是我的整个设置:

background.html

options.html

background.js

contentscript.js

contentscript.js

 <!doctype html>
<html>
  <head>
    <title>Background Page</title>
    <script src="jquery.min.js"/>
    <script src='background.js'/>

</script>
  </head>
  <body>
  </body>
</html>

manifest.js

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    if (request.method == "getLocalStorage")
      sendResponse({data: localStorage[request.key]});
    else
      sendResponse({}); // snub them.
});

0 个答案:

没有答案