我正在从Contentscript发出获取请求,并将已解决的Promise数据存储在数组中。但是我想在另一个我称为index.js的Js文件中访问该数组,下面是我的代码
let pluginData = [];
let request = 'www.dummydata.com';
(async () =>{
const rawResponse = await fetch(request);
const data = await rawResponse.json();
let result = pluginData.push(data);
})();
chrome.runtime.sendMessage(pluginData,function(response){ });
这是我的index.js文件
let profiles = [];
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
getUserResults(request, sender, sendResponse);
});
async function getUserResults(request, sender, sendResponse){
profiles = await request;
console.log(profiles);
for (let i =0; i < profiles.length;i++){
function setHtml(id, value) {
document.getElementById(id).innerHTML = value;
}
setHtml('pending_requests', `${profiles[0].pending_requests}`);
return true;
}
我在做什么错了?