0

In the extention there is a button on the popup page, when I click it I want it to get the title of the current tab. But when I click it, it gives me the title of the popup page. I have tried using chrome.tabs.executeScript() but couldn't make it work. The only time it worked it when I use a backgound.js, but I only want it to do something when I clicked the button. I am really stuck, any help would be apreciated.

Here is the manifest.json

{
    "name": "extention_test",

    "description": "extention descripton",

    "manifest_version": 3,

    "version": "1.0",

    "content_scripts": [{
        "matches": ["https://www.youtube.com/*"],
        "js": ["background.js"],

    }],


    "action": {
        "default_popup": "popup.html",
        "default_title": "test",

    },

    "permissions": [
        "activeTab"
    ]


}

Here is the popup.html

<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Not This Title</title>
</head>

<body>

    <button id="btn">Click me</button>
    <script src="button.js"></script>


</body>

</html> 

Here is the button.js

const btn = document.getElementById('btn');


btn.addEventListener('click', function handleClick() {


    btn.textContent = 'Button clicked';
    alert(document.title)
   
});
Boranroni
  • 1
  • 1

0 Answers0