私のmanfiest.jsonはこれです。Chrome拡張機能のローカルストレージにアクセスしたい
{
"manifest_version": 2,
"name": "GTmetrix Analyzer Plugin",
"description": "This extension will analyze a page using GTmetrix",
"version": "2.1",
"options_page": "options.html",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions": ["tabs", "storage"],
"content_scripts": [
{
"matches": ["http://ticketchest.geekschicagolabs.com/admin/orderHistory"],
"css": ["mystyles.css"],
"js": ["jqueryui-min.js", "content-script.js"]
}
]
}
と私のpopup.htmlが
<!doctype html>
<html>
<head>
<title>Ticket chest</title>
<script src="popup.js"></script>
</head>
<body>
<h1>Ticket chest extension</h1>
<a href="options.html">Settings</a>
<!-- <button id="checkPage">Check this page now!</button> -->
</body>
</html>
あるとbackground.jsは
chrome.runtime.onMessage.addListener(function(response, sender, sendResponse){
localStorage['privateKeyy'] = response;
});
は今、私はそれも可能のローカルストレージに保存されますどのようなユーザーがテキストエリアに入力したいですエクステンションのローカルストレージを持つウェブでは、エクステンションのローカルストレージに保存されますが、ウェブページには保存されません。
、あなたは(拡張機能のバックグラウンドスクリプトで代わりにコードを実行する(のみ))コンテンツスクリプトにコードを移動し、Webページのローカルストレージにデータを保存したい場合は、そのコンテンツのスクリプトコード
window.onload = function() {
document.getElementById('save').onclick = function(){
var privateKey = document.getElementById("textarea").value;
chrome.storage.sync.set({'privateKey':privateKey}, function(){
//document.getElementById('privateKey').value = privateKey;
//chrome.browserAction.setBadgeBackgroundColor({color:[200, 0, 0, 100]});
//chrome.tabs.sendMessage(privateKey);
chrome.storage.local.set({'privateKeyy':privateKey});
localStorage.setItem("lastname", "Smith");
alert('save successfully');
});
//syncStorage["privateKey"] = privateKey;
}
document.getElementById('erase').onclick = function(){
chrome.storage.sync.remove('privateKey', function(){
alert('erase successfully');
});
}
document.getElementById('get').onclick = function(){
chrome.storage.sync.get('privateKey', function(data){
alert(data.privateKey);
console.log(data.privateKey);
});
}
}
これはPHPと関係がありますか? – Farkie
https://developer.chrome.com/extensions/storage – Farkie
@Farkie私はこのリンクに従いますが、間違ったキーがウェブページのローカルストレージにストアされていないことがあります... – hu7sy