Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I got you. Apparently, you want to parse current page's HTML code to find some HTML samples inside. Just modify my code a little bit. You need to put all the JavaScript that is inside your <code>getHTML()</code> function into the string inside <code>executeString()</code> call. That way is weird, but the string inside <code>executeString()</code> call is the code that is running inside the opened page's HTML (and you can get any inner HTML when you are inside), so you should use it. After some changes in my code, the popup shows the page with all <code>&lt;p&gt;</code> elements coloured red (as an example that you can get HTML code and modify it; in your case you are cutting the HTML according to the regular expression matching result instead of making text red):</p> <p>popup.js:</p> <pre><code>chrome.tabs.query( { active: true, lastFocusedWindow: true }, function(array_of_Tabs) { var tab = array_of_Tabs[0]; //tab.url; - url of the active tab chrome.tabs.executeScript(tab.id, {code: "var match = document.getElementsByTagName('html')[0].innerHTML + '&lt;style&gt;p{color:red}&lt;/style&gt;'; chrome.runtime.sendMessage(match);"}); }); chrome.runtime.onMessage.addListener(function(request) { document.getElementsByTagName('html')[0].innerHTML = request; }); </code></pre> <p>You can change the JavaScript code inside that string depending on what you want from your regular expression. The point is that you have to write your <code>getHTML()</code> algorithm inside the string you are injecting using <code>executeString()</code>. It is kind of weird, but that's the way you can execute something inside opened page's code, and you need that to get access to its code. It's only left for you to work on your regular expression logic. I guess that answers your direct question about how to invoke some JavaScript algorithm inside currently opened tab's code and send something to your popup.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload