I am very new to programming and I am trying to make a Chrome extension that searches for a given string of text on the webpage where the extension is loaded and do some stuff.
In my popup.js file I tried with a function like this:
function findtext() {
if (document.body.innerHTML.search("String I am looking for") != -1) {
//do stuff
} else {
alert("Nope");
}
}
However, when I launch my extension from a page that clearly includes the text "String I am looking for", I get the control alert "Nope".
I don't really understand why this does not work.
UPDATE: I kind of solved this through a code.js file injection, as shown here.