Firefox 扩展:如何从 popup.js 获取当前打开的标签页的文档?

Firefox extension: how to get document of currently opened tab from popup.js?

我试过:

browser.tabs.query({ active: true, currentWindow: true }, callback)  // can't get extract document from tab
browser.windows.getCurrent()  // can't get document from window
content.document  // document of popup

我需要文档来获取当前打开的站点上的选定文本。

需要activeTab权限和executeScript功能:

browser.tabs
      .executeScript({
        code: "document.getSelection().toString()"
      })
      .then(results => {
        console.log(results[0])
      });