如何从内容脚本获取数组到background.js和其他js文件

时间:2018-07-19 13:41:43

标签: javascript google-chrome google-chrome-extension

我正在从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;
    }

我在做什么错了?

0 个答案:

没有答案