0

我有一个从清单 v2 移动到 v3 的扩展。在清单 v3 上,executeScript 已更改。简单地说,在 V2 中,我有一个类似的代码;

chrome.tabs.query({
        active: true,
        currentWindow: true
    }, function (tabs) {
        chrome.tabs.executeScript({
            code: "window.getSelection().toString();"
        }, function (selection) {
            console.log(selection[0]);
            // I use the user selection for another purpose but for simplicity lets just log the selection
        });
    });

现在我已将其更改为;

chrome.tabs.query({
        active: true,
        currentWindow: true
    }, function (tabs) {
        chrome.scripting.executeScript({
            function: () => window.getSelection().toString(),
            target: {tabId: tabs[0].id}
        }, function (selection) {
            console.log(selection[0]);
            // For simplicity just log
        });
    });

但我无法阅读选择。它总是未定义的。我怎样才能做到这一点?

4

0 回答 0