可能重复:
Port error while changing chrome extension from manifest v1 to v2
想要制作我的第一个Chrome扩展程序,但当我开始考虑使用option
页面的localStorage
和www.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.
});