我想创建一个镀铬扩展程序,它会浏览标签,抓住我想要的元素并将它们粘贴回popup.html。
我成功地将元素从内容脚本发送到bg.js:
内容脚本
chrome.runtime.sendMessage(document.getElementsByClassName('link')[0].innerHTML);
后台脚本
chrome.runtime.onMessage.addListener(function(response, sender, sendResponse){
var companynames = [];
companynames.push(response);
console.log(companynames)
})
我在后台视图中看到了变量。但是,我没有看到所有变量的数组,而是看到了很多arrary,每个数组都包含每个页面中的一个变量。
如何将它们组合在一起?