1

edit: just found answer here: Chrome Extension how to send data from content script to popup.html

I want to count for example h2 elements on website and then print variable in popup.

I can actually alert this variable, but can't make it pass to popup.

manifest.json

{
  "manifest_version": 2,

  "name": "Getting started example",
  "description": "",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },

  "permissions": [
    "activeTab",
    "storage",
  ],

}

popup.html

<!doctype html>

<html>
  <head>



  </head>

  <body>

  <span>h2:<span><span id="log"></span>



     <script src="popup.js"></script>

  </body>
</html>

popup.js

chrome.tabs.executeScript(null, { file: 'content.js' },function(result){

document.getElementById('log').innerHTML = (result);

});

content.js

var result=document.getElementsByTagName("h2").length;
riten
  • 185
  • 1
  • 12

0 Answers0