Edit: I gave up and decided to store the data in the storage.local of the popup.
I am sending a message from the popup to the background to fetch some data from storage.local (when I do it from the popup it just returns an empty map). The background should respond with a map.
The problem is that before the response from the background is sent, the response is a map with values, but after the response, it's "undefined".
popup.js
window.addEventListener('DOMContentLoaded', () => { chrome.runtime.sendMessage({subject:"config"},function(response){ // prints undefined console.log(response); }); });
background.js
chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { if(request.subject == "config"){ (async () => { chrome.storage.local.get("config2t2b", function(result){ //prints a map console.log(result.config2t2b); sendResponse(result.config2t2b); return; }); })(); } } );
chrome
object? In theory the code you have should work.chrome
because otherwise, it wouldn't work in chromium based browsers.globalThis.browser ??= globalThis.chrome;
. Did you really give on the the original question?