如何通过一个数组对象从contentscript.js弹出.html

How to pass an array object from contentscript.js to popup.html?

本文关键字:对象 contentscript js html 弹出 数组 一个 何通过      更新时间:2023-09-26

popup.html向contentscript.js发送请求。contentscript.js创建了一个数组,并将响应(一个数组对象)发送给pop .html。

如何通过一个数组对象从contentscript.js弹出。html?

是否需要background.html页面从contentscript.js中获取数组对象,然后将其传递给pop .html ?

//content script
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    var result = [{},{},{}];
    sendResponse(result);
});
//popup
chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, "request", function(result) {
        console.log("Received from content script:", result)
    });
});

update:添加选定的制表符id而不是null