title: Return map from background script using Promise
body: <p>I am writing web-extension and I need to get a map as a reply from background script. In order to make my extension compatible with both firefox and chrome, I use Mozilla's <em>webextension-polyfill</em>.
  Here is a code sample:</p>
  
  <p><strong>front.js:</strong></p>
  
  <pre><code>var sendmsg = browser.runtime.sendMessage(1);
  
  sendmsg.then(
      result =&gt; { handleResponse(result); },
      error =&gt; { handleError(error); });
  
  function handleError(e)
  {
     console.log("ERROR HANDLED: " + e);
  }
  
  function handleResponse(result)
  {
      console.log("map size = " + result.size);  
  }
  </code></pre>
  
  <p><strong>background.js</strong></p>
  
  <pre><code>var maptest = new Map();
  
  browser.runtime.onMessage.addListener(onContentMessage);
  
  function onContentMessage(msg, sender, handleResponse)
  {
    return new Promise(resolve =&gt; {
      maptest.clear();
      maptest.set("aaa", 1);
      resolve(maptest);
    });
  }
  </code></pre>
  
  <p>However, this works only in ff, in any chromium-based browser handleResponse argument is <em>undefined</em>. I have tested Promises under chrome without content-background message exchange, and it returns map correctly. Is the problem in webextension-polyfill and does anybody know, how to solve it?</p>