我正在开发 Chrome 扩展程序,但遇到以下问题。当某个事件发生时,我的后台页面会创建一个带有chrome.tabs.create
API 的新选项卡(页面)并发送一个对象。
发送的对象(称为项目)是一个对象列表,具有称为项目的特定类(原型)。
这里有一些代码:
// in background.html
chrome.tabs.create({index: 0, url: "results.html"}, function(tab) {
chrome.tabs.sendRequest(tab.id, {'items': itemsList}, function(response) {
console.log(response.farewall);
});
});
另一方面,在新创建的页面中,我收到了发送的对象
// newpage.html
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
console.dir(request.items);
sendResponse({});
}
);
问题是,当我收到对象列表时,newpage.html
对象类型丢失了。确实console.dir()
在 new中使用, itemsListbackground page
中的对象类型被正确报告,但在接收到的项目列表对象中却没有。newpage.html
我可以background.html
通过字符串手动序列化他中的数据,然后手动反序列化,newpage.html
但我想知道是否有更好的方法来负担这个并防止列表中的对象类型(即项目)丢失。