ポップアップ ウィンドウでテスト サーバーを認証し、テスト サーバーからデータを取得し、バックグラウンド スクリプトを介してローカル ストレージに保存し、popup.html に表示する拡張機能を構築しようとしています。問題は、サーバーからのデータを保存できますが、最初の認証で表示できないことです。再度ログインする必要があります。その後、テスト サーバーから取得したデータを表示できますか? ヒントやアドバイスをいただければ幸いです。
ポップアップ.js:
chrome.runtime.sendMessage({from: "login", user: username, pass: password, subject: "page_details"},function(response)
{
//Sends message to background to start content script.
var login_response = response.type1;
if(login_response == "DONE")
{
//window.location = "index.html";
}
if(login_response == "INVALID")
{
}
});
Backgroundscript.js
if (msg.from && (msg.from === "login")
&& msg.subject && (msg.subject = "page_details"))
{
chrome.tabs.executeScript( { file: 'contentscript.js' });
sendResponse({'type1':"DONE"});
}
Contentscript.js:
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.setRequestHeader("Content-Type","application/json");
xhr.send(JSON.stringify(data));
var raw_data = xhr.responseText;
var project_details = JSON.parse(xhr.responseText);
chrome.runtime.sendMessage({from: "content2", subject: "page_details", data: raw_data},function(response)
{
});
backgroundscript.js:
if (msg.from && (msg.from === "content2")
&& msg.subject && (msg.subject = "page_details"))
{
var project_name = [];
chrome.pageAction.show(sender.tab.id);
var raw_details = msg.data;
var project_details = JSON.parse(msg.data);
localStorage["Project"] = JSON.stringify(project_name);
}
index.html (拡張機能の別のポップアップ ページ) に localStorage["Project"] を入力しますが、一度にプロジェクトの詳細を入力することはできませんでした。ページをリロードする必要があります。それはindex.htmlにあります