火狐扩展:如何从弹出窗口.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])
});

最新更新