Skip to content Skip to sidebar Skip to footer

Chrome.tabs.executescript Is Not Returning Results From Content Page

I am working on a chrome extension where I attempt to return all h2 tags from the web page i am on. chrome.tabs.executeScript will work if its simple such as chrome.tabs.executeSc

Solution 1:

You can't return DOM nodes using executeScript. But if you need their innerHTML you can return an array with it.

chrome.tabs.executeScript(null,{
    code: 'Array.from(document.getElementsByTagName("h2")).map(h => h.innerHTML)'
},function (results){
    console.log(results);
});

Post a Comment for "Chrome.tabs.executescript Is Not Returning Results From Content Page"