初めての Chrome 拡張機能を作成しようとしていますが、optionページlocalStorageを. Message Passingのこのページで、2つの間でメッセージをやり取りする方法を調べましたが、 eventListener を設定し、 in で許可されていないsを使用する必要があるようです:www.example.com/example.htmllocalStorageSendRequestbackground.htmlmanifest : 2
There were warnings when trying to install this extension:
'background_page' requires manifest version of 1 or lower.
編集: `bac を使用するには、manifest ここに表示されているように変更を加える必要があります
Message Passingページではポートの作成について説明していますが、リスナーをどこに配置するかは不明です。前半をcontent.jsスクリプトに入れ、残りの半分を に入れるoptions.jsと、リスナーoptions.htmlは が開いているときにのみアクティブになります。
だから私の質問は:現在の Web ページを操作するoptions.html ために選択した設定を渡すにはどうすればよいですか?contentscript.js
セットアップ全体は次のとおりです。
background.html
<!doctype html>
<html>
<head>
<title>Background Page</title>
<script src="jquery.min.js"/>
<script src='background.js'/>
</script>
</head>
<body>
</body>
</html>
background.js
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "getLocalStorage")
sendResponse({data: localStorage[request.key]});
else
sendResponse({}); // snub them.
});
contentscript.js
chrome.extension.sendRequest({method: "getLocalStorage", key: "status"}, function(response) {
console.log(response.data);
});
マニフェスト.js
{
"manifest_version": 2,
"name": "Image replacer",
"version": "1.0",
"description": "A script to replace all images in the browser with images from any given Imgur gallery",
"browser_action": {
"name": "Image replace BA",
"icons": ["icon.png"],
"default_icon": "icon.png"
},
"background": {
"page": "background.html"
},
"permissions": ["storage"],
"content_security_policy": "script-src 'self' https://www.imgur.com; object-src 'self'",
"content_scripts": [{
"js": ["jquery.min.js", "contentscript.js"],
"matches": ["http://*/*", "https://*/*"]
}],
"options_page": "options.html"
}