我试过:
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])
});