I'm sending a map from my popup.js to content script but instead of a map I get an [object Object]. I tried using JSON.parse and JSON.stringify but I had a 'unexpected token O'.
script for sending the map:
const mapObject=new Map();
mapObject.set("key2","vakku");
mapObject.set("key4","val4");
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
from: "tpopup",
command: "specifyAccounts"
, tableData: mapObject,
},function(message,sender,sendresponse){
// stuff
});
});
and in the listener:
var dataset = msg.tableData;
var datasetJS= new Map(Object.entries(dataset));
if(typeof datasetJS!="undefined"){
console.log(datasetJS.size);//0
console.log(typeof datasetJS);//object
console.log(datasetJS.toString());// [object Map]
console.log(JSON.stringify(datasetJS));//{}
console.log(typeof dataset);//object
console.log(dataset.toString());[object Object]
}
Any idea what went wrong? Thank you!