En la extensión hay un botón en la página emergente, cuando hago clic en él, quiero que obtenga el título de la pestaña actual. Pero cuando hago clic en él, me da el título de la página emergente. Intenté usar chrome.tabs.executeScript() pero no pude hacerlo funcionar. La única vez que funcionó fue cuando uso un backgound.js, pero solo quiero que haga algo cuando hago clic en el botón. Estoy realmente atascado, cualquier ayuda sería apreciada.
Aquí está el manifiesto.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" ] }Aquí está el 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>Aquí está el botón.js
const btn = document.getElementById('btn'); btn.addEventListener('click', function handleClick() { btn.textContent = 'Button clicked'; alert(document.title) });