Get Multiple value in Chrome.tabs.executeScript

前端 未结 1 713
夕颜
夕颜 2021-01-29 09:37

How to return multiple element\'s value from Chrome Plugin, tabs.executeScript.

Please suggest in below code.

 chrome.tabs.executeScript(
      targetTab         


        
相关标签:
1条回答
  • 2021-01-29 10:15

    chrome.tabs.executeScript can transfer any JSON-ifiable data, including simple objects/arrays.

    chrome.tabs.executeScript(targetTab.id, {
        code: '(' + function() {
            return {
                top: document.querySelector('.top-card').innerHTML,
                footer: document.querySelector('.footer').innerHTML,
                content: document.querySelector('.content').innerHTML,
            };
        } + ')()'
    }, function(data) {
        var myCode = data[0]; // data is an array, item 0 is the main page, 1.. for frames
        console.log(myCode.top, myCode.footer);
    });
    
    0 讨论(0)
提交回复
热议问题