Return value from chrome.tabs.executeScript

后端 未结 1 645
無奈伤痛
無奈伤痛 2021-01-11 12:32

In popup.js i\'m using the following code to display all the text within a certain div id of the current tab - and display in alert. I\'m wondering how would it be possible

相关标签:
1条回答
  • 2021-01-11 13:06

    Use the following code,

    var getText = Array();
    chrome.tabs.executeScript(tabs[tab].id, {
        "code": "document.getElementById(\"_Your_ID_Here_\").innerText.split(' ')"
    }, function (result) {
        for (i = 0; i < result[0].length; i++)
        getText [i] = result[0][i];
        console.log(getText);
    });
    

    You have update variable inside callback, because of async nature of chrome.api

    0 讨论(0)
提交回复
热议问题