0

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.

Rob
  • 11
  • 3
  • I just realized that I probably don’t know how to run this code on the exact page where I open the Chrome extension and launch the command from the extension’s UI (it has a button). If I try to launch this from the Chrome console, it works correctly by finding the text. – Rob Apr 16 '20 at 20:01
  • Since the extension's console shows this message "popup.js:112 Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' blob: filesystem:"." I am starting to understand what the problem is, but I am unsure how to fix it. – Rob Apr 16 '20 at 20:13

0 Answers0