0

I'm developing a Chrome extension which scrappes some data via content scripts and passes one composite object to the background worker.

In the passed object, I have many properties. Some are strings, some are integers, some arrays and 3 of them are Map objects.

The thing is: these Map objects are stripped in the proccess. I console.log the same object immediatelly before sending and after receiving, and the 3 properties which are Map objects become empty objects:

In content script:

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
    if (msg.attemptedStartScrapping) {
        try {
            fetchInfo()
                .then(info => {
                    console.log({content: info})
                    sendResponse(info)
                })
            return true
        } catch (e) {
            if(!(e instanceof NotHomepageException)) console.error(e)
        }
    }
})

In bg worker:

chrome.action.onClicked.addListener(tab => {
    const details = { tabId: tab.id }
    sendMessage(details)
})

function sendMessage(details) {
    chrome.tabs.sendMessage(
        details.tabId,
        {
            attemptedStartScrapping: true,
            tabId: details.tabId ?? null,
        },
        info => {
            console.log({ worker: info })
        }
    )
}

Console outputs:

enter image description here enter image description here

Any thoughts? Did we find a bug in message passing?

César Rodriguez
  • 296
  • 5
  • 16
  • 1
    you can't send map\set objets and anyway object that can't be serialized. In your case you can transform map in 2 distinc arrays of keys and values or better a new object. – Robbi Aug 28 '22 at 15:08
  • Thanks! The associated question answers mine. I don't want to delete it, though, because with this title it's easier for other people facing the same problem to find it on search engines. – César Rodriguez Aug 28 '22 at 20:29

0 Answers0