How to trigger an action on the opened tab via my popup.html extension

Viewed 24

Probably I'm having a misunderstanding about how to use the browser_action, but basically I need to trigger an action on the actual tab opened on the browser via the popup.html opened when I click my extension icon and inside of this html I have a button for this trigger.

So i clicked on the button inside the html on my extension, and i want to trigger a console.log on the opened tab at my browser.

This is my code below, what I'm doing wrong?

manifest.json

{
  "name": "Test",
  "description": "Test",
  "version": "1.0.0",
  "manifest_version": 2,
  "minimum_chrome_version": "46",
  
  "permissions": ["tabs", "<all_urls>"],
 
  "background":{
    "scripts":["script.js"]
  },
  "browser_action": {
    "default_title": "Test",
    "default_popup": "popup.html",  
    "default_icon": {
      "16": "/images/icon-16.png",
      "48": "/images/icon-48.png",
      "128": "/images/icon-128.png"
    }
  },
  
}

script.js

document.getElementById("myButton").addEventListener("click", test);
function test() {
  alert("Message")
}

popup.html

<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-    scale=1.0">
    <title>Document</title>
  </head>
<body>
  <button id="myButton"> TEST </button>

  <script type="text/javascript" src="./script.js" ></script>
</body>
</html>

What i want: enter image description here

0 Answers
Related