I need to get the HTML source code of the current tab from my popup.html, then scrape the HTML, and send the scraped information to my background.js.
Initially, I made a physical button in the current tab just to check my background.js logic worked, after I've finished testing I moved that button to the popup.html page, but now I don't know how to get the current tab's HTML.
The button inside my popup.html calls my popup.js script:
function scrapNames() {
//chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
//var currentTab = tabs[0];
//});
var prof = [..."need current tab html here".querySelectorAll(`[data-content*="Instructor"]`)]
prof.map(p => {
pname = p.innerText.split(" ", 2);
chrome.runtime.sendMessage({ names: pname }, res => console.log(res))
});
}
document.getElementById("search-ratings").onclick = scrapNames;
As you can see I have messed around with chrome.tabs.query trying to get the HTML source of the current tab, but I don't know how to use it properly. When I printed tab[0] out I saw I can get the URL. I could do a fetch() with the URL to get the HTML, but I am sure there is a better way to do this.